pr review - refactoring backtesting freqai
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import copy
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Tuple
|
||||
@@ -1108,15 +1107,25 @@ class FreqaiDataKitchen:
|
||||
:param file_name: h5 file name
|
||||
:param root_folder: folder to save h5 file
|
||||
"""
|
||||
os.makedirs(root_folder, exist_ok=True)
|
||||
append_df.to_hdf(file_name, key='append_df', mode='w')
|
||||
backtesting_root = Path(
|
||||
self.full_path
|
||||
/ root_folder
|
||||
)
|
||||
if not backtesting_root.is_dir():
|
||||
backtesting_root.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def get_backtesting_prediction(self, prediction_file_name: str) -> DataFrame:
|
||||
full_file_path = Path(self.full_path / root_folder / file_name)
|
||||
append_df.to_hdf(full_file_path, key='append_df', mode='w')
|
||||
|
||||
def get_backtesting_prediction(
|
||||
self, root_prediction: str, prediction_file_name: str
|
||||
) -> DataFrame:
|
||||
"""
|
||||
Retrive from disk the prediction dataframe
|
||||
:param prediction_file_name: prediction file full path
|
||||
:return:
|
||||
:Dataframe: Backtesting prediction from current backtesting period
|
||||
"""
|
||||
append_df = pd.read_hdf(prediction_file_name)
|
||||
prediction_path = Path(self.full_path / root_prediction / prediction_file_name)
|
||||
append_df = pd.read_hdf(prediction_path)
|
||||
return append_df
|
||||
|
@@ -234,12 +234,12 @@ class IFreqaiModel(ABC):
|
||||
if self.backtest_prediction_exists(
|
||||
metadata["pair"], dk, trained_timestamp=trained_timestamp_int
|
||||
):
|
||||
prediction_filename, _ = self.get_backtesting_prediction_file_name(
|
||||
prediction_filename, root_prediction = self.get_backtesting_prediction_file_name(
|
||||
metadata["pair"],
|
||||
dk,
|
||||
trained_timestamp=int(trained_timestamp.stopts))
|
||||
|
||||
append_df = dk.get_backtesting_prediction(prediction_filename)
|
||||
append_df = dk.get_backtesting_prediction(root_prediction, prediction_filename)
|
||||
dk.append_predictions(append_df)
|
||||
else:
|
||||
if not self.model_exists(
|
||||
@@ -680,10 +680,10 @@ class IFreqaiModel(ABC):
|
||||
:boolean: whether the prediction file exists or not.
|
||||
"""
|
||||
if not self.live:
|
||||
prediction_file_name, _ = self.get_backtesting_prediction_file_name(
|
||||
prediction_file_name, root_prediction = self.get_backtesting_prediction_file_name(
|
||||
pair, dk, trained_timestamp
|
||||
)
|
||||
path_to_predictionfile = Path(prediction_file_name)
|
||||
path_to_predictionfile = Path(dk.full_path / root_prediction / prediction_file_name)
|
||||
|
||||
file_exists = path_to_predictionfile.is_file()
|
||||
if file_exists and not scanning:
|
||||
@@ -711,8 +711,8 @@ class IFreqaiModel(ABC):
|
||||
"""
|
||||
coin, _ = pair.split("/")
|
||||
prediction_base_filename = f"{coin.lower()}_{trained_timestamp}"
|
||||
root_prediction = f'{dk.full_path}/backtesting_predictions'
|
||||
prediction_file_name = f"{root_prediction}/{prediction_base_filename}_predictions.h5"
|
||||
root_prediction = 'backtesting_predictions'
|
||||
prediction_file_name = f"{prediction_base_filename}_predictions.h5"
|
||||
return prediction_file_name, root_prediction
|
||||
|
||||
# Following methods which are overridden by user made prediction models.
|
||||
|
Reference in New Issue
Block a user