The SagesGym4 strategy is designed to backtest trading strategies by using technical indicators. Here's a breakdown of what the strategy does:
populate_indicators: This function calculates various technical indicators for the given DataFrame, such as RSI (Relative Strength Index), AO (Awesome Oscillator), MACD (Moving Average Convergence Divergence), Aroon, and current price. The indicators are calculated and added as columns to the DataFrame.
populate_buy_trend: Based on the calculated indicators, this function determines the buy signal for the DataFrame.
It uses a model (not shown in the provided code) to predict the action, and if the predicted action is a buy (1), it sets the 'buy' column in the DataFrame to 1 for that particular row.
populate_sell_trend: Similar to the 'populate_buy_trend' function, this function determines the sell signal for the DataFrame. It uses the same model to predict the action, and if the predicted action is a sell (2), it sets the 'sell' column in the DataFrame to 1 for that particular row. action_output: This section initializes a DataFrame to store the action outputs. It prepares the indicators and loops through the DataFrame to predict actions based on the prepared observation window. The predicted actions are stored in the 'action_output' DataFrame. calculate_percent_of_balance: This function calculates the percentage of the available balance to be used for trading. It retrieves the analyzed DataFrame for the given trading pair and timeframe, gets the last candle's information, and retrieves the corresponding percentage of balance from the 'percent_of_balance_dict'. If the percentage of balance is greater than 0, it returns a fraction of the available stake amount. zscore: This function calculates the z-score normalization of the given data. It calculates the rolling mean and standard deviation, and then computes the z-score for each data point based on the mean and standard deviation. Overall, the strategy first populates the indicators, determines the buy and sell signals based on the indicators, predicts the actions using a model, calculates the percentage of balance to be used, and performs z-score normalization on the data.