fix backtesting bug, undo move of label stat calc, fix example strat exit logic

This commit is contained in:
robcaulk 2022-07-29 17:27:35 +02:00
parent 08d3ac7ef8
commit f22b140782
4 changed files with 12 additions and 15 deletions

View File

@ -635,20 +635,20 @@ class FreqaiDataKitchen:
Append backtest prediction from current backtest period to all previous periods
"""
self.append_df = DataFrame()
append_df = DataFrame()
for label in self.label_list:
self.append_df[label] = predictions[label]
self.append_df[f"{label}_mean"] = self.data["labels_mean"][label]
self.append_df[f"{label}_std"] = self.data["labels_std"][label]
append_df[label] = predictions[label]
append_df[f"{label}_mean"] = self.data["labels_mean"][label]
append_df[f"{label}_std"] = self.data["labels_std"][label]
self.append_df["do_predict"] = do_predict
append_df["do_predict"] = do_predict
if self.freqai_config["feature_parameters"].get("DI_threshold", 0) > 0:
self.append_df["DI_values"] = self.DI_values
append_df["DI_values"] = self.DI_values
if self.full_df.empty:
self.full_df = self.append_df
self.full_df = append_df
else:
self.full_df = pd.concat([self.full_df, self.append_df], axis=0)
self.full_df = pd.concat([self.full_df, append_df], axis=0)
return
@ -668,7 +668,7 @@ class FreqaiDataKitchen:
to_keep = [col for col in dataframe.columns if not col.startswith("&")]
self.return_dataframe = pd.concat([dataframe[to_keep], self.full_df], axis=1)
self.append_df = DataFrame()
# self.append_df = DataFrame()
self.full_df = DataFrame()
return

View File

@ -1,7 +1,6 @@
# import contextlib
import copy
import datetime
import gc
import logging
import shutil
import threading
@ -183,8 +182,6 @@ class IFreqaiModel(ABC):
(_, _, _) = self.dd.get_pair_dict_info(metadata["pair"])
train_it += 1
total_trains = len(dk.backtesting_timeranges)
gc.collect()
dk.data = {} # clean the pair specific data between training window sliding
self.training_timerange = tr_train
dataframe_train = dk.slice_dataframe(tr_train, dataframe)
dataframe_backtest = dk.slice_dataframe(tr_backtest, dataframe)

View File

@ -56,6 +56,8 @@ class BaseRegressionModel(IFreqaiModel):
f"{end_date}--------------------")
# split data into train/test data.
data_dictionary = dk.make_train_test_datasets(features_filtered, labels_filtered)
if not self.freqai_info.get('fit_live_predictions', 0) or not self.live:
dk.fit_labels()
# normalize all data based on train_dataset only
data_dictionary = dk.normalize_data(data_dictionary)
@ -75,8 +77,6 @@ class BaseRegressionModel(IFreqaiModel):
if self.freqai_info.get('fit_live_predictions_candles', 0) and self.live:
self.fit_live_predictions(dk)
else:
dk.fit_labels()
self.dd.save_historic_predictions_to_disk()

View File

@ -235,7 +235,7 @@ class FreqaiExampleStrategy(IStrategy):
if (
"prediction" + entry_tag not in pair_dict[pair]
or pair_dict[pair]["prediction" + entry_tag] > 0
or pair_dict[pair]["prediction" + entry_tag] == 0
):
with self.freqai.lock:
pair_dict[pair]["prediction" + entry_tag] = abs(trade_candle["&-s_close"])