Options Spread Conviction Engine
by @adamnaghs
Multi-regime options spread analysis engine with Kelly Criterion Position Sizing. Scores vertical spreads (bull put, bear call, bull call, bear put) and mult...
clawhub install options-spread-conviction-engineπ About This Skill
name: options-spread-conviction-engine description: Multi-regime options spread analysis engine with quantitative rigor. Features regime detection (VIX-based), GARCH volatility forecasting, drawdown-constrained Kelly position sizing, and walk-forward backtesting. Scores vertical spreads (bull put, bear call, bull call, bear put) and multi-leg strategies (iron condors, butterflies, calendar spreads) using Ichimoku, RSI, MACD, Bollinger Bands, and IV term structure analysis. version: 2.3.0 author: Leonardo Da Pinchy metadata: openclaw: emoji: π requires: bins: ["python3"] install: - id: venv-setup kind: exec command: "cd {baseDir} && python3 scripts/setup-venv.sh" label: "Setup isolated Python environment with dependencies"
Options Spread Conviction Engine
Multi-regime options spread scoring using technical indicators and IV term structure analysis.
Install
brew install jq
npm install yahoo-finance2
sudo ln -s /opt/homebrew/bin/yahoo-finance /usr/local/bin/yf
Overview
This engine analyzes any ticker and scores seven options strategies across two categories:
Vertical Spreads (Directional)
| Strategy | Type | Philosophy | Ideal Setup | |----------|------|------------|-------------| | bull_put | Credit | Mean Reversion | Bullish trend + oversold dip | | bear_call | Credit | Mean Reversion | Bearish trend + overbought rip | | bull_call | Debit | Breakout | Strong bullish momentum | | bear_put | Debit | Breakout | Strong bearish momentum |Multi-Leg Strategies (Non-Directional / Theta)
| Strategy | Type | Philosophy | Ideal Setup | |----------|------|------------|-------------| | iron_condor | Credit | Premium Selling | IV Rank >70, RSI neutral, range-bound | | butterfly | Debit | Pinning Play | BB squeeze, RSI center, low ADX | | calendar | Debit | Theta Harvest | Inverted IV term structure (front > back) |Scoring Methodology
Vertical Spreads
Weights vary by strategy type (Credit = Mean Reversion, Debit = Breakout):
#### Credit Spreads (bull_put, bear_call) | Indicator | Weight | Purpose | |-----------|--------|---------| | Ichimoku Cloud | 25 pts | Trend structure & equilibrium | | RSI | 20 pts | Entry timing (mean-reversion) | | MACD | 15 pts | Momentum confirmation | | Bollinger Bands | 25 pts | Volatility regime | | ADX | 15 pts | Trend strength validation |
#### Debit Spreads (bull_call, bear_put) | Indicator | Weight | Purpose | |-----------|--------|---------| | Ichimoku Cloud | 20 pts | Trend confirmation | | RSI | 10 pts | Directional momentum | | MACD | 30 pts | Breakout acceleration | | Bollinger Bands | 25 pts | Bandwidth expansion | | ADX | 15 pts | Trend strength validation |
Multi-Leg Strategies
#### Iron Condor (Credit / Range-Bound) | Component | Weight | Rationale | |-----------|--------|-----------| | IV Rank (BBW %) | 25 pts | Rich premiums to sell | | RSI Neutrality | 20 pts | No directional momentum | | ADX Range-Bound | 20 pts | Weak trend = range structure | | Price Position | 20 pts | Centered in range = safe margins | | MACD Neutrality | 15 pts | No acceleration in any direction |
Triggers:
Strike Selection:
Output:
#### Butterfly (Debit / Volatility Compression) | Component | Weight | Rationale | |-----------|--------|-----------| | BB Squeeze | 30 pts | Vol compression = narrow range | | RSI Neutrality | 25 pts | Price at equilibrium | | ADX Weakness | 20 pts | No directional trend at all | | Price Centering | 15 pts | At center of range for max profit | | MACD Flatness | 10 pts | No momentum |
Triggers:
Strike Selection:
Output:
#### Calendar Spread (Debit / Theta Harvesting) | Component | Weight | Rationale | |-----------|--------|-----------| | IV Term Structure | 30 pts | Front IV > Back IV = theta edge | | Price Stability | 20 pts | Price stays near strike | | RSI Neutrality | 20 pts | Not trending away from strike | | ADX Moderate | 15 pts | Some structure, not trending hard | | MACD Neutrality | 15 pts | No directional acceleration |
Triggers:
Data Sources:
Strike Selection:
Output:
Conviction Tiers
| Score | Tier | Action | |-------|------|--------| | 80-100 | EXECUTE | High conviction β Enter the spread | | 60-79 | PREPARE | Favorable β Size the trade | | 40-59 | WATCH | Interesting β Add to watchlist | | 0-39 | WAIT | Poor conditions β Avoid / No setup |
Usage
Vertical Spreads
# Basic analysis (auto-detects best strategy)
conviction-engine AAPLSpecific strategy
conviction-engine SPY --strategy bear_call
conviction-engine QQQ --strategy bull_call --period 2y
Multi-Leg Strategies
# Iron Condor β high IV, range-bound
conviction-engine SPY --strategy iron_condorButterfly β volatility compression, pinning play
conviction-engine AAPL --strategy butterflyCalendar β inverted IV term structure, theta harvest
conviction-engine TSLA --strategy calendar
Multiple Tickers
conviction-engine AAPL MSFT GOOGL --strategy bull_put
conviction-engine SPY QQQ IWM --strategy iron_condor
JSON Output (for automation)
conviction-engine TSLA --strategy butterfly --json
conviction-engine SPY --strategy calendar --json | jq '.[0].iv_term_structure'
Full Options
conviction-engine [ticker...]
--strategy {bull_put,bear_call,bull_call,bear_put,iron_condor,butterfly,calendar}
--period {1y,2y,3y,5y}
--interval {1h,1d,1wk}
--json
Example Outputs
Iron Condor
================================================================================
SPY β Iron Condor (Credit)
================================================================================
Price: $681.27 | Score: 31.8/100 β WAIT[IV Rank +2.5/25]
IV Rank (BBW proxy): 5% (VERY_LOW)
BBW: 3.17 (1Y range: 2.37 - 18.13)
Premiums are THIN β poor risk/reward for credit
Strikes:
BUY 680.0P | SELL 685.0P
SELL 695.0C | BUY 700.0C
Max Profit Zone: $685.0 - $695.0
Wing Width: $5.00
Butterfly
================================================================================
SPY β Long Butterfly (Debit)
================================================================================
Price: $681.27 | Score: 64.5/100 β PREPARE[BB Squeeze +27.0/30]
Bandwidth: 3.1701 (percentile: 21%)
SQUEEZE ACTIVE β 19 consecutive bars
Strikes:
BUY 1x 685.0C | SELL 2x 690.0C | BUY 1x 695.0C
Max Profit Price: $690.0
Profit Zone: ~$685.0 - $695.0
Calendar Spread
================================================================================
SPY β Calendar Spread (Debit)
================================================================================
Price: $681.27 | Score: 67.2/100 β PREPARE[IV Term Structure +30.0/30]
Front IV: 27.5% | Back IV: 19.4%
Differential: +41.7%
INVERTED TERM STRUCTURE β calendar opportunity confirmed
Strikes:
Strike: $680.0
SELL 2026-02-13 | BUY 2026-03-13
Theta Advantage: Front IV > Back IV by 41.7%
IV Rank Approximation
IV Rank is approximated using Bollinger Bandwidth (BBW) percentile over 252 trading days:
IV Rank β (Current BBW - 52wk Low BBW) / (52wk High BBW - 52wk Low BBW) Γ 100
This correlation is well-documented: realized volatility (BBW) and implied volatility rank move with ~0.7-0.8 correlation (Sinclair, "Volatility Trading", 2013).
IV Term Structure
For calendar spreads, the engine attempts to fetch live ATM implied volatility from Yahoo Finance options chains. If unavailable, it falls back to historical volatility term structure (HV 10-day vs HV 30-day) as a proxy.
Quantitative Modules (v2.3.0)
The engine now includes four quantitative modules for rigorous strategy validation and optimization:
1. Regime Detector (regime_detector.py)
Market regime classification using VIX percentiles:
# Detect current regime
python3 scripts/regime_detector.pyGet regime-adjusted weights for specific strategy
python3 scripts/regime_detector.py --strategy iron_condor --json
Integration:
from regime_detector import RegimeDetectordetector = RegimeDetector()
regime, confidence = detector.detect_regime()
weights = detector.get_regime_weights(regime)
adjusted_score, reasoning = detector.regime_aware_score(75, regime, 'bull_put')
2. Volatility Forecaster (vol_forecaster.py)
GARCH-based realized volatility forecasting with VRP analysis:
# Analyze AAPL volatility
python3 scripts/vol_forecaster.py AAPLCompare IV = 25% vs forecast RV
python3 scripts/vol_forecaster.py SPY --iv 0.25 --horizon 5
Interpretation:
Integration:
from vol_forecaster import VolatilityForecasterforecaster = VolatilityForecaster("AAPL")
params = forecaster.fit_garch() # Returns omega, alpha, beta
forecast = forecaster.forecast_vol(horizon=5)
vrp, strength, rec = forecaster.vol_risk_premium(iv=0.25, rv_forecast=forecast.annualized_vol)
adjusted_score, reasoning = forecaster.add_to_conviction(70, vrp_signal, 'bull_put')
3. Enhanced Kelly Sizer (enhanced_kelly.py)
Drawdown-constrained, correlation-aware position sizing:
# Calculate position with $390 account
python3 scripts/enhanced_kelly.py --loss 80 --win 40 --pop 0.65 --conviction 85Include correlation with existing position
python3 scripts/enhanced_kelly.py --loss 80 --win 40 --pop 0.65 --conviction 85 --correlation 0.3
Integration:
from enhanced_kelly import EnhancedKellySizersizer = EnhancedKellySizer(account_value=390, max_drawdown=0.20)
result = sizer.calculate_position(
spread_cost=80,
max_loss=80,
win_amount=40,
conviction=85,
pop=0.65,
existing_correlation=0.0
)
Returns: contracts, total_risk, kelly_fraction, recommendation
4. Backtest Validator (backtest_validator.py)
Walk-forward validation of conviction scores:
# Backtest bull_put on AAPL, MSFT, SPY (2022-2024)
python3 scripts/backtest_validator.py --tickers AAPL MSFT SPY --start 2022-01-01 --end 2024-01-01 --strategy bull_putJSON output for analysis
python3 scripts/backtest_validator.py --tickers SPY --json
Output Metrics:
Integration:
from backtest_validator import BacktestValidatorvalidator = BacktestValidator(engine, "2022-01-01", "2024-01-01")
results_df = validator.run_walk_forward(["AAPL", "MSFT"], hold_days=5)
report = validator.validate_tiers(results_df)
print(f"Separation score: {report.tier_separation_score:.2f}")
print(f"EXECUTE vs WAIT p-value: {report.p_values['execute_vs_wait']:.4f}")
5. Quantitative Integration (quantitative_integration.py)
Unified interface combining all quantitative modules:
# Full quantitative analysis with regime and VRP
python3 scripts/quantitative_integration.py AAPL --regime-aware --vol-awareWith Kelly sizing
python3 scripts/quantitative_integration.py SPY --regime-aware --pop 0.65 --max-loss 80 --win-amount 40Run backtest validation
python3 scripts/quantitative_integration.py --backtest SPY QQQ --start 2022-01-01 --end 2024-01-01
Integration:
from quantitative_integration import QuantConvictionEngineengine = QuantConvictionEngine(account_value=390, max_drawdown=0.20)
Analyze with regime and VRP adjustments
result = engine.analyze("AAPL", "bull_put", regime_aware=True, vol_aware=True)
print(f"Final score: {result.final_score}")
print(f"Regime: {result.regime}")
print(f"VRP: {result.vrp_signal.vrp if result.vrp_signal else 'N/A'}")Calculate position size
sizing = engine.calculate_position(result, pop=0.65, max_loss=80, win_amount=40)
print(f"Contracts: {sizing['contracts']}")Run backtest validation
report = engine.run_backtest(["SPY", "QQQ"], "2022-01-01", "2024-01-01")
print(f"Recommendation: {report.recommendation}")
Academic Foundation
Combining orthogonal signals reduces false-positive rate compared to single-indicator strategies (Pring, 2002; Murphy, 1999).
Architecture
conviction-engine/
βββ scripts/
β βββ conviction-engine # CLI wrapper (bash)
β βββ spread_conviction_engine.py # Core engine (vertical spreads)
β βββ multi_leg_strategies.py # Multi-leg extensions
β βββ quantitative_integration.py # Unified quantitative interface
β βββ regime_detector.py # VIX-based regime classification
β βββ vol_forecaster.py # GARCH volatility forecasting
β βββ enhanced_kelly.py # Drawdown-constrained Kelly sizing
β βββ backtest_validator.py # Walk-forward validation
β βββ quant_scanner.py # Quantitative options scanner
β βββ market_scanner.py # Technical market scanner
β βββ calculator.py # Black-Scholes & POP calculator
β βββ position_sizer.py # Kelly position sizing
β βββ chain_analyzer.py # IV surface analyzer
β βββ options_math.py # Core mathematical models
β βββ setup-venv.sh # Environment setup
βββ tests/ # Unit tests
β βββ test_regime_detector.py
β βββ test_vol_forecaster.py
β βββ test_enhanced_kelly.py
β βββ test_backtest_validator.py
β βββ run_tests.py
βββ SKILL.md # This documentation
Module Separation
This separation keeps concerns clean while avoiding duplication.
Limitations & Assumptions
IV Data
Strike Selection
Data Quality
Market Assumptions
Requirements
Installation
clawhub install options-spread-conviction-engine
The skill automatically creates a virtual environment and installs:
Note: On Python 3.14+, the engine runs in pure Python mode without numba. Performance is slightly reduced but all functionality works correctly.
Market Scanners
The engine includes two distinct scanning tools for different trading philosophies:
1. Technical Scanner (market_scanner.py)
Automates the search for high-conviction plays across entire stock universes using technical indicators (Ichimoku, RSI, MACD, BB).#### Features
#### Usage
# Scan S&P 500 for high-conviction technical setups
python3 scripts/market_scanner.py --universe sp500
2. Quantitative Scanner (quant_scanner.py)
A mathematically-rigorous scanner that ignores technical indicators in favor of market microstructure and probability.#### Features
#### Usage
# Maximize POP (Probability of Profit) for SPY
python3 scripts/quant_scanner.py SPY --mode popHigh-expectancy (EV) plays with specific DTE
python3 scripts/quant_scanner.py AAPL TSLA --mode ev --min-dte 30
Calculator & Position Sizer
The integrated toolchain includes:
calculator.py
Black-Scholes options pricing with support for:position_sizer.py
Kelly criterion position sizing adapted for small accounts:from position_sizer import calculate_positionresult = calculate_position(
account_value=390,
max_loss_per_spread=80,
win_amount=40,
pop=0.65,
)
Returns: contracts, total_risk, recommendation, reason
Files
scripts/conviction-engine β Main CLI wrapper for conviction enginescripts/spread_conviction_engine.py β Core engine (vertical spreads)scripts/multi_leg_strategies.py β Multi-leg extensions (v2.0.0)scripts/market_scanner.py β Automated market scanner for EXECUTE playsscripts/calculator.py β Black-Scholes pricing, Greeks, Monte Carlo POPscripts/position_sizer.py β Kelly criterion position sizingscripts/setup-venv.sh β Environment setupdata/sp500_tickers.txt β S&P 500 constituentsdata/ndx100_tickers.txt β Nasdaq 100 constituentsassets/ β Documentation and examplesVersion History
License
MIT β Part of the Financial Toolkit for OpenClaw
π‘ Examples
Vertical Spreads
# Basic analysis (auto-detects best strategy)
conviction-engine AAPLSpecific strategy
conviction-engine SPY --strategy bear_call
conviction-engine QQQ --strategy bull_call --period 2y
Multi-Leg Strategies
# Iron Condor β high IV, range-bound
conviction-engine SPY --strategy iron_condorButterfly β volatility compression, pinning play
conviction-engine AAPL --strategy butterflyCalendar β inverted IV term structure, theta harvest
conviction-engine TSLA --strategy calendar
Multiple Tickers
conviction-engine AAPL MSFT GOOGL --strategy bull_put
conviction-engine SPY QQQ IWM --strategy iron_condor
JSON Output (for automation)
conviction-engine TSLA --strategy butterfly --json
conviction-engine SPY --strategy calendar --json | jq '.[0].iv_term_structure'
Full Options
conviction-engine [ticker...]
--strategy {bull_put,bear_call,bull_call,bear_put,iron_condor,butterfly,calendar}
--period {1y,2y,3y,5y}
--interval {1h,1d,1wk}
--json