match config and strats to upstream freqai

This commit is contained in:
robcaulk 2022-08-15 18:27:48 +02:00
parent e5df39e891
commit 69d542d3e2
3 changed files with 73 additions and 76 deletions

View File

@ -55,6 +55,7 @@
} }
], ],
"freqai": { "freqai": {
"enabled": true,
"model_save_type": "stable_baselines_ppo", "model_save_type": "stable_baselines_ppo",
"conv_width": 10, "conv_width": 10,
"follow_mode": false, "follow_mode": false,

View File

@ -62,57 +62,55 @@ class ReinforcementLearningExample3ac(IStrategy):
coin = pair.split('/')[0] coin = pair.split('/')[0]
with self.freqai.lock:
if informative is None:
informative = self.dp.get_pair_dataframe(pair, tf)
# first loop is automatically duplicating indicators for time periods if informative is None:
for t in self.freqai_info["feature_parameters"]["indicator_periods_candles"]: informative = self.dp.get_pair_dataframe(pair, tf)
t = int(t) # first loop is automatically duplicating indicators for time periods
informative[f"%-{coin}rsi-period_{t}"] = ta.RSI(informative, timeperiod=t) for t in self.freqai_info["feature_parameters"]["indicator_periods_candles"]:
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}pct-change"] = informative["close"].pct_change() t = int(t)
informative[f"%-{coin}raw_volume"] = informative["volume"] 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}adx-period_{t}"] = ta.ADX(informative, window=t)
# Raw price currently necessary for RL models: informative[f"%-{coin}pct-change"] = informative["close"].pct_change()
informative[f"%-{coin}raw_price"] = informative["close"] informative[f"%-{coin}raw_volume"] = informative["volume"]
indicators = [col for col in informative if col.startswith("%")] # Raw price currently necessary for RL models:
# This loop duplicates and shifts all indicators to add a sense of recency to data informative[f"%-{coin}raw_price"] = informative["close"]
for n in range(self.freqai_info["feature_parameters"]["include_shifted_candles"] + 1):
if n == 0:
continue
informative_shift = informative[indicators].shift(n)
informative_shift = informative_shift.add_suffix("_shift-" + str(n))
informative = pd.concat((informative, informative_shift), axis=1)
df = merge_informative_pair(df, informative, self.config["timeframe"], tf, ffill=True) indicators = [col for col in informative if col.startswith("%")]
skip_columns = [ # This loop duplicates and shifts all indicators to add a sense of recency to data
(s + "_" + tf) for s in ["date", "open", "high", "low", "close", "volume"] for n in range(self.freqai_info["feature_parameters"]["include_shifted_candles"] + 1):
] if n == 0:
df = df.drop(columns=skip_columns) continue
informative_shift = informative[indicators].shift(n)
informative_shift = informative_shift.add_suffix("_shift-" + str(n))
informative = pd.concat((informative, informative_shift), axis=1)
# Add generalized indicators here (because in live, it will call this df = merge_informative_pair(df, informative, self.config["timeframe"], tf, ffill=True)
# function to populate indicators during training). Notice how we ensure not to skip_columns = [
# add them multiple times (s + "_" + tf) for s in ["date", "open", "high", "low", "close", "volume"]
if set_generalized_indicators: ]
df["%-day_of_week"] = (df["date"].dt.dayofweek + 1) / 7 df = df.drop(columns=skip_columns)
df["%-hour_of_day"] = (df["date"].dt.hour + 1) / 25
# user adds targets here by prepending them with &- (see convention below) # Add generalized indicators here (because in live, it will call this
# If user wishes to use multiple targets, a multioutput prediction model # function to populate indicators during training). Notice how we ensure not to
# needs to be used such as templates/CatboostPredictionMultiModel.py # add them multiple times
df["&-action"] = 2 if set_generalized_indicators:
df["%-day_of_week"] = (df["date"].dt.dayofweek + 1) / 7
df["%-hour_of_day"] = (df["date"].dt.hour + 1) / 25
# 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["&-action"] = 2
return df return df
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
self.freqai_info = self.config["freqai"]
dataframe = self.freqai.start(dataframe, metadata, self) dataframe = self.freqai.start(dataframe, metadata, self)
return dataframe return dataframe

View File

@ -62,57 +62,55 @@ class ReinforcementLearningExample5ac(IStrategy):
coin = pair.split('/')[0] coin = pair.split('/')[0]
with self.freqai.lock:
if informative is None:
informative = self.dp.get_pair_dataframe(pair, tf)
# first loop is automatically duplicating indicators for time periods if informative is None:
for t in self.freqai_info["feature_parameters"]["indicator_periods_candles"]: informative = self.dp.get_pair_dataframe(pair, tf)
t = int(t) # first loop is automatically duplicating indicators for time periods
informative[f"%-{coin}rsi-period_{t}"] = ta.RSI(informative, timeperiod=t) for t in self.freqai_info["feature_parameters"]["indicator_periods_candles"]:
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}pct-change"] = informative["close"].pct_change() t = int(t)
informative[f"%-{coin}raw_volume"] = informative["volume"] 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}adx-period_{t}"] = ta.ADX(informative, window=t)
# Raw price currently necessary for RL models: informative[f"%-{coin}pct-change"] = informative["close"].pct_change()
informative[f"%-{coin}raw_price"] = informative["close"] informative[f"%-{coin}raw_volume"] = informative["volume"]
indicators = [col for col in informative if col.startswith("%")] # Raw price currently necessary for RL models:
# This loop duplicates and shifts all indicators to add a sense of recency to data informative[f"%-{coin}raw_price"] = informative["close"]
for n in range(self.freqai_info["feature_parameters"]["include_shifted_candles"] + 1):
if n == 0:
continue
informative_shift = informative[indicators].shift(n)
informative_shift = informative_shift.add_suffix("_shift-" + str(n))
informative = pd.concat((informative, informative_shift), axis=1)
df = merge_informative_pair(df, informative, self.config["timeframe"], tf, ffill=True) indicators = [col for col in informative if col.startswith("%")]
skip_columns = [ # This loop duplicates and shifts all indicators to add a sense of recency to data
(s + "_" + tf) for s in ["date", "open", "high", "low", "close", "volume"] for n in range(self.freqai_info["feature_parameters"]["include_shifted_candles"] + 1):
] if n == 0:
df = df.drop(columns=skip_columns) continue
informative_shift = informative[indicators].shift(n)
informative_shift = informative_shift.add_suffix("_shift-" + str(n))
informative = pd.concat((informative, informative_shift), axis=1)
# Add generalized indicators here (because in live, it will call this df = merge_informative_pair(df, informative, self.config["timeframe"], tf, ffill=True)
# function to populate indicators during training). Notice how we ensure not to skip_columns = [
# add them multiple times (s + "_" + tf) for s in ["date", "open", "high", "low", "close", "volume"]
if set_generalized_indicators: ]
df["%-day_of_week"] = (df["date"].dt.dayofweek + 1) / 7 df = df.drop(columns=skip_columns)
df["%-hour_of_day"] = (df["date"].dt.hour + 1) / 25
# user adds targets here by prepending them with &- (see convention below) # Add generalized indicators here (because in live, it will call this
# If user wishes to use multiple targets, a multioutput prediction model # function to populate indicators during training). Notice how we ensure not to
# needs to be used such as templates/CatboostPredictionMultiModel.py # add them multiple times
df["&-action"] = 2 if set_generalized_indicators:
df["%-day_of_week"] = (df["date"].dt.dayofweek + 1) / 7
df["%-hour_of_day"] = (df["date"].dt.hour + 1) / 25
# 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["&-action"] = 2
return df return df
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
self.freqai_info = self.config["freqai"]
dataframe = self.freqai.start(dataframe, metadata, self) dataframe = self.freqai.start(dataframe, metadata, self)
return dataframe return dataframe