backtest_live_models - fix issue with timerange BT and 2 trainings within same candle (no data)
This commit is contained in:
parent
14b96aaa38
commit
72aa47fc51
@ -465,6 +465,11 @@ class FreqaiDataKitchen:
|
||||
|
||||
tr_backtesting_list_timerange = []
|
||||
pair = self.pair.split("/")[0].split(":")[0]
|
||||
if pair not in self.backtest_live_models_data["pairs_end_dates"]:
|
||||
raise OperationalException(
|
||||
f"Model not available for pair {self.pair}. "
|
||||
"Please, try again after removing this pair from the configuration file."
|
||||
)
|
||||
pair_data = self.backtest_live_models_data["pairs_end_dates"][pair]
|
||||
model_end_dates = []
|
||||
backtesting_timerange = self.backtest_live_models_data["backtesting_timerange"]
|
||||
|
@ -257,6 +257,21 @@ class IFreqaiModel(ABC):
|
||||
dataframe_train = dk.slice_dataframe(tr_train, dataframe)
|
||||
dataframe_backtest = dk.slice_dataframe(tr_backtest, dataframe)
|
||||
|
||||
if dk.backtest_live_models and len(dataframe_backtest) == 0:
|
||||
tr_backtest_startts_str = datetime.fromtimestamp(
|
||||
tr_backtest.startts,
|
||||
tz=timezone.utc).strftime(DATETIME_PRINT_FORMAT)
|
||||
tr_backtest_stopts_str = datetime.fromtimestamp(
|
||||
tr_backtest.stopts,
|
||||
tz=timezone.utc).strftime(DATETIME_PRINT_FORMAT)
|
||||
logger.info(
|
||||
f"No data found for pair {pair} "
|
||||
f" from {tr_backtest_startts_str} "
|
||||
f"to {tr_backtest_stopts_str}. "
|
||||
"Probably more than one training within the same candle period."
|
||||
)
|
||||
continue
|
||||
|
||||
trained_timestamp = tr_train
|
||||
tr_train_startts_str = datetime.fromtimestamp(
|
||||
tr_train.startts,
|
||||
@ -264,6 +279,7 @@ class IFreqaiModel(ABC):
|
||||
tr_train_stopts_str = datetime.fromtimestamp(
|
||||
tr_train.stopts,
|
||||
tz=timezone.utc).strftime(DATETIME_PRINT_FORMAT)
|
||||
|
||||
if not dk.backtest_live_models:
|
||||
logger.info(
|
||||
f"Training {pair}, {self.pair_it}/{self.total_pairs} pairs"
|
||||
|
@ -2,7 +2,7 @@
|
||||
FreqAI generic functions
|
||||
"""
|
||||
import logging
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Tuple
|
||||
|
||||
@ -89,7 +89,17 @@ def get_timerange_from_ready_models(models_path: Path) -> Tuple[TimeRange, str,
|
||||
all_models_end_dates.sort()
|
||||
start = datetime.fromtimestamp(min(all_models_end_dates), tz=timezone.utc)
|
||||
stop = datetime.fromtimestamp(max(all_models_end_dates), tz=timezone.utc)
|
||||
backtesting_string_timerange = f"{start.strftime('%Y%m%d')}-{stop.strftime('%Y%m%d')}"
|
||||
end_date_string_timerange = stop
|
||||
if (
|
||||
finish_timestamp < int(datetime.now(tz=timezone.utc).timestamp()) and
|
||||
datetime.now(tz=timezone.utc).strftime('%Y%m%d') != stop.strftime('%Y%m%d')
|
||||
):
|
||||
# add 1 day to string timerange to ensure BT module will load all dataframe data
|
||||
end_date_string_timerange = stop + timedelta(days=1)
|
||||
|
||||
backtesting_string_timerange = (
|
||||
f"{start.strftime('%Y%m%d')}-{end_date_string_timerange.strftime('%Y%m%d')}"
|
||||
)
|
||||
backtesting_timerange = TimeRange(
|
||||
'date', 'date', min(all_models_end_dates), max(all_models_end_dates)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user