ensure user defined timerange truncates final backtest so that we arent mismatching data lengths upon return to strategy. Rename DataHandler class to FreqaiDataKitchen

This commit is contained in:
robcaulk 2022-05-06 12:54:49 +02:00
parent 66715c5ba4
commit 00ff0c9b91
2 changed files with 22 additions and 6 deletions

View File

@ -22,7 +22,7 @@ SECONDS_IN_DAY = 86400
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class DataHandler: class FreqaiDataKitchen:
""" """
Class designed to handle all the data for the IFreqaiModel class model. Class designed to handle all the data for the IFreqaiModel class model.
Functionalities include holding, saving, loading, and analyzing the data. Functionalities include holding, saving, loading, and analyzing the data.
@ -291,32 +291,48 @@ class DataHandler:
bt_period = bt_split * SECONDS_IN_DAY bt_period = bt_split * SECONDS_IN_DAY
full_timerange = TimeRange.parse_timerange(tr) full_timerange = TimeRange.parse_timerange(tr)
config_timerange = TimeRange.parse_timerange(self.config["timerange"])
timerange_train = copy.deepcopy(full_timerange) timerange_train = copy.deepcopy(full_timerange)
timerange_backtest = copy.deepcopy(full_timerange) timerange_backtest = copy.deepcopy(full_timerange)
tr_training_list = [] tr_training_list = []
tr_backtesting_list = [] tr_backtesting_list = []
first = True first = True
# within_config_timerange = True
while True: while True:
if not first: if not first:
timerange_train.startts = timerange_train.startts + bt_period timerange_train.startts = timerange_train.startts + bt_period
timerange_train.stopts = timerange_train.startts + train_period timerange_train.stopts = timerange_train.startts + train_period
# if a full training period doesnt fit, we stop # make sure we finish with a full backtest
if timerange_train.stopts > full_timerange.stopts: # if timerange_train.stopts > config_timerange.stopts - bt_period:
break # within_config_timerange = False
# timerange_train.stopts = config_timerange.stopts - bt_period
# # if a full training period doesnt fit, we stop
# if timerange_train.stopts > full_timerange.stopts:
# break
first = False first = False
start = datetime.datetime.utcfromtimestamp(timerange_train.startts) start = datetime.datetime.utcfromtimestamp(timerange_train.startts)
stop = datetime.datetime.utcfromtimestamp(timerange_train.stopts) stop = datetime.datetime.utcfromtimestamp(timerange_train.stopts)
tr_training_list.append(start.strftime("%Y%m%d") + "-" + stop.strftime("%Y%m%d")) tr_training_list.append(start.strftime("%Y%m%d") + "-" + stop.strftime("%Y%m%d"))
# associated backtest period # associated backtest period
if timerange_backtest.stopts > config_timerange.stopts:
timerange_backtest.stopts = config_timerange.stopts
timerange_backtest.startts = timerange_train.stopts timerange_backtest.startts = timerange_train.stopts
timerange_backtest.stopts = timerange_backtest.startts + bt_period timerange_backtest.stopts = timerange_backtest.startts + bt_period
start = datetime.datetime.utcfromtimestamp(timerange_backtest.startts) start = datetime.datetime.utcfromtimestamp(timerange_backtest.startts)
stop = datetime.datetime.utcfromtimestamp(timerange_backtest.stopts) stop = datetime.datetime.utcfromtimestamp(timerange_backtest.stopts)
tr_backtesting_list.append(start.strftime("%Y%m%d") + "-" + stop.strftime("%Y%m%d")) tr_backtesting_list.append(start.strftime("%Y%m%d") + "-" + stop.strftime("%Y%m%d"))
# ensure we are predicting on exactly same amount of data as requested by user defined
# --timerange
if timerange_backtest.stopts == config_timerange.stopts:
break
print(tr_training_list, tr_backtesting_list)
return tr_training_list, tr_backtesting_list return tr_training_list, tr_backtesting_list
def slice_dataframe(self, tr: str, df: DataFrame) -> DataFrame: def slice_dataframe(self, tr: str, df: DataFrame) -> DataFrame:

View File

@ -8,7 +8,7 @@ import numpy as np
import pandas as pd import pandas as pd
from pandas import DataFrame from pandas import DataFrame
from freqtrade.freqai.data_handler import DataHandler from freqtrade.freqai.data_kitchen import FreqaiDataKitchen
pd.options.mode.chained_assignment = None pd.options.mode.chained_assignment = None
@ -55,7 +55,7 @@ class IFreqaiModel(ABC):
:metadata: pair metadataa coming from strategy. :metadata: pair metadataa coming from strategy.
""" """
self.pair = metadata["pair"] self.pair = metadata["pair"]
self.dh = DataHandler(self.config, dataframe) self.dh = FreqaiDataKitchen(self.config, dataframe)
logger.info("going to train %s timeranges", len(self.dh.training_timeranges)) logger.info("going to train %s timeranges", len(self.dh.training_timeranges))