Skip to content

Commit a6158ed

Browse files
committed
completed
1 parent 8dac7b9 commit a6158ed

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Finally the top 10 strategies will be saved to a [JSON file](top10sqn.json) so t
2222

2323
*Ideally, the backtest will run automatically each X period and reset the best strategy.*
2424

25+
 
26+
2527

2628
# Code review <a name="review"></a>
2729

@@ -257,7 +259,28 @@ def timeFrame(datapath):
257259

258260
&nbsp;
259261

262+
To complete our program we've added two analyzers from backtrader ([analyzers reference](https://www.backtrader.com/docu/analyzers-reference/)) :
260263

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+
&nbsp;
261284

262285

263286
# Analysis <a name="analysis"></a>

0 commit comments

Comments
 (0)