You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example for this strategy ([SMA-BTCUSDT-20170101-20201231-1h.csv](result/SMA-BTCUSDT-20170101-20201231-1h.csv)) using SMA on the 1 hour timeframe BTCUSDT pair from 2017 to 2020, we can notice that the lower the SMA period is the lower our sqn and profit will be (in that case even negative), and conversely when the SMA period is higher our profit is better.
124
126
127
+
*The code was run again between 2018-03-01 and 2020-11-15 to exclude the bullrun period and test our strategies during upward trend and range period.*
128
+
125
129
126
130
## Backtest <aname="backtest"></a>
127
131
@@ -201,7 +205,59 @@ else :
201
205
202
206
203
207
204
-
*compression and timeframe*
208
+
* Get compression and timeframe
209
+
210
+
When we create the data feed we need to define the compression and timeframe.
For a 3 days timeframe (one candlestick represent 3 days) we would have ```compression = 3``` and ```timeframe = bt.TimeFrame.Days```. However, for a 2h timeframe ```compression = 120``` but ```timeframe = bt.TimeFrame.Minutes```.
226
+
227
+
To automatically do this conversion the ```runbacktest()``` function will analyse the given datapath name and pass it to another function that will read the file name and retrieve its timeframe (e.g. data/ETHUSDT-2017-2020-**4h**.csv).
228
+
229
+
```python
230
+
deftimeFrame(datapath):
231
+
"""
232
+
Select the write compression and timeframe.
233
+
"""
234
+
sepdatapath = datapath[5:-4].split(sep='-') # ignore name file 'data/' and '.csv'
235
+
tf = sepdatapath[3]
236
+
237
+
if tf =='1mth':
238
+
compression =1
239
+
timeframe = bt.TimeFrame.Months
240
+
elif tf =='12h':
241
+
compression =720
242
+
timeframe = bt.TimeFrame.Minutes
243
+
244
+
...
245
+
246
+
elif tf =='8h':
247
+
compression =480
248
+
timeframe = bt.TimeFrame.Minutes
249
+
else:
250
+
print('dataframe not recognized')
251
+
exit()
252
+
253
+
return compression, timeframe
254
+
```
255
+
256
+
*Later this function can be improved to save more lines by autocomputing the compression if we have a hour timeframe (e.g. if 'h' take what's in the front, say 12 and multiply it by 60 => 720 and timeframe = bt.TimeFrame.Minutes).*
0 commit comments