This Python algorithm implements a mean reversion strategy using a 20-day Weighted Moving Average to detect overbought and oversold conditions in the SPY index. It calculates the standard deviation and Z-score of price movements to identify potential buy and sell signals based on significant deviations from the weighted moving average.
Trading Logic: The algorithm buys 10 shares when a buy signal is triggered (oversold) and sells 10 shares when a sell signal is triggered (overbought).
Backtesting Range: January 1st, 2021 - January 1st, 2022
Initial Capital: $10,000
Final Capital: $10,738.70
Final Profit: $738.70 or 7.38%