The SagesGym2 strategy is designed to backtest trading strategies by populating indicators, generating buy signals, and generating sell signals based on technical analysis (TA) indicators. Here's a breakdown of what each method does:
populate_indicators: This method calculates TA indicators for a given DataFrame of raw data. It adds indicators such as RSI (Relative Strength Index) to the DataFrame.
populate_buy_trend: Based on the calculated TA indicators, this method populates the buy signal column in the DataFrame.
It uses an RL (Reinforcement Learning) model to predict the action to take, and sets the 'buy' column accordingly.
populate_sell_trend: Similar to the populate_buy_trend method, this method populates the sell signal column in the DataFrame based on TA indicators and the RL model's predictions. action_output: This variable is initialized as an empty DataFrame that will store the trading actions (buy/sell signals) generated by the strategy. The indicators DataFrame is created as a copy of the original DataFrame, and unnecessary columns are dropped based on the COLUMNS_FILTER list. It is then converted to a numpy array. A loop iterates over a window of data in the DataFrame. Within each window, an observation is created from the indicators. The observation is passed to a prediction function, which returns an action and a percentage of the balance to use for that action. If the action is a buy (1), the percentage of balance is stored in a dictionary. The action is recorded in the action_output DataFrame. Finally, there is a function named get_stake_amount that calculates the stake amount based on the current candle's data, including the percent of balance stored in the dictionary. Overall, this strategy uses TA indicators, an RL model, and historical data to generate buy and sell signals for backtesting trading strategies.