File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ Finally the top 10 strategies will be saved to a [JSON file](top10sqn.json) so t
22
22
23
23
* Ideally, the backtest will run automatically each X period and reset the best strategy.*
24
24
25
+   ;
26
+
25
27
26
28
# Code review <a name =" review " ></a >
27
29
@@ -257,7 +259,28 @@ def timeFrame(datapath):
257
259
258
260
  ;
259
261
262
+ To complete our program we've added two analyzers from backtrader ([ analyzers reference] ( https://www.backtrader.com/docu/analyzers-reference/ ) ) :
260
263
264
+ ``` python
265
+ cerebro.addanalyzer(bt.analyzers.TradeAnalyzer, _name = " ta" )
266
+ cerebro.addanalyzer(bt.analyzers.SQN , _name = " sqn" )
267
+ ```
268
+
269
+ It enable us to get the total number of win/loss, the net pnl and the sqn after a strategy was run.
270
+
271
+ ``` python
272
+ totalwin, totalloss, pnl_net = getWinLoss(stratexe.analyzers.ta.get_analysis())
273
+ sqn = getSQN(stratexe.analyzers.sqn.get_analysis())
274
+ ```
275
+
276
+ ``` python
277
+ def getWinLoss (analyzer ):
278
+ return analyzer.won.total, analyzer.lost.total, analyzer.pnl.net.total
279
+ def getSQN (analyzer ):
280
+ return round (analyzer.sqn,2 )
281
+ ```
282
+
283
+   ;
261
284
262
285
263
286
# Analysis <a name =" analysis " ></a >
You can’t perform that action at this time.
0 commit comments