@@ -33,9 +33,9 @@ from backtesting.test import SMA, GOOG
33
33
34
34
class SmaCross (Strategy ):
35
35
def init (self ):
36
- Close = self .data.Close
37
- self .ma1 = self .I(SMA , Close , 10 )
38
- self .ma2 = self .I(SMA , Close , 20 )
36
+ price = self .data.Close
37
+ self .ma1 = self .I(SMA , price , 10 )
38
+ self .ma2 = self .I(SMA , price , 20 )
39
39
40
40
def next (self ):
41
41
if crossover(self .ma1, self .ma2):
@@ -44,8 +44,8 @@ class SmaCross(Strategy):
44
44
self .sell()
45
45
46
46
47
- bt = Backtest(GOOG , SmaCross,
48
- cash = 10000 , commission = .002 )
47
+ bt = Backtest(GOOG , SmaCross, commission = .002 ,
48
+ exclusive_orders = True )
49
49
bt.run()
50
50
bt.plot()
51
51
```
@@ -56,30 +56,33 @@ Results in:
56
56
Start 2004-08-19 00:00:00
57
57
End 2013-03-01 00:00:00
58
58
Duration 3116 days 00:00:00
59
- Exposure [%] 94.29
60
- Equity Final [$] 69665 .12
61
- Equity Peak [$] 69722.15
62
- Return [%] 596.65
59
+ Exposure Time [%] 94.27
60
+ Equity Final [$] 68935 .12
61
+ Equity Peak [$] 68991.22
62
+ Return [%] 589.35
63
63
Buy & Hold Return [%] 703.46
64
- Max. Drawdown [%] -33.61
65
- Avg. Drawdown [%] -5.68
66
- Max. Drawdown Duration 689 days 00:00:00
64
+ Max. Drawdown [%] -33.08
65
+ Avg. Drawdown [%] -5.58
66
+ Max. Drawdown Duration 688 days 00:00:00
67
67
Avg. Drawdown Duration 41 days 00:00:00
68
68
# Trades 93
69
69
Win Rate [%] 53.76
70
- Best Trade [%] 56.98
71
- Worst Trade [%] -17.03
72
- Avg. Trade [%] 2.44
70
+ Best Trade [%] 57.12
71
+ Worst Trade [%] -16.63
72
+ Avg. Trade [%] 1.96
73
73
Max. Trade Duration 121 days 00:00:00
74
74
Avg. Trade Duration 32 days 00:00:00
75
- Expectancy [%] 6.92
76
- SQN 1.77
77
- Sharpe Ratio 0.22
78
- Sortino Ratio 0.54
79
- Calmar Ratio 0.07
80
- _strategy SmaCross
75
+ Profit Factor 2.13
76
+ Expectancy [%] 6.91
77
+ SQN 1.78
78
+ Sharpe Ratio 0.18
79
+ Sortino Ratio 0.44
80
+ Calmar Ratio 0.06
81
+ _strategy SmaCross(n1=10, n2=20)
82
+ _equity_curve Equ...
83
+ _trades Size EntryB...
81
84
```
82
- [ ![ plot of trading simulation] ( https://i.imgur.com/q6OSQD8 .png )] ( https://kernc.github.io/backtesting.py/#example )
85
+ [ ![ plot of trading simulation] ( https://i.imgur.com/xRFNHfg .png )] ( https://kernc.github.io/backtesting.py/#example )
83
86
84
87
Find more usage examples in the [ documentation] .
85
88
0 commit comments