fix issue with different backtesting prediction size

This commit is contained in:
Wagner Costa Santos 2022-11-02 15:49:51 -03:00
parent 09e0a8d4df
commit 23b6915dde
2 changed files with 18 additions and 8 deletions

View File

@ -1312,14 +1312,16 @@ class FreqaiDataKitchen:
append_df = pd.read_hdf(self.backtesting_results_path) append_df = pd.read_hdf(self.backtesting_results_path)
return append_df return append_df
def check_if_backtest_prediction_exists( def check_if_backtest_prediction_is_valid(
self self,
length_backtesting_dataframe: int
) -> bool: ) -> bool:
""" """
Check if a backtesting prediction already exists Check if a backtesting prediction already exists and if the predictions
:param dk: FreqaiDataKitchen to append has the same sime of backtesting dataframe slice
:param length_backtesting_dataframe: Length of backtesting dataframe slice
:return: :return:
:boolean: whether the prediction file exists or not. :boolean: whether the prediction file is valid.
""" """
path_to_predictionfile = Path(self.full_path / path_to_predictionfile = Path(self.full_path /
self.backtest_predictions_folder / self.backtest_predictions_folder /
@ -1327,10 +1329,18 @@ class FreqaiDataKitchen:
self.backtesting_results_path = path_to_predictionfile self.backtesting_results_path = path_to_predictionfile
file_exists = path_to_predictionfile.is_file() file_exists = path_to_predictionfile.is_file()
if file_exists: if file_exists:
append_df = self.get_backtesting_prediction()
if len(append_df) == length_backtesting_dataframe:
logger.info(f"Found backtesting prediction file at {path_to_predictionfile}") logger.info(f"Found backtesting prediction file at {path_to_predictionfile}")
return True
else:
logger.info("A new backtesting prediction file is required. "
"(Number of predictions is different of dataframe length).")
return False
else: else:
logger.info( logger.info(
f"Could not find backtesting prediction file at {path_to_predictionfile}" f"Could not find backtesting prediction file at {path_to_predictionfile}"
) )
return file_exists return False

View File

@ -275,7 +275,7 @@ class IFreqaiModel(ABC):
dk.set_new_model_names(pair, trained_timestamp) dk.set_new_model_names(pair, trained_timestamp)
if dk.check_if_backtest_prediction_exists(): if dk.check_if_backtest_prediction_is_valid(len(dataframe_backtest)):
self.dd.load_metadata(dk) self.dd.load_metadata(dk)
dk.find_features(dataframe_train) dk.find_features(dataframe_train)
self.check_if_feature_list_matches_strategy(dk) self.check_if_feature_list_matches_strategy(dk)