remove prepare data from baseanalysis

This commit is contained in:
Stefano Ariestasia
2023-09-12 19:29:13 +09:00
parent 475d8486bb
commit cfeefa8754
3 changed files with 49 additions and 57 deletions

View File

@@ -49,36 +49,6 @@ class BaseAnalysis:
timestamp = int(dt.replace(tzinfo=timezone.utc).timestamp()) timestamp = int(dt.replace(tzinfo=timezone.utc).timestamp())
return timestamp return timestamp
def prepare_data(self, varholder: VarHolder, pairs_to_load: List[DataFrame], backtesting: Backtesting):
if 'freqai' in self.local_config and 'identifier' in self.local_config['freqai']:
# purge previous data if the freqai model is defined
# (to be sure nothing is carried over from older backtests)
path_to_current_identifier = (
Path(f"{self.local_config['user_data_dir']}/models/"
f"{self.local_config['freqai']['identifier']}").resolve())
# remove folder and its contents
if Path.exists(path_to_current_identifier):
shutil.rmtree(path_to_current_identifier)
prepare_data_config = deepcopy(self.local_config)
prepare_data_config['timerange'] = (str(self.dt_to_timestamp(varholder.from_dt)) + "-" +
str(self.dt_to_timestamp(varholder.to_dt)))
prepare_data_config['exchange']['pair_whitelist'] = pairs_to_load
if self._fee is not None:
# Don't re-calculate fee per pair, as fee might differ per pair.
prepare_data_config['fee'] = self._fee
backtesting = Backtesting(prepare_data_config, self.exchange)
backtesting._set_strategy(backtesting.strategylist[0])
varholder.data, varholder.timerange = backtesting.load_bt_data()
backtesting.load_bt_data_detail()
varholder.timeframe = backtesting.timeframe
varholder.indicators = backtesting.strategy.advise_all_indicators(varholder.data)
def fill_full_varholder(self): def fill_full_varholder(self):
self.full_varHolder = VarHolder() self.full_varHolder = VarHolder()

View File

@@ -119,41 +119,37 @@ class LookaheadAnalysis(BaseAnalysis):
f"{col_name[0]}. " f"{col_name[0]}. "
f"{str(self_value)} != {str(other_value)}") f"{str(self_value)} != {str(other_value)}")
def prepare_data(self, varholder: VarHolder, pairs_to_load: List[DataFrame], backtesting=None): def prepare_data(self, varholder: VarHolder, pairs_to_load: List[DataFrame]):
if backtesting is None: if 'freqai' in self.local_config and 'identifier' in self.local_config['freqai']:
backtesting = Backtesting(deepcopy(self.local_config)) # purge previous data if the freqai model is defined
super().prepare_data(varholder, pairs_to_load, backtesting) # (to be sure nothing is carried over from older backtests)
path_to_current_identifier = (
Path(f"{self.local_config['user_data_dir']}/models/"
f"{self.local_config['freqai']['identifier']}").resolve())
# remove folder and its contents
if Path.exists(path_to_current_identifier):
shutil.rmtree(path_to_current_identifier)
# if 'freqai' in self.local_config and 'identifier' in self.local_config['freqai']: prepare_data_config = deepcopy(self.local_config)
# # purge previous data if the freqai model is defined prepare_data_config['timerange'] = (str(self.dt_to_timestamp(varholder.from_dt)) + "-" +
# # (to be sure nothing is carried over from older backtests) str(self.dt_to_timestamp(varholder.to_dt)))
# path_to_current_identifier = ( prepare_data_config['exchange']['pair_whitelist'] = pairs_to_load
# Path(f"{self.local_config['user_data_dir']}/models/"
# f"{self.local_config['freqai']['identifier']}").resolve())
# # remove folder and its contents
# if Path.exists(path_to_current_identifier):
# shutil.rmtree(path_to_current_identifier)
# prepare_data_config = deepcopy(self.local_config) if self._fee is not None:
# prepare_data_config['timerange'] = (str(self.dt_to_timestamp(varholder.from_dt)) + "-" + # Don't re-calculate fee per pair, as fee might differ per pair.
# str(self.dt_to_timestamp(varholder.to_dt))) prepare_data_config['fee'] = self._fee
# prepare_data_config['exchange']['pair_whitelist'] = pairs_to_load
# if self._fee is not None: backtesting = Backtesting(prepare_data_config, self.exchange)
# # Don't re-calculate fee per pair, as fee might differ per pair.
# prepare_data_config['fee'] = self._fee
# backtesting = Backtesting(prepare_data_config, self.exchange)
self.exchange = backtesting.exchange self.exchange = backtesting.exchange
self._fee = backtesting.fee self._fee = backtesting.fee
# backtesting._set_strategy(backtesting.strategylist[0]) backtesting._set_strategy(backtesting.strategylist[0])
# varholder.data, varholder.timerange = backtesting.load_bt_data() varholder.data, varholder.timerange = backtesting.load_bt_data()
# backtesting.load_bt_data_detail() backtesting.load_bt_data_detail()
# varholder.timeframe = backtesting.timeframe varholder.timeframe = backtesting.timeframe
# varholder.indicators = backtesting.strategy.advise_all_indicators(varholder.data) varholder.indicators = backtesting.strategy.advise_all_indicators(varholder.data)
varholder.result = self.get_result(backtesting, varholder.indicators) varholder.result = self.get_result(backtesting, varholder.indicators)
def fill_entry_and_exit_varHolders(self, result_row): def fill_entry_and_exit_varHolders(self, result_row):

View File

@@ -104,6 +104,32 @@ class RecursiveAnalysis(BaseAnalysis):
else: else:
logger.info("No lookahead bias on indicators found. Stop the process.") logger.info("No lookahead bias on indicators found. Stop the process.")
def prepare_data(self, varholder: VarHolder, pairs_to_load: List[DataFrame]):
if 'freqai' in self.local_config and 'identifier' in self.local_config['freqai']:
# purge previous data if the freqai model is defined
# (to be sure nothing is carried over from older backtests)
path_to_current_identifier = (
Path(f"{self.local_config['user_data_dir']}/models/"
f"{self.local_config['freqai']['identifier']}").resolve())
# remove folder and its contents
if Path.exists(path_to_current_identifier):
shutil.rmtree(path_to_current_identifier)
prepare_data_config = deepcopy(self.local_config)
prepare_data_config['timerange'] = (str(self.dt_to_timestamp(varholder.from_dt)) + "-" +
str(self.dt_to_timestamp(varholder.to_dt)))
prepare_data_config['exchange']['pair_whitelist'] = pairs_to_load
backtesting = Backtesting(prepare_data_config, self.exchange)
backtesting._set_strategy(backtesting.strategylist[0])
varholder.data, varholder.timerange = backtesting.load_bt_data()
backtesting.load_bt_data_detail()
varholder.timeframe = backtesting.timeframe
varholder.indicators = backtesting.strategy.advise_all_indicators(varholder.data)
def fill_partial_varholder(self, start_date, startup_candle): def fill_partial_varholder(self, start_date, startup_candle):
partial_varHolder = VarHolder() partial_varHolder = VarHolder()