The SMA (Simple Moving Average) strategy is a backtesting trading strategy that uses the Markov regime-switching model to generate buy and sell signals based on the probabilities of different market regimes. Here's how the strategy works:
The strategy uses the 5-minute timeframe for analysis. The populate_indicators function calculates the returns of the closing prices and the volume gaps between consecutive candles.
It preprocesses the data by removing any rows with NaN, infinite, or negative infinite values.
The endogenous variable (dependent variable) is set as the returns, and the exogenous variable (independent variable) is set as the volume gaps.
The Markov regime-switching model with 2 regimes and 2nd order is fitted to the data. This model allows the probabilities of being in different market regimes (up or down) to change over time. The smoothed marginal probabilities of being in the up regime are calculated and stored in the "prob" column of the dataframe. The populate_buy_trend function generates buy signals when the probability of being in the up regime is below 0.45. The populate_sell_trend function generates sell signals when the probability of being in the up regime is above 0.45. By using these buy and sell signals, the backtesting website can evaluate the performance of this SMA strategy on historical data.