Strategy Methodology
Strategy A — Technical Momentum
agent2_technical.py · Sleeve A
What it does: Scans a 500+ stock universe for technical breakout setups using 7 quantitative signals.
How it works: For each ticker, it downloads daily OHLCV data (Bloomberg primary, yfinance fallback), computes indicators, then scores each of 7 signals 0–100. The weighted composite determines conviction level.
The 7 Signals:
Risk Sizing: Stop = entry − 2×ATR (14-day). Target = entry + 3×ATR. Min R:R = 1.5:1. Position = 1% portfolio risk ÷ ATR stop distance.
Best Regime: BULL and TRANSITION markets. Performs poorly in BEAR (signals disabled by regime filter).
How it works: For each ticker, it downloads daily OHLCV data (Bloomberg primary, yfinance fallback), computes indicators, then scores each of 7 signals 0–100. The weighted composite determines conviction level.
The 7 Signals:
🔹 MACD (20%) — Histogram positive + recent cross above signal line = bullish momentum confirmed.
🔹 RSI (15%) — Score 50–70 earns full marks (momentum zone). Penalised if overbought above 75.
🔹 EMA Alignment (20%) — Price above EMA8 > EMA21 > EMA50. All three aligned = bullish structure.
🔹 Volume (15%) — Volume ≥ 1.5× average = strong confirmation. Penalised below 0.7× average.
🔹 Relative Strength (15%) — Stock outperforming SPY on a 63-day trailing basis earns full score.
🔹 Bollinger Bands (10%) — %B above 0.8 with bandwidth expanding = breakout in progress.
🔹 Chart Patterns (5%) — Golden cross (SMA50 > SMA200) + ADX > 25 confirms trend.
Risk Sizing: Stop = entry − 2×ATR (14-day). Target = entry + 3×ATR. Min R:R = 1.5:1. Position = 1% portfolio risk ÷ ATR stop distance.
Best Regime: BULL and TRANSITION markets. Performs poorly in BEAR (signals disabled by regime filter).
Strategy B — Factor Investing
agent3_factor.py · Sleeve B
What it does: Screens the universe for multi-factor exposure combining Momentum, Quality, Value, and Low-Vol factors.
How it works: Each ticker is scored 0–100 on four classic academic factors and combined into a weighted composite. Only stocks scoring ≥50 composite are emitted as signals.
The 4 Factors:
Best Regime: SIDEWAYS and low-volatility environments. Quality + Low-Vol factors protect in BEAR markets.
How it works: Each ticker is scored 0–100 on four classic academic factors and combined into a weighted composite. Only stocks scoring ≥50 composite are emitted as signals.
The 4 Factors:
🔹 Momentum (25%) — 12–1 month price return annualised. Positive return maps to 50–100 score.
🔹 Quality (25%) — Price above 200-day EMA (50pts) + realised vol below 20% (50pts).
🔹 Value (25%) — Distance from 52-week high. 30% off high = 60pts. Used as contrarian value signal.
🔹 Low-Vol (25%) — 63-day annualised volatility below 15% = 100pts, above 50% = 0pts.
Best Regime: SIDEWAYS and low-volatility environments. Quality + Low-Vol factors protect in BEAR markets.
Strategy C — Pairs Trading
agent4_pairs.py · Sleeve C
What it does: Finds pairs of historically correlated stocks that have temporarily diverged, then trades the expected reversion to the mean.
How it works:
Signal Direction: z < −2.0 → LONG spread (buy Leg A, sell Leg B). z > +2.0 → SHORT spread (sell Leg A, buy Leg B).
Best Regime: SIDEWAYS and TRANSITION markets. Market-neutral by construction (long/short simultaneously).
How it works:
1. Group all stocks by GICS sector (only pairs within same sector qualify).
2. Compute 252-day Pearson correlation on daily returns. Only pairs with r ≥ 0.70 pass.
3. Run Engle-Granger cointegration test. Only pairs with p-value < 0.10 pass.
4. Compute OLS hedge ratio (β) and 60-day rolling z-score of the spread.
5. Entry: |z| ≥ 2.0. Exit: |z| ≤ 0.5.
Signal Direction: z < −2.0 → LONG spread (buy Leg A, sell Leg B). z > +2.0 → SHORT spread (sell Leg A, buy Leg B).
Best Regime: SIDEWAYS and TRANSITION markets. Market-neutral by construction (long/short simultaneously).
Strategy D — Short Momentum
agents/strategy_d_short.py · Sleeve D
What it does: Screens for weak names breaking down below their 200-day SMA with fading relative strength — ideal short candidates.
Entry Criteria:
Regime Gate: BEAR or SIDEWAYS only (bypassed in SIM mode).
Risk Sizing:
Best Regime: BEAR and SIDEWAYS markets. Disabled in BULL (regime gate blocks signals).
Entry Criteria:
🔹 Price below 200-day SMA — Long-term trend is bearish.
🔹 RSI(14) above 50 — Not yet oversold, still has downside room.
🔹 Relative Strength bottom quartile — Weakest performers in the universe.
Regime Gate: BEAR or SIDEWAYS only (bypassed in SIM mode).
Risk Sizing:
Time stop: 6 trading days
Stop loss: 4% above entry
Target: 8% below entry (R:R = 2.0:1)
Max position: 1.5% of AUM per short
Best Regime: BEAR and SIDEWAYS markets. Disabled in BULL (regime gate blocks signals).
Glossary of Terms
ADX
Average Directional Index
Trend strength indicator (0–100). ADX > 25 = strong trend. Does not indicate direction — only strength. Used in Chart Patterns signal.
ATR
Average True Range
Measures daily price volatility as an average of the true range (high − low, adjusted for gaps) over 14 days. QAIP uses 2×ATR for stops and 3×ATR for targets.
Backtest
Historical Simulation
Running a strategy's rules against past data as if trading live. Used to estimate win rate, Sharpe ratio, and optimal signal weights. Not predictive of future results.
Bollinger Bands
Volatility Envelope
Upper and lower bands drawn 2 standard deviations above/below a 20-day SMA. %B shows where price sits within the bands (0 = lower, 1 = upper).
BULL / BEAR / SIDEWAYS
Market Regime
BULL: SPX > 200-day SMA and VIX < 20. BEAR: SPX < 200-day SMA and VIX > 25. SIDEWAYS: SPX near SMA and VIX 20–25. TRANSITION: mixed signals.
Cointegration
Statistical Relationship
Two price series are cointegrated if they share a long-run equilibrium. Even if prices drift apart, they tend to revert. Tested using the Engle-Granger ADF test (p < 0.10 required).
Composite Score
Weighted Signal Total
Sum of all 7 signal scores weighted by their assigned percentages (default: MACD 20%, RSI 15%, EMA Align 20%, Volume 15%, Rel Str 15%, BB 10%, Patterns 5%). Range: 0–100.
Conviction
Signal Strength Label
HIGH = composite ≥ 70. MEDIUM = 55–69. LOW = < 55. Conviction is a shorthand for how strongly all signals agree on a trade.
EMA
Exponential Moving Average
A moving average that gives more weight to recent prices. Responds faster than a simple SMA. QAIP uses EMA8, EMA21, EMA50, EMA200.
EMA Alignment
Trend Structure Check
Bullish when price > EMA8 > EMA21 > EMA50. Each layer confirms a stronger trend. All three aligned = maximum score (20pts).
Engle-Granger Test
Cointegration Test
Two-step statistical test: fit OLS regression on two price series, then run ADF test on residuals. If residuals are stationary (p < 0.10), the pair is cointegrated.
ERC
Equal Risk Contribution
Portfolio construction method where each position contributes an equal dollar amount of risk to the total portfolio. Prevents any single position dominating portfolio risk.
Factor Investing
Systematic Return Driver
Investing based on attributes (factors) that historically drive returns: Momentum (recent winners keep winning), Quality (stable earnings), Value (cheap stocks), Low-Vol (low-risk stocks).
Golden Cross
Bullish SMA Signal
When the 50-day SMA crosses above the 200-day SMA. Historically signals the start of a sustained uptrend. Used in Chart Patterns score.
Hedge Ratio
Pairs Trading Weight
The OLS regression coefficient (β) between two stock prices. In a pairs trade, you buy 1 share of Stock A for every β shares of Stock B to neutralise market exposure.
Kelly Criterion
Optimal Bet Sizing
Mathematical formula for optimal position sizing: f = W − (1−W)/B where W=win rate, B=win/loss ratio. QAIP uses half-Kelly (×0.5) for conservatism.
MACD
Moving Avg Convergence/Divergence
Momentum indicator: MACD line = EMA12 − EMA26. Signal line = EMA9 of MACD. Histogram = MACD − Signal. Bullish when histogram turns positive or crosses above zero.
Maximum Drawdown
Worst Peak-to-Trough Loss
Largest percentage decline from a portfolio's peak value to its subsequent trough. Hard limit in QAIP: −15% triggers a circuit breaker halting new positions.
Pairs Trading
Market-Neutral Strategy
Simultaneously long one stock and short a correlated stock. Profit comes from convergence of the spread, not market direction. Requires both cointegration (long-run) and z-score divergence (short-term entry).
Pearson Correlation
Linear Relationship Measure
Statistical measure of how closely two return series move together (−1 to +1). QAIP requires r ≥ 0.70 before testing a pair for cointegration.
Position Sizing
Capital Allocation
How much to invest in each trade. QAIP uses 1% portfolio risk rule: position = $1,000 risk ÷ stop distance in dollars. Hard cap at 5% of total equity per position.
R:R Ratio
Risk-Reward Ratio
Expected profit divided by expected loss. Target distance ÷ Stop distance. QAIP requires minimum 1.5:1. A 3×ATR target vs 2×ATR stop = 1.5:1 R:R.
Regime
Market Condition
Classification of the current macro environment: BULL, BEAR, SIDEWAYS, or TRANSITION. Determined by SPX vs 200-day SMA and VIX level. Strategy weights adapt per regime.
Relative Strength
Comparative Performance
How much a stock outperforms (or underperforms) its benchmark (SPY). Computed as 63-day stock return minus 63-day SPY return. Positive = outperforming.
RSI
Relative Strength Index
Momentum oscillator (0–100) measuring speed and magnitude of price changes over 14 days. <30 = oversold, >70 = overbought. QAIP scores best in the 50–70 range (momentum zone).
Sharpe Ratio
Risk-Adjusted Return
Return per unit of risk: (Portfolio return − risk-free rate) ÷ standard deviation. Annualised. >1.0 = good. >2.0 = excellent. Used by the weight optimizer to find optimal signal weights.
Signal
Trade Recommendation
A ticker that has passed all screening filters and scored above the minimum composite threshold. Signals are PENDING until explicitly APPROVED or REJECTED by the PM.
SMA
Simple Moving Average
The arithmetic mean of closing prices over N days. Less reactive to recent moves than EMA. QAIP uses SMA50 and SMA200 for regime detection and golden cross.
Spread
Pairs Trading Differential
The residual of the OLS regression: Spread = Price_A − β × Price_B. Mean-reverts when the pair is cointegrated. Z-score measures current deviation from the rolling mean.
Strategy Toggle
On/Off Signal Switch
Each signal (MACD, RSI, etc.) can be enabled or disabled individually. Disabled signals are excluded from the composite denominator so scores still sum to 100.
TRANSITION
Uncertain Regime
Market regime where SPX is between key technical levels — neither clearly BULL nor BEAR. All new position entries are hard-blocked across all three strategies until regime resolves. Existing positions are monitored normally. Triggered when VIX crosses 20 or SPX breaks key EMA levels without confirmation.
Universe
Stock Watchlist
The set of tickers scanned on each run. Defined in config.UNIVERSE. Typically 500+ large-cap US equities across all GICS sectors.
VIX
Volatility Index
CBOE Volatility Index: 30-day implied volatility of S&P 500 options. Known as the 'fear gauge'. >25 = elevated fear (often BEAR regime). <15 = complacency (often BULL).
Volume Surge
Breakout Confirmation
Current day's volume relative to 20-day average. Volume ≥ 1.5× average on a breakout = high conviction. Volume < 0.7× = weak, penalised in score.
Z-Score
Spread Deviation
Measures how far the current spread is from its 60-day rolling mean, in units of standard deviation. QAIP enters pairs trades when |z| ≥ 2.0 and exits when |z| ≤ 0.5.