Increase performance by only predicting on most recent candle instead of full strat provided dataframe. Collect predictions and store them so that we can feed true predictions back to strategy (so that frequi isnt updating historic predictions based on newly trained models).

This commit is contained in:
robcaulk 2022-05-30 11:37:05 +02:00
parent 2f1a2c1cd7
commit a20651efd8
3 changed files with 37 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import copy
import json
import logging
from pathlib import Path
@ -24,6 +25,7 @@ class FreqaiDataDrawer:
self.pair_dict: Dict[str, Any] = {}
# dictionary holding all actively inferenced models in memory given a model filename
self.model_dictionary: Dict[str, Any] = {}
self.model_return_values: Dict[str, Any] = {}
self.pair_data_dict: Dict[str, Any] = {}
self.full_path = full_path
self.load_drawer_from_disk()
@ -83,3 +85,27 @@ class FreqaiDataDrawer:
self.pair_dict[p]['priority'] -= 1
# send pair to end of queue
self.pair_dict[pair]['priority'] = len(self.pair_dict)
def set_initial_return_values(self, pair, dh):
self.model_return_values[pair] = {}
self.model_return_values[pair]['predictions'] = dh.full_predictions
self.model_return_values[pair]['do_preds'] = dh.full_do_predict
self.model_return_values[pair]['target_mean'] = dh.full_target_mean
self.model_return_values[pair]['target_std'] = dh.full_target_std
def append_model_predictions(self, pair, predictions, do_preds,
target_mean, target_std, dh) -> None:
pred_store = self.model_return_values[pair]['predictions']
do_pred_store = self.model_return_values[pair]['do_preds']
tm_store = self.model_return_values[pair]['target_mean']
ts_store = self.model_return_values[pair]['target_std']
pred_store = np.append(pred_store[1:], predictions[-1])
do_pred_store = np.append(do_pred_store[1:], do_preds[-1])
tm_store = np.append(tm_store[1:], target_mean)
ts_store = np.append(ts_store[1:], target_std)
dh.full_predictions = copy.deepcopy(pred_store)
dh.full_do_predict = copy.deepcopy(do_pred_store)
dh.full_target_mean = copy.deepcopy(tm_store)
dh.full_target_std = copy.deepcopy(ts_store)

View File

@ -623,7 +623,7 @@ class FreqaiDataKitchen:
Append backtest prediction from current backtest period to all previous periods
"""
ones = np.ones(len_dataframe)
ones = np.ones(len(predictions))
target_mean, target_std = ones * self.data["target_mean"], ones * self.data["target_std"]
self.full_predictions = np.append(self.full_predictions, predictions)

View File

@ -219,8 +219,16 @@ class IFreqaiModel(ABC):
self.check_if_feature_list_matches_strategy(dataframe, dh)
preds, do_preds = self.predict(dataframe, dh)
dh.append_predictions(preds, do_preds, len(dataframe))
if metadata['pair'] not in self.data_drawer.model_return_values:
preds, do_preds = self.predict(dataframe, dh)
dh.append_predictions(preds, do_preds, len(dataframe))
dh.fill_predictions(len(dataframe))
self.data_drawer.set_initial_return_values(metadata['pair'], dh)
else:
preds, do_preds = self.predict(dataframe.iloc[-2:], dh)
self.data_drawer.append_model_predictions(metadata['pair'], preds, do_preds,
self.dh.data["target_mean"],
self.dh.data["target_std"], dh)
return dh