save_live_data_backtest - added docs and tests

This commit is contained in:
Wagner Costa Santos
2022-11-17 15:20:07 -03:00
parent 99bff9cbfa
commit 3903b04d3f
6 changed files with 114 additions and 11 deletions

View File

@@ -1541,14 +1541,16 @@ class FreqaiDataKitchen:
if self.backtesting_live_model_path.is_file():
saved_dataframe = self.get_backtesting_live_dataframe()
concat_dataframe = pd.concat([saved_dataframe, last_row_df])
concat_dataframe.reset_index(drop=True).to_feather(
self.backtesting_live_model_path, compression_level=9, compression='lz4')
self.save_backtesting_live_dataframe_to_feather(concat_dataframe)
else:
last_row_df.reset_index(drop=True).to_feather(
self.backtesting_live_model_path, compression_level=9, compression='lz4')
self.save_backtesting_live_dataframe_to_feather(last_row_df)
shutil.copy(self.backtesting_live_model_path, self.backtesting_live_model_bkp_path)
def save_backtesting_live_dataframe_to_feather(self, dataframe: DataFrame):
dataframe.reset_index(drop=True).to_feather(
self.backtesting_live_model_path, compression_level=9, compression='lz4')
def get_backtesting_live_dataframe(
self
) -> DataFrame:

View File

@@ -694,7 +694,8 @@ class IFreqaiModel(ABC):
for label in full_labels:
if self.dd.historic_predictions[dk.pair][label].dtype == object:
continue
f = spy.stats.norm.fit(self.dd.historic_predictions[dk.pair][label].tail(num_candles))
f = spy.stats.norm.fit(
self.dd.historic_predictions[dk.pair][label].fillna(0).tail(num_candles))
dk.data["labels_mean"][label], dk.data["labels_std"][label] = f[0], f[1]
return
@@ -882,11 +883,7 @@ class IFreqaiModel(ABC):
if index >= fit_live_predictions_candles:
self.dd.historic_predictions[self.dk.pair] = (
dk.full_df.iloc[index - fit_live_predictions_candles:index])
else:
self.dd.historic_predictions[self.dk.pair] = dk.full_df.iloc[:index]
self.fit_live_predictions(self.dk, self.dk.pair)
if index >= fit_live_predictions_candles:
self.fit_live_predictions(self.dk, self.dk.pair)
for label in label_columns:
if dk.full_df[label].dtype == object:
continue
@@ -899,6 +896,7 @@ class IFreqaiModel(ABC):
for extra_col in self.dk.data["extra_returns_per_train"]:
dk.full_df.at[index, f"{extra_col}"] = (
self.dk.data["extra_returns_per_train"][extra_col])
return
# Following methods which are overridden by user made prediction models.