diff --git a/docs/freqai-reinforcement-learning.md b/docs/freqai-reinforcement-learning.md index 8b775e046..7179da626 100644 --- a/docs/freqai-reinforcement-learning.md +++ b/docs/freqai-reinforcement-learning.md @@ -38,8 +38,6 @@ where `ReinforcementLearner` will use the templated `ReinforcementLearner` from self, pair, df, tf, informative=None, set_generalized_indicators=False ): - coin = pair.split('/')[0] - if informative is None: informative = self.dp.get_pair_dataframe(pair, tf) @@ -47,15 +45,15 @@ where `ReinforcementLearner` will use the templated `ReinforcementLearner` from for t in self.freqai_info["feature_parameters"]["indicator_periods_candles"]: t = int(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}adx-period_{t}"] = ta.ADX(informative, window=t) + informative[f"%-{pair}rsi-period_{t}"] = ta.RSI(informative, timeperiod=t) + informative[f"%-{pair}mfi-period_{t}"] = ta.MFI(informative, timeperiod=t) + informative[f"%-{pair}adx-period_{t}"] = ta.ADX(informative, window=t) # The following features are necessary for RL models - informative[f"%-{coin}raw_close"] = informative["close"] - informative[f"%-{coin}raw_open"] = informative["open"] - informative[f"%-{coin}raw_high"] = informative["high"] - informative[f"%-{coin}raw_low"] = informative["low"] + informative[f"%-{pair}raw_close"] = informative["close"] + informative[f"%-{pair}raw_open"] = informative["open"] + informative[f"%-{pair}raw_high"] = informative["high"] + informative[f"%-{pair}raw_low"] = informative["low"] indicators = [col for col in informative if col.startswith("%")] # This loop duplicates and shifts all indicators to add a sense of recency to data @@ -88,10 +86,10 @@ Most of the function remains the same as for typical Regressors, however, the fu ```python # The following features are necessary for RL models - informative[f"%-{coin}raw_close"] = informative["close"] - informative[f"%-{coin}raw_open"] = informative["open"] - informative[f"%-{coin}raw_high"] = informative["high"] - informative[f"%-{coin}raw_low"] = informative["low"] + informative[f"%-{pair}raw_close"] = informative["close"] + informative[f"%-{pair}raw_open"] = informative["open"] + informative[f"%-{pair}raw_high"] = informative["high"] + informative[f"%-{pair}raw_low"] = informative["low"] ``` Finally, there is no explicit "label" to make - instead the you need to assign the `&-action` column which will contain the agent's actions when accessed in `populate_entry/exit_trends()`. In the present example, the user set the neutral action to 0. This value should align with the environment used. FreqAI provides two environments, both use 0 as the neutral action. diff --git a/freqtrade/freqai/RL/BaseReinforcementLearningModel.py b/freqtrade/freqai/RL/BaseReinforcementLearningModel.py index f3da91b51..323cfd782 100644 --- a/freqtrade/freqai/RL/BaseReinforcementLearningModel.py +++ b/freqtrade/freqai/RL/BaseReinforcementLearningModel.py @@ -253,18 +253,26 @@ class BaseReinforcementLearningModel(IFreqaiModel): Builds the train prices and test prices for the environment. """ - coin = pair.split('/')[0] + pair = pair.replace(':', '') train_df = data_dictionary["train_features"] test_df = data_dictionary["test_features"] # price data for model training and evaluation tf = self.config['timeframe'] - ohlc_list = [f'%-{coin}raw_open_{tf}', f'%-{coin}raw_low_{tf}', - f'%-{coin}raw_high_{tf}', f'%-{coin}raw_close_{tf}'] - rename_dict = {f'%-{coin}raw_open_{tf}': 'open', f'%-{coin}raw_low_{tf}': 'low', - f'%-{coin}raw_high_{tf}': ' high', f'%-{coin}raw_close_{tf}': 'close'} + ohlc_list = [f'%-{pair}raw_open_{tf}', f'%-{pair}raw_low_{tf}', + f'%-{pair}raw_high_{tf}', f'%-{pair}raw_close_{tf}'] + rename_dict = {f'%-{pair}raw_open_{tf}': 'open', f'%-{pair}raw_low_{tf}': 'low', + f'%-{pair}raw_high_{tf}': ' high', f'%-{pair}raw_close_{tf}': 'close'} prices_train = train_df.filter(ohlc_list, axis=1) + if prices_train.empty: + raise OperationalException('Reinforcement learning module didnt find the raw prices ' + 'assigned in populate_any_indicators. Please assign them ' + 'with:\n' + 'informative[f"%-{pair}raw_close"] = informative["close"]\n' + 'informative[f"%-{pair}raw_open"] = informative["open"]\n' + 'informative[f"%-{pair}raw_high"] = informative["high"]\n' + 'informative[f"%-{pair}raw_low"] = informative["low"]\n') prices_train.rename(columns=rename_dict, inplace=True) prices_train.reset_index(drop=True)