Skip to content

Commit cbe8c4c

Browse files
committed
Integration of a new multi files importer window
Not finished
1 parent 0255fa2 commit cbe8c4c

14 files changed

+279175
-200145
lines changed

Controller.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(self):
4848

4949
# Init attributes
5050
self.strategyParameters = {}
51+
self.dataframes = {}
5152

5253
# Global is here to update the Ui in observers easily, if you find a better way, don't hesistate to tell me (Skinok)
5354
global interface
@@ -98,21 +99,40 @@ def resetCerebro(self):
9899
pass
99100

100101

101-
def loadData(self, dataPath):
102+
def loadData(self, dataPath, datetimeFormat, separator):
102103

103-
self.dataframe = pd.read_csv(dataPath, sep='\t', parse_dates=[0], date_parser=lambda x: pd.to_datetime(x, format='%Y-%m-%d %H:%M:%S'),skiprows=0,header=0,index_col=0)
104+
# Try importing data file
105+
# We should code a widget that ask for options as : separators, date format, and so on...
106+
try:
107+
fileName = os.path.basename(dataPath)
108+
self.dataframes[fileName] = pd.read_csv(dataPath, sep=separator, parse_dates=[0], date_parser=lambda x: pd.to_datetime(x, format=datetimeFormat), skiprows=0, header=0, index_col=0)
109+
except ValueError as err:
110+
return False, "ValueError error:" + str(err)
111+
except AttributeError as err:
112+
return False, "AttributeError error:" + str(err)
113+
except :
114+
return False, "Unexpected error:" + str(sys.exc_info()[0])
104115

105-
# Datetime first column : 2012-12-28 17:45:00
106-
#self.dataframe['TimeInt'] = pd.to_datetime(self.dataframe.index).astype('int64') # use finplot's internal representation, which is ns
107-
108-
# Pass it to the backtrader datafeed and add it to the cerebro
109-
self.data = bt.feeds.PandasData(dataname=self.dataframe, timeframe=bt.TimeFrame.Minutes)
116+
return True, ""
110117

111-
# Add data to cerebro
112-
self.cerebro.adddata(self.data) # Add the data feed
118+
def importData(self, fileNamesOrdered):
113119

114-
# Draw charts based on input data
115-
self.interface.drawChart(self.dataframe)
120+
# Files should be loaded in the good order
121+
for fileName in fileNamesOrdered:
122+
123+
df = self.dataframes[fileName]
124+
125+
# Datetime first column : 2012-12-28 17:45:00
126+
#self.dataframe['TimeInt'] = pd.to_datetime(self.dataframe.index).astype('int64') # use finplot's internal representation, which is ns
127+
128+
# Pass it to the backtrader datafeed and add it to the cerebro
129+
self.data = bt.feeds.PandasData(dataname=df, timeframe=bt.TimeFrame.Minutes)
130+
131+
# Add data to cerebro : only add data when all files have been selected for multi-timeframes
132+
self.cerebro.adddata(self.data) # Add the data feed
133+
134+
# Draw charts based on input data
135+
self.interface.drawChart(df)
116136

117137
# Enable run button
118138
self.interface.strategyTesterUI.runBacktestPB.setEnabled(True)
@@ -214,7 +234,9 @@ def displayStrategyResults(self):
214234
pnl_data['value'] = self.wallet.value_list
215235
pnl_data['equity'] = self.wallet.equity_list
216236
pnl_data['cash'] = self.wallet.cash_list
217-
pnl_data['time'] = self.dataframe.index
237+
238+
# really uggly
239+
pnl_data['time'] = list(self.dataframes.values())[0].index
218240

219241
# draw charts
220242
df = pd.DataFrame(pnl_data)

data/EURUSD_M15.csv

Lines changed: 0 additions & 200001 deletions
This file was deleted.

data/Source 1/EURUSD_D1.csv

Lines changed: 4670 additions & 0 deletions
Large diffs are not rendered by default.

data/Source 1/EURUSD_H1.csv

Lines changed: 50000 additions & 0 deletions
Large diffs are not rendered by default.

data/Source 1/EURUSD_H4.csv

Lines changed: 24083 additions & 0 deletions
Large diffs are not rendered by default.

data/Source 1/EURUSD_M1.csv

Lines changed: 50000 additions & 0 deletions
Large diffs are not rendered by default.

data/Source 1/EURUSD_M15.csv

Lines changed: 50000 additions & 0 deletions
Large diffs are not rendered by default.

data/Source 1/EURUSD_M30.csv

Lines changed: 50000 additions & 0 deletions
Large diffs are not rendered by default.

data/Source 1/EURUSD_M5.csv

Lines changed: 50000 additions & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy