Skip to content

Commit 8dac7b9

Browse files
committed
timeframe automatisation
1 parent a830b2f commit 8dac7b9

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

backtest.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,46 +135,49 @@ def timeFrame(datapath):
135135
"""
136136
Select the write compression and timeframe.
137137
"""
138-
if datapath[-8:-4] == '1mth':
138+
sepdatapath = datapath[5:-4].split(sep='-') # ignore name file 'data/' and '.csv'
139+
tf = sepdatapath[3]
140+
141+
if tf == '1mth':
139142
compression = 1
140143
timeframe = bt.TimeFrame.Months
141-
elif datapath[-7:-4] == '12h':
144+
elif tf == '12h':
142145
compression = 720
143146
timeframe = bt.TimeFrame.Minutes
144-
elif datapath[-7:-4] == '15m':
147+
elif tf == '15m':
145148
compression = 15
146149
timeframe = bt.TimeFrame.Minutes
147-
elif datapath[-7:-4] == '30m':
150+
elif tf == '30m':
148151
compression = 30
149152
timeframe = bt.TimeFrame.Minutes
150-
elif datapath[-6:-4] == '1d':
153+
elif tf == '1d':
151154
compression = 1
152155
timeframe = bt.TimeFrame.Days
153-
elif datapath[-6:-4] == '1h':
156+
elif tf == '1h':
154157
compression = 60
155158
timeframe = bt.TimeFrame.Minutes
156-
elif datapath[-6:-4] == '3m':
159+
elif tf == '3m':
157160
compression = 3
158161
timeframe = bt.TimeFrame.Minutes
159-
elif datapath[-6:-4] == '2h':
162+
elif tf == '2h':
160163
compression = 120
161164
timeframe = bt.TimeFrame.Minutes
162-
elif datapath[-6:-4] == '3d':
165+
elif tf == '3d':
163166
compression = 3
164167
timeframe = bt.TimeFrame.Days
165-
elif datapath[-6:-4] == '1w':
168+
elif tf == '1w':
166169
compression = 1
167170
timeframe = bt.TimeFrame.Weeks
168-
elif datapath[-6:-4] == '4h':
171+
elif tf == '4h':
169172
compression = 240
170173
timeframe = bt.TimeFrame.Minutes
171-
elif datapath[-6:-4] == '5m':
174+
elif tf == '5m':
172175
compression = 5
173176
timeframe = bt.TimeFrame.Minutes
174-
elif datapath[-6:-4] == '6h':
177+
elif tf == '6h':
175178
compression = 360
176179
timeframe = bt.TimeFrame.Minutes
177-
elif datapath[-6:-4] == '8h':
180+
elif tf == '8h':
178181
compression = 480
179182
timeframe = bt.TimeFrame.Minutes
180183
else:

0 commit comments

Comments
 (0)