The "Theta-Harvest Credit Spread Expiry" algorithm is designed to capitalize on short-term directional movements in the NIFTY 50 index by trading credit spreads, specifically targeting the capture of theta decay as options approach their expiry. It utilizes a combination of technical indicators derived from historical and real-time options chain data to identify potential trading opportunities. The core strategy involves selling a credit spread—simultaneously selling a near-the-money option (either call or put) and buying a further out-of-the-money option of the same type and expiry. This creates a range within which the strategy aims to profit if the index price remains, with the expectation that the premium received from selling the option will decay faster than the cost of the purchased option. The algorithm specifically considers the time until expiry to maximize the theta harvest.
The algorithm generates trading signals based on a composite "alpha" factor, calculated from net aggressive option flow, changes in open interest, regime directional energy, and coupling amplification, all normalized using a time-series rank. Long (credit put spread) signals are triggered when "alpha" and a related "alpha3" factor are both high, indicating potential downward price movement. Short (credit call spread) signals are generated when both alpha factors are low, signaling possible upward movement. The algorithm incorporates risk management via a stop-loss percentage based on the margin required for the trade and a profit target which considers the premium received. It also includes checks to avoid trading on the day of expiry and during periods outside of a tested time window (10:15 AM to 2:15 PM). The trade execution logic sends signals to a trading platform, calculates margin requirements, and determines appropriate stop-loss and target levels.