*breaking change* simplify user strat by consolidating feature loops into backend

This commit is contained in:
robcaulk
2022-07-21 12:24:22 +02:00
parent e7337728bf
commit 8f86b0deaa
5 changed files with 42 additions and 72 deletions

View File

@@ -1043,7 +1043,12 @@ class FreqaiDataKitchen:
# return corr_dataframes, base_dataframes
def use_strategy_to_populate_indicators(
self, strategy: IStrategy, corr_dataframes: dict, base_dataframes: dict, pair: str
self,
strategy: IStrategy,
corr_dataframes: dict = {},
base_dataframes: dict = {},
pair: str = "",
prediction_dataframe: DataFrame = pd.DataFrame(),
) -> DataFrame:
"""
Use the user defined strategy for populating indicators during
@@ -1058,16 +1063,31 @@ class FreqaiDataKitchen:
:returns:
dataframe: DataFrame = dataframe containing populated indicators
"""
dataframe = base_dataframes[self.config["timeframe"]].copy()
# for prediction dataframe creation, we let dataprovider handle everything in the strategy
# so we create empty dictionaries, which allows us to pass None to
# `populate_any_indicators()`. Signaling we want the dp to give us the live dataframe.
tfs = self.freqai_config.get("feature_parameters", {}).get("include_timeframes")
pairs = self.freqai_config.get("feature_parameters", {}).get("include_corr_pairlist", [])
if not prediction_dataframe.empty:
dataframe = prediction_dataframe.copy()
for tf in tfs:
base_dataframes[tf] = None
for p in pairs:
if p not in corr_dataframes:
corr_dataframes[p] = {}
corr_dataframes[p][tf] = None
else:
dataframe = base_dataframes[self.config["timeframe"]].copy()
sgi = True
for tf in self.freqai_config.get("feature_parameters", {}).get("include_timeframes"):
for tf in tfs:
dataframe = strategy.populate_any_indicators(
pair,
pair,
dataframe.copy(),
tf,
base_dataframes[tf],
informative=base_dataframes[tf],
coin=pair.split("/")[0] + "-",
set_generalized_indicators=sgi,
)
@@ -1081,7 +1101,7 @@ class FreqaiDataKitchen:
i,
dataframe.copy(),
tf,
corr_dataframes[i][tf],
informative=corr_dataframes[i][tf],
coin=i.split("/")[0] + "-",
)

View File

@@ -281,6 +281,10 @@ class IFreqaiModel(ABC):
# load the model and associated data into the data kitchen
self.model = dk.load_data(coin=metadata["pair"])
dataframe = self.dk.use_strategy_to_populate_indicators(
strategy, prediction_dataframe=dataframe, pair=metadata["pair"]
)
if not self.model:
logger.warning(
f"No model ready for {metadata['pair']}, returning null values to strategy."