*BREAKING CHANGE* remove unnecessary arguments from populate_any_indicators(), accommodate tests

This commit is contained in:
robcaulk 2022-07-31 17:05:29 +02:00
parent 153336d424
commit d830105605
5 changed files with 35 additions and 22 deletions

View File

@ -892,29 +892,26 @@ class FreqaiDataKitchen:
else: else:
dataframe = base_dataframes[self.config["timeframe"]].copy() dataframe = base_dataframes[self.config["timeframe"]].copy()
sgi = True sgi = False
for tf in tfs: for tf in tfs:
if tf == tfs[-1]:
sgi = True # doing this last allows user to use all tf raw prices in labels
dataframe = strategy.populate_any_indicators( dataframe = strategy.populate_any_indicators(
pair,
pair, pair,
dataframe.copy(), dataframe.copy(),
tf, tf,
informative=base_dataframes[tf], informative=base_dataframes[tf],
coin=pair.split("/")[0] + "-", set_generalized_indicators=sgi
set_generalized_indicators=sgi,
) )
sgi = False
if pairs: if pairs:
for i in pairs: for i in pairs:
if pair in i: if pair in i:
continue # dont repeat anything from whitelist continue # dont repeat anything from whitelist
dataframe = strategy.populate_any_indicators( dataframe = strategy.populate_any_indicators(
pair,
i, i,
dataframe.copy(), dataframe.copy(),
tf, tf,
informative=corr_dataframes[i][tf], informative=corr_dataframes[i][tf]
coin=i.split("/")[0] + "-",
) )
return dataframe return dataframe

View File

@ -557,8 +557,8 @@ class IStrategy(ABC, HyperStrategyMixin):
""" """
return None return None
def populate_any_indicators(self, basepair: str, pair: str, df: DataFrame, tf: str, def populate_any_indicators(self, pair: str, df: DataFrame, tf: str,
informative: DataFrame = None, coin: str = "", informative: DataFrame = None,
set_generalized_indicators: bool = False) -> DataFrame: set_generalized_indicators: bool = False) -> DataFrame:
""" """
Function designed to automatically generate, name and merge features Function designed to automatically generate, name and merge features
@ -570,7 +570,6 @@ class IStrategy(ABC, HyperStrategyMixin):
:param df: strategy dataframe which will receive merges from informatives :param df: strategy dataframe which will receive merges from informatives
:param tf: timeframe of the dataframe which will modify the feature names :param tf: timeframe of the dataframe which will modify the feature names
:param informative: the dataframe associated with the informative pair :param informative: the dataframe associated with the informative pair
:param coin: the name of the coin which will modify the feature names.
""" """
return df return df

View File

@ -65,7 +65,7 @@ class FreqaiExampleStrategy(IStrategy):
return informative_pairs return informative_pairs
def populate_any_indicators( def populate_any_indicators(
self, metadata, pair, df, tf, informative=None, coin="", set_generalized_indicators=False self, pair, df, tf, informative=None, set_generalized_indicators=False
): ):
""" """
Function designed to automatically generate, name and merge features Function designed to automatically generate, name and merge features
@ -78,9 +78,10 @@ class FreqaiExampleStrategy(IStrategy):
:param df: strategy dataframe which will receive merges from informatives :param df: strategy dataframe which will receive merges from informatives
:param tf: timeframe of the dataframe which will modify the feature names :param tf: timeframe of the dataframe which will modify the feature names
:param informative: the dataframe associated with the informative pair :param informative: the dataframe associated with the informative pair
:param coin: the name of the coin which will modify the feature names.
""" """
coin = pair.split('/')[0]
with self.freqai.lock: with self.freqai.lock:
if informative is None: if informative is None:
informative = self.dp.get_pair_dataframe(pair, tf) informative = self.dp.get_pair_dataframe(pair, tf)
@ -92,11 +93,8 @@ class FreqaiExampleStrategy(IStrategy):
informative[f"%-{coin}rsi-period_{t}"] = ta.RSI(informative, timeperiod=t) informative[f"%-{coin}rsi-period_{t}"] = ta.RSI(informative, timeperiod=t)
informative[f"%-{coin}mfi-period_{t}"] = ta.MFI(informative, timeperiod=t) informative[f"%-{coin}mfi-period_{t}"] = ta.MFI(informative, timeperiod=t)
informative[f"%-{coin}adx-period_{t}"] = ta.ADX(informative, window=t) informative[f"%-{coin}adx-period_{t}"] = ta.ADX(informative, window=t)
informative[f"{coin}20sma-period_{t}"] = ta.SMA(informative, timeperiod=t) informative[f"{coin}sma-period_{t}"] = ta.SMA(informative, timeperiod=t)
informative[f"{coin}21ema-period_{t}"] = ta.EMA(informative, timeperiod=t) informative[f"{coin}ema-period_{t}"] = ta.EMA(informative, timeperiod=t)
informative[f"%-{coin}close_over_20sma-period_{t}"] = (
informative["close"] / informative[f"{coin}20sma-period_{t}"]
)
informative[f"%-{coin}mfi-period_{t}"] = ta.MFI(informative, timeperiod=t) informative[f"%-{coin}mfi-period_{t}"] = ta.MFI(informative, timeperiod=t)
@ -148,8 +146,6 @@ class FreqaiExampleStrategy(IStrategy):
df["%-hour_of_day"] = (df["date"].dt.hour + 1) / 25 df["%-hour_of_day"] = (df["date"].dt.hour + 1) / 25
# user adds targets here by prepending them with &- (see convention below) # user adds targets here by prepending them with &- (see convention below)
# If user wishes to use multiple targets, a multioutput prediction model
# needs to be used such as templates/CatboostPredictionMultiModel.py
df["&-s_close"] = ( df["&-s_close"] = (
df["close"] df["close"]
.shift(-self.freqai_info["feature_parameters"]["label_period_candles"]) .shift(-self.freqai_info["feature_parameters"]["label_period_candles"])
@ -159,6 +155,23 @@ class FreqaiExampleStrategy(IStrategy):
- 1 - 1
) )
# If user wishes to use multiple targets, they can add more by
# appending more columns with '&'. User should keep in mind that multi targets
# requires a multioutput prediction model such as
# templates/CatboostPredictionMultiModel.py,
# df["&-s_range"] = (
# df["close"]
# .shift(-self.freqai_info["feature_parameters"]["label_period_candles"])
# .rolling(self.freqai_info["feature_parameters"]["label_period_candles"])
# .max()
# -
# df["close"]
# .shift(-self.freqai_info["feature_parameters"]["label_period_candles"])
# .rolling(self.freqai_info["feature_parameters"]["label_period_candles"])
# .min()
# )
return df return df
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:

View File

@ -62,7 +62,7 @@ class freqai_test_multimodel_strat(IStrategy):
return informative_pairs return informative_pairs
def populate_any_indicators( def populate_any_indicators(
self, metadata, pair, df, tf, informative=None, coin="", set_generalized_indicators=False self, pair, df, tf, informative=None, set_generalized_indicators=False
): ):
""" """
Function designed to automatically generate, name and merge features Function designed to automatically generate, name and merge features
@ -79,6 +79,8 @@ class freqai_test_multimodel_strat(IStrategy):
:coin: the name of the coin which will modify the feature names. :coin: the name of the coin which will modify the feature names.
""" """
coin = pair.split('/')[0]
with self.freqai.lock: with self.freqai.lock:
if informative is None: if informative is None:
informative = self.dp.get_pair_dataframe(pair, tf) informative = self.dp.get_pair_dataframe(pair, tf)

View File

@ -62,7 +62,7 @@ class freqai_test_strat(IStrategy):
return informative_pairs return informative_pairs
def populate_any_indicators( def populate_any_indicators(
self, metadata, pair, df, tf, informative=None, coin="", set_generalized_indicators=False self, pair, df, tf, informative=None, set_generalized_indicators=False
): ):
""" """
Function designed to automatically generate, name and merge features Function designed to automatically generate, name and merge features
@ -79,6 +79,8 @@ class freqai_test_strat(IStrategy):
:coin: the name of the coin which will modify the feature names. :coin: the name of the coin which will modify the feature names.
""" """
coin = pair.split('/')[0]
with self.freqai.lock: with self.freqai.lock:
if informative is None: if informative is None:
informative = self.dp.get_pair_dataframe(pair, tf) informative = self.dp.get_pair_dataframe(pair, tf)