change BT prediction files to feather format
This commit is contained in:
parent
df979ece33
commit
8ea58ab352
@ -1317,41 +1317,24 @@ class FreqaiDataKitchen:
|
|||||||
self, append_df: DataFrame
|
self, append_df: DataFrame
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Save prediction dataframe from backtesting to h5 file format
|
Save prediction dataframe from backtesting to feather file format
|
||||||
:param append_df: dataframe for backtesting period
|
:param append_df: dataframe for backtesting period
|
||||||
"""
|
"""
|
||||||
full_predictions_folder = Path(self.full_path / self.backtest_predictions_folder)
|
full_predictions_folder = Path(self.full_path / self.backtest_predictions_folder)
|
||||||
if not full_predictions_folder.is_dir():
|
if not full_predictions_folder.is_dir():
|
||||||
full_predictions_folder.mkdir(parents=True, exist_ok=True)
|
full_predictions_folder.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
append_df.to_hdf(self.backtesting_results_path, key=self.model_filename)
|
append_df.to_feather(self.backtesting_results_path)
|
||||||
|
|
||||||
def get_backtesting_prediction(
|
def get_backtesting_prediction(
|
||||||
self
|
self
|
||||||
) -> DataFrame:
|
) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
Get prediction dataframe from h5 file format
|
Get prediction dataframe from feather file format
|
||||||
"""
|
"""
|
||||||
append_df = self.backtesting_h5_data[self.model_filename]
|
append_df = pd.read_feather(self.backtesting_results_path)
|
||||||
return append_df
|
return append_df
|
||||||
|
|
||||||
def load_prediction_pair_file(
|
|
||||||
self
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
Load prediction file if it exists
|
|
||||||
"""
|
|
||||||
pair_file_name = self.pair.split(':')[0].replace('/', '_').lower()
|
|
||||||
path_to_predictionfile = Path(self.full_path /
|
|
||||||
self.backtest_predictions_folder /
|
|
||||||
f"{pair_file_name}_prediction.h5")
|
|
||||||
self.backtesting_results_path = path_to_predictionfile
|
|
||||||
file_exists = path_to_predictionfile.is_file()
|
|
||||||
if file_exists:
|
|
||||||
self.backtesting_h5_data = pd.HDFStore(path_to_predictionfile)
|
|
||||||
else:
|
|
||||||
self.backtesting_h5_data = {}
|
|
||||||
|
|
||||||
def check_if_backtest_prediction_is_valid(
|
def check_if_backtest_prediction_is_valid(
|
||||||
self,
|
self,
|
||||||
len_backtest_df: int
|
len_backtest_df: int
|
||||||
@ -1363,11 +1346,17 @@ class FreqaiDataKitchen:
|
|||||||
:return:
|
:return:
|
||||||
:boolean: whether the prediction file is valid.
|
:boolean: whether the prediction file is valid.
|
||||||
"""
|
"""
|
||||||
if self.model_filename in self.backtesting_h5_data:
|
path_to_predictionfile = Path(self.full_path /
|
||||||
|
self.backtest_predictions_folder /
|
||||||
|
f"{self.model_filename}_prediction.feather")
|
||||||
|
self.backtesting_results_path = path_to_predictionfile
|
||||||
|
|
||||||
|
file_exists = path_to_predictionfile.is_file()
|
||||||
|
|
||||||
|
if file_exists:
|
||||||
append_df = self.get_backtesting_prediction()
|
append_df = self.get_backtesting_prediction()
|
||||||
if len(append_df) == len_backtest_df and 'date' in append_df:
|
if len(append_df) == len_backtest_df and 'date' in append_df:
|
||||||
logger.info("Found backtesting prediction file "
|
logger.info(f"Found backtesting prediction file at {path_to_predictionfile}")
|
||||||
f"at {self.backtesting_results_path.name}")
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
logger.info("A new backtesting prediction file is required. "
|
logger.info("A new backtesting prediction file is required. "
|
||||||
@ -1376,8 +1365,7 @@ class FreqaiDataKitchen:
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
logger.info(
|
logger.info(
|
||||||
"Could not find backtesting prediction file "
|
f"Could not find backtesting prediction file at {path_to_predictionfile}"
|
||||||
f"at {self.backtesting_results_path.name}"
|
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -275,7 +275,6 @@ class IFreqaiModel(ABC):
|
|||||||
|
|
||||||
self.pair_it += 1
|
self.pair_it += 1
|
||||||
train_it = 0
|
train_it = 0
|
||||||
dk.load_prediction_pair_file()
|
|
||||||
# Loop enforcing the sliding window training/backtesting paradigm
|
# Loop enforcing the sliding window training/backtesting paradigm
|
||||||
# tr_train is the training time range e.g. 1 historical month
|
# tr_train is the training time range e.g. 1 historical month
|
||||||
# tr_backtest is the backtesting time range e.g. the week directly
|
# tr_backtest is the backtesting time range e.g. the week directly
|
||||||
|
Loading…
Reference in New Issue
Block a user