The GymStrategy class is a backtesting strategy that calculates various technical indicators using the TA-Lib and qtpylib libraries. These indicators are used to make buy and sell decisions in the backtesting process. The populate_indicators method is responsible for calculating the following indicators:
ADX (Average Directional Index)
PLUS_DM (Plus Directional Movement)
PLUS_DI (Plus Directional Indicator)
MINUS_DM (Minus Directional Movement)
MINUS_DI (Minus Directional Indicator)
AROON (Aroon Up and Aroon Down)
AROONOSC (Aroon Oscillator)
AO (Awesome Oscillator)
UO (Ultimate Oscillator)
CCI (Commodity Channel Index)
RSI (Relative Strength Index)
Fisher RSI (Fisher Transform on RSI)
STOCH (Stochastic Oscillator)
STOCHF (Fast Stochastic)
STOCHRSI (Stochastic RSI)
MACD (Moving Average Convergence Divergence)
MFI (Money Flow Index)
ROC (Rate of Change)
Bollinger Bands (BB_LOWERBAND, BB_MIDDLEBAND, BB_UPPERBAND, BB_PERCENT, BB_WIDTH)
TEMA (Triple Exponential Moving Average)
The populate_buy_trend method uses a reinforcement learning (RL) model to predict buy actions based on the indicator values.
It sets the 'buy' column to 1 for the predicted buy actions and 0 for other cases.
The populate_sell_trend method uses the same RL model to predict sell actions based on the indicator values.
It sets the 'sell' column to 1 for the predicted sell actions and 0 for other cases. The data array is created by selecting relevant indicator columns from the dataframe and reshaping them into a suitable format for prediction. Any rows containing NaN values are replaced with zeros. Finally, the strategy returns the predicted actions (buy/sell) and a nan_list indicating rows with NaN values for further processing.