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:
parent
66715c5ba4
commit
00ff0c9b91
@ -22,7 +22,7 @@ SECONDS_IN_DAY = 86400
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DataHandler:
|
||||
class FreqaiDataKitchen:
|
||||
"""
|
||||
Class designed to handle all the data for the IFreqaiModel class model.
|
||||
Functionalities include holding, saving, loading, and analyzing the data.
|
||||
@ -291,32 +291,48 @@ class DataHandler:
|
||||
bt_period = bt_split * SECONDS_IN_DAY
|
||||
|
||||
full_timerange = TimeRange.parse_timerange(tr)
|
||||
config_timerange = TimeRange.parse_timerange(self.config["timerange"])
|
||||
timerange_train = copy.deepcopy(full_timerange)
|
||||
timerange_backtest = copy.deepcopy(full_timerange)
|
||||
|
||||
tr_training_list = []
|
||||
tr_backtesting_list = []
|
||||
first = True
|
||||
# within_config_timerange = True
|
||||
while True:
|
||||
if not first:
|
||||
timerange_train.startts = timerange_train.startts + bt_period
|
||||
timerange_train.stopts = timerange_train.startts + train_period
|
||||
|
||||
# if a full training period doesnt fit, we stop
|
||||
if timerange_train.stopts > full_timerange.stopts:
|
||||
break
|
||||
# make sure we finish with a full backtest
|
||||
# if timerange_train.stopts > config_timerange.stopts - bt_period:
|
||||
# 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
|
||||
start = datetime.datetime.utcfromtimestamp(timerange_train.startts)
|
||||
stop = datetime.datetime.utcfromtimestamp(timerange_train.stopts)
|
||||
tr_training_list.append(start.strftime("%Y%m%d") + "-" + stop.strftime("%Y%m%d"))
|
||||
|
||||
# associated backtest period
|
||||
if timerange_backtest.stopts > config_timerange.stopts:
|
||||
timerange_backtest.stopts = config_timerange.stopts
|
||||
|
||||
timerange_backtest.startts = timerange_train.stopts
|
||||
timerange_backtest.stopts = timerange_backtest.startts + bt_period
|
||||
|
||||
start = datetime.datetime.utcfromtimestamp(timerange_backtest.startts)
|
||||
stop = datetime.datetime.utcfromtimestamp(timerange_backtest.stopts)
|
||||
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
|
||||
|
||||
def slice_dataframe(self, tr: str, df: DataFrame) -> DataFrame:
|
@ -8,7 +8,7 @@ import numpy as np
|
||||
import pandas as pd
|
||||
from pandas import DataFrame
|
||||
|
||||
from freqtrade.freqai.data_handler import DataHandler
|
||||
from freqtrade.freqai.data_kitchen import FreqaiDataKitchen
|
||||
|
||||
|
||||
pd.options.mode.chained_assignment = None
|
||||
@ -55,7 +55,7 @@ class IFreqaiModel(ABC):
|
||||
:metadata: pair metadataa coming from strategy.
|
||||
"""
|
||||
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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user