This is a credit spread options trading algorithm that implements a mean-reversion strategy based on volatility and volume analysis. The algorithm operates on NIFTY 50 index options and generates signals for credit put spreads (when bullish) and credit call spreads (when bearish). The core strategy relies on two primary alpha signals: alpha and alpha2. The first alpha signal (alpha) is calculated using a time-series rank of the 5-minute forward price change normalized by the opening price, with a lookback period of 800 minutes. The second alpha signal (alpha2) incorporates volume confirmation and volatility scaling - it multiplies the price change by the average volume ratio of ATM put and call options, then divides by the ATM volatility (sum of CE and PE rolling volatility), and applies a 300-minute time-series rank.
The algorithm generates trading signals when both alpha values exceed 0.8 (for long positions) or fall below 0.2 (for short positions), indicating strong directional conviction. When the conditions are met, it constructs credit spreads by selling ATM options and buying OTM/ITM options at different strike distances. For bullish signals (alpha > 0.8), it creates a credit put spread by selling ATM puts and buying ITM puts 400 points below. For bearish signals (alpha < 0.2), it creates a credit call spread by selling ATM calls and buying OTM calls 400 points above. The algorithm includes risk management through stop-loss calculations based on margin requirements and operates only during specific market hours (10:15 AM to 2:15 PM) to avoid high volatility periods around market open and close.
Show more 