Expand model tag support: add GLM-5.1, simplify Anthropic IDs, scan tags anywhere in message

- Flink update_bars debouncing
- update_bars subscription idempotency bugfix
- Price decimal correction bugfix of previous commit
- Add GLM-5.1 model tag alongside renamed GLM-5
- Use short Anthropic model IDs (sonnet/haiku/opus) instead of full version strings
- Allow @tags anywhere in message content, not just at start
- Return hasOtherContent flag instead of trimmed rest string
- Only trigger greeting stream when tag has no other content
- Update workspace knowledge base references to platform/workspace and platform/shapes
- Hierarchical knowledge base catalog
- 151 Trading Strategies knowledge base articles
- Shapes knowledge base article
- MutateShapes tool instead of workspace patch
This commit is contained in:
2026-04-28 15:05:15 -04:00
parent d41fcd0499
commit 47471b7700
184 changed files with 9044 additions and 170 deletions

View File

@@ -0,0 +1,48 @@
---
description: "Background on volatility as an asset class: historical vs. implied volatility, VIX as the market's fear gauge, and the spectrum of instruments (options, futures, ETNs) used for volatility trading."
tags: [volatility, background, vix, implied-volatility, options]
---
# Volatility Generalities
**Section**: 7.1 | **Asset Class**: Volatility | **Type**: Background / Reference
## Overview
Volatility can be viewed as an asset class in its own right. Volatility strategies make bets on whether future realized volatility will be higher or lower, or on the relationship between implied and realized volatility. Volatility is measured historically (from past returns) or implied (extracted from option prices, forward-looking). VIX is the dominant index-level volatility measure and its derivatives provide direct trading vehicles.
## Construction / Mechanics
### Historical (Realized) Volatility
Based on a time series of past returns. For daily log-returns R(t) = ln[S(t)/S(t-1)] over a window of T days:
```
σ_realized = sqrt(F/T · Σ_{t=1}^T R(t)²)
```
where F = 252 (annualization factor for daily data). Note: mean is not subtracted (consistent with variance swap conventions).
### Implied Volatility
Extracted from option prices via the Black-Scholes formula or model-free methods. Implied volatility is forward-looking: it represents the market's expectation of future volatility over the option's lifetime.
### VIX
The CBOE Volatility Index (VIX), the "fear gauge" or "uncertainty index," measures the market's expectation of 30-day volatility of the S&P 500 as implied by a range of S&P 500 options. Related indexes include:
- **RVX**: CBOE Russell 2000 Volatility Index
- **VXEEM**: CBOE Emerging Markets ETF Volatility Index
- **TYVIX**: CBOE/CBOT 10-year U.S. Treasury Note Volatility Index
- **GVZ**: CBOE Gold ETF Volatility Index
- **EUVIX**: CBOE/CME FX Euro Volatility Index
### Volatility Trading Instruments
- **Options**: direct vol exposure, but require Delta-hedging to isolate volatility (see Section 7.4.1)
- **VIX futures (UX1, UX2, ...)**: UX1 ≈ 1 month to maturity; allow direct trading of forward implied vol
- **Volatility ETNs**: VXX tracks short-maturity VIX futures (months 1-2); VXZ tracks medium-maturity (months 4-7); subject to roll/contango losses
- **Variance swaps**: payoff proportional to realized variance minus strike; no Delta-hedging required (see Section 7.6)
## Key Concepts
- **Volatility risk premium**: implied vol > realized vol most of the time; selling volatility is structurally profitable on average but with crash risk
- **Contango**: VIX futures curve upward-sloping (most common); VXX loses value via roll loss
- **Backwardation**: VIX futures curve downward-sloping (during stress); VXX gains from roll
- **VIX and equities are anti-correlated**: VIX typically spikes during equity market selloffs
## Notes
- Options-based volatility strategies (straddles, etc.) are covered in Section 2 of the book; this chapter focuses on VIX derivatives and variance swaps.
- Long volatility positions profit in crises (natural hedge) but are expensive to maintain due to roll/theta decay.
- Short volatility positions earn the volatility risk premium in normal markets but suffer catastrophic losses during sudden vol spikes.

View File

@@ -0,0 +1,68 @@
---
description: "Variance swaps are derivative contracts whose payoff is proportional to the difference between realized variance and a preset variance strike, allowing pure volatility bets without the need for continuous Delta-hedging."
tags: [volatility, variance-swap, realized-variance, delta-neutral, derivatives]
---
# Volatility Trading with Variance Swaps
**Section**: 7.6 | **Asset Class**: Volatility | **Type**: Volatility / Derivatives
## Overview
Variance swaps allow traders to bet on future realized variance without the operational burden of continuous Delta-hedging required by options-based volatility strategies. The payoff at maturity is proportional to the difference between the realized variance of the underlying and a preset variance strike K, scaled by a variance notional N.
## Construction / Mechanics
**Payoff at maturity T** (for the long side):
```
P(T) = N × (v(T) - K) (434)
```
**Realized variance** over the period:
```
v(T) = (F/T) Σ_{t=1}^T R(t)² (435)
```
**Log-return** at time t:
```
R(t) = ln[S(t) / S(t-1)] (436)
```
where:
- t = 0, 1, ..., T: sample points (e.g., trading days)
- S(t): underlying price at time t
- F: annualization factor (F = 252 for daily data)
- N: variance notional (preset, in dollar terms)
- K: variance strike (preset at contract inception; determines the fair value entry price)
- Note: the mean return is NOT subtracted in v(T), so the denominator is T (not T-1)
**Long variance swap**: benefits when realized variance v(T) > K (realized vol was higher than expected).
**Short variance swap**: benefits when realized variance v(T) < K (realized vol was lower than expected).
**Fair value of K**: at inception, K is set such that the swap has zero initial value; it equals the market's expected future variance (often proxied by the square of the VIX for equity index variance swaps).
## Payoff / Return Profile
- **Long variance swap** profits when realized variance exceeds the variance strike K: v(T) > K.
- Typical use: hedge against a volatility spike; gains are convex in the volatility move (since variance is the square of vol).
- **Short variance swap** profits when realized variance is below K: v(T) < K.
- Typical use: harvest the volatility risk premium (implied vol > realized vol on average); earns N × (K - v(T)) in normal markets.
- The payoff is in units of variance (not volatility); a move from 10% to 20% vol generates 4× the payoff of a move from 10% to 15% vol.
## Key Parameters / Signals
- K: variance strike (the break-even point)
- N: variance notional (dollar value per unit of variance)
- v(T): realized variance (the key realized outcome)
- F: annualization factor (252 for daily, 52 for weekly, etc.)
- T: number of observation periods
- v(T) - K: the net P&L per unit of notional
## Variations
- **Volatility swap**: payoff based on sqrt(v(T)) - K_vol (realized volatility minus vol strike); less convex than variance swap; harder to replicate.
- **Conditional variance swap**: accumulates variance only on days when the underlying is within a specified range.
- **Corridor variance swap**: similar, accumulates variance only when the underlying is above (or below) a barrier.
## Notes
- The key advantage over options-based volatility strategies: no Delta-hedging required, so the trader takes pure variance exposure with no directional risk (assuming no P&L drift from Delta).
- The convexity of the variance payoff (variance = vol²) means long variance swaps gain more from large vol spikes than short options positions gain from vol increases.
- Short variance swaps capture the volatility risk premium (K > expected realized variance) but have unlimited downside: if realized variance is very high (e.g., a market crash), N × (v(T) - K) can be very large.
- Variance swaps on equity indexes are liquid OTC instruments; single-stock variance swaps are less common.
- The mean is not subtracted in v(T) (Eq. 435), which is standard market convention; subtracting the mean would change the denominator to T-1.

View File

@@ -0,0 +1,64 @@
---
description: "VIX futures basis trading is a mean-reversion strategy that shorts VIX futures when the basis is positive (contango) and buys when the basis is negative (backwardation), based on the empirical finding that the basis predicts subsequent VIX futures price changes."
tags: [volatility, vix, futures, basis, mean-reversion]
---
# VIX Futures Basis Trading
**Section**: 7.2 | **Asset Class**: Volatility | **Type**: Mean-Reversion
## Overview
The VIX futures basis is the difference between the first-month VIX futures price and the VIX spot price. Empirically, the basis has no forecasting power for subsequent VIX changes, but does forecast VIX futures price changes (mean-reversion). When the curve is in contango (positive basis), futures prices tend to fall; when in backwardation (negative basis), futures prices tend to rise. The strategy trades this mean-reversion.
## Construction / Mechanics
**VIX futures basis**:
```
B_VIX = P_UX1 - P_VIX (429)
```
**Daily roll value** (normalized by days to settlement T):
```
D = B_VIX / T (430)
```
where:
- P_UX1: price of the first-month (UX1) VIX futures contract
- P_VIX: VIX spot price
- T: number of business days until settlement (assumed ≥ 10)
- D: daily roll value (basis per business day remaining)
**Trading rule** (based on D):
```
Rule = { Open long UX1 position if D < -0.10
{ Close long UX1 position if D > -0.05
{ Open short UX1 position if D > 0.10
{ Close short UX1 position if D < 0.05 (431)
```
- **Short UX1**: when the curve is in contango (D > 0.10); futures price tends to converge down toward VIX.
- **Long UX1**: when the curve is in backwardation (D < -0.10); futures price tends to converge up toward VIX.
**Optional hedge**: short UX1 position can be hedged by shorting mini-S&P 500 futures (since VIX and equity markets are anti-correlated; a VIX spike usually accompanies an equity selloff).
## Payoff / Return Profile
- Profits when VIX futures prices revert toward the VIX spot (as they do at settlement).
- In contango: short position earns the roll-down as futures price falls toward VIX.
- In backwardation: long position earns the roll-up as futures price rises toward VIX.
- Loses when VIX spikes suddenly (short position) or crashes (long position) before mean-reversion occurs.
## Key Parameters / Signals
- D = B_VIX / T: the daily roll value primary signal
- Entry thresholds: |D| > 0.10 to open; |D| < 0.05 to close
- T: days to settlement (must be 10 for the strategy to be viable)
- Hedge ratio: estimated from serial regression of VIX futures price changes on mini-S&P 500 futures returns
## Variations
- Use a basket of VIX futures (UX1, UX2, etc.) rather than just UX1 for more stable exposure.
- Combine with VIX ETN strategies (VXX/VXZ carry, Section 7.3).
## Notes
- A short UX1 position is exposed to the risk of a sudden VIX spike (equity market selloff), which typically requires the mini-S&P hedge.
- The hedge ratio for the mini-S&P position should be estimated from historical regression of VIX futures price changes on S&P 500 futures returns.
- The empirical basis for this strategy rests on the mean-reverting property of the VIX futures basis, documented in Mixon (2007), Nossman & Wilhelmsson (2009), Simon & Campasano (2014).
- Settlement date proximity (small T) makes D volatile and the signal unreliable; hence the T 10 minimum requirement.

View File

@@ -0,0 +1,68 @@
---
description: "Volatility carry with two ETNs shorts VXX (short-maturity VIX futures ETN) and buys VXZ (medium-maturity VIX futures ETN) to harvest the contango roll loss differential, with the hedge ratio determined by serial regression."
tags: [volatility, carry, vxx, vxz, etn, contango, roll]
---
# Volatility Carry with Two ETNs
**Section**: 7.3 | **Asset Class**: Volatility | **Type**: Carry
## Overview
VXX and VXZ are exchange-traded notes (ETNs) tracking VIX futures. VXX tracks short-maturity (months 1-2) futures and suffers greater roll/contango losses than VXZ (months 4-7), because the VIX futures curve is steepest at the short end in contango. The strategy shorts VXX (captures the larger roll loss as profit) and buys VXZ as a hedge (offsets some exposure to VIX spikes), earning the contango roll differential.
## Construction / Mechanics
**VXX**: tracks a constant-maturity position in months 1-2 VIX futures. Each day, a fraction of the front-month futures is sold and replaced with the next-month futures. In contango, the next-month is more expensive → daily roll loss → VXX decays over time.
**VXZ**: tracks months 4-7 VIX futures. Same roll mechanism but in a less steep part of the contango curve → lower roll loss than VXX.
**Basic strategy**: short VXX, long VXZ.
**Hedge ratio** h (number of VXZ units per VXX shorted):
```
h = β = ρ · σ_X / σ_Z
```
where:
- ρ: historical pairwise correlation between VXX and VXZ returns
- σ_X: historical volatility of VXX
- σ_Z: historical volatility of VXZ
- β: slope of serial regression of VXX returns on VXZ returns (with intercept)
The position: short 1 unit of VXX, long h units of VXZ.
## Payoff / Return Profile
- Earns the differential roll loss between VXX and VXZ: the strategy benefits because VXX decays faster than VXZ in contango.
- The VXZ long position partially hedges against VIX spikes (which cause VXX to spike more sharply than VXZ).
- Profitable in normal, low-volatility, contango environments.
- Experiences sharp drawdowns during sudden VIX spikes (equity market selloffs), as VXX spikes more violently than VXZ in the short term.
## Key Parameters / Signals
- Contango in VIX futures curve: the necessary condition for the strategy to profit
- h = ρ · σ_X / σ_Z: hedge ratio (number of VXZ units per 1 unit of VXX shorted)
- Roll loss differential between VXX and VXZ: the carry being harvested
- VIX level and slope of futures curve: risk indicators
## Variations
### 7.3.1 Hedging Short VXX with VIX Futures
Instead of using VXZ to hedge, use a basket of N medium-maturity VIX futures (e.g., months 4-7) directly. The optimal weights w_i for the N futures:
```
w_i = σ_X Σ_{j=1}^N C_{ij}^{-1} σ_j ρ_j (432)
```
where:
- ρ_j: historical correlation between futures j and VXX returns
- C_{ij}: N×N sample covariance matrix of the N futures returns (C_{ii} = σ_i²)
- σ_X: historical volatility of VXX
Dollar-neutral constraint (optional): Σ_i w_i = 1 (Eq. 433). Some w_i may be negative; can impose w_i ≥ 0 if short futures is undesirable.
Portfolio can be rebalanced monthly or more frequently. This variation allows finer control over the hedge than using VXZ alone.
## Notes
- VXX spikes (which occur during equity market selloffs) can be large and sudden, causing substantial short-term P&L drawdowns even if the strategy is profitable overall.
- The hedge ratio h should be recalibrated periodically using updated historical data.
- The corresponding VXZ spikes are typically smaller, providing only partial protection during stress.
- Transaction costs (bid-ask spread on VXX/VXZ) and ETN management fees must be accounted for in return estimates.
- In sustained backwardation periods, both VXX and VXZ can rise; the strategy may lose money if VXX rises faster than VXZ.

View File

@@ -0,0 +1,63 @@
---
description: "Volatility risk premium strategy sells S&P 500 ATM straddles when implied volatility (VIX) exceeds recent realized volatility, capturing the persistent premium that implied vol commands over realized vol in normal markets."
tags: [volatility, risk-premium, straddle, vix, implied-volatility, realized-volatility]
---
# Volatility Risk Premium
**Section**: 7.4 | **Asset Class**: Volatility | **Type**: Carry / Short Volatility
## Overview
Implied volatility is empirically higher than realized volatility most of the time — the volatility risk premium. This means options are, on average, overpriced relative to their Black-Scholes fair value based on realized volatility. The strategy sells options (ATM straddles on S&P 500) when the premium is positive, earning the excess implied vol over realized vol. It is profitable in sideways markets but loses money during sharp volatility spikes.
## Construction / Mechanics
**Volatility risk premium proxy signal**: at the start of each month, compare:
- VIX (implied volatility of S&P 500, in %) at the beginning of the current month
- Realized volatility of S&P 500 daily returns (in %) since the beginning of the current month
If the spread (VIX - realized vol) is positive → **sell the ATM straddle** on S&P 500 options.
**Position**: short 1 near-ATM straddle (1 short ATM call + 1 short ATM put) on S&P 500 index options, held for approximately 1 month.
The straddle is ATM at inception, hence approximately Delta-neutral at entry. However, as the underlying moves, the straddle becomes Delta-nonzero.
## Payoff / Return Profile
- Earns the net option premium (implied vol minus realized vol differential) when the market moves less than implied by VIX.
- Profitable in low-volatility, sideways markets.
- Loses money when the S&P 500 moves sharply (volatility spike), which typically accompanies equity market selloffs.
- The "short vega" position loses immediately when implied volatility rises, even before expiry.
## Key Parameters / Signals
- VIX at month start: measure of implied volatility
- Realized vol of S&P 500 since month start: backward-looking volatility
- Spread = VIX - realized vol: entry signal (sell when positive)
- Strike selection: near-ATM (at-the-money) straddle
- Holding period: approximately 1 month (to option expiry)
## Variations
### 7.4.1 Volatility Risk Premium with Gamma Hedging
The ATM straddle is initially Delta-neutral but becomes Delta-nonzero as the S&P 500 moves. This variation adds Gamma hedging to maintain near-Delta-neutrality:
- **Gamma (Γ = ∂²V/∂S²)**: measures the rate of change of Delta with the underlying price.
- As the underlying moves up (down), the short straddle develops positive (negative) Delta.
- **Gamma hedge**: buy (sell) the underlying S&P 500 to offset the Delta change; i.e., trade the underlying in the direction opposite to the move.
Effect of Gamma hedging:
- The strategy becomes a "Theta play": profits from Theta (Θ = ∂V/∂t) decay — the time value of the short options erodes daily.
- The cost of Gamma hedging is the bid-ask spread and transaction costs of continuously rebalancing.
- As the underlying moves further from the strike, Gamma hedging becomes more expensive (the underlying positions become larger) and can eventually exceed the collected option premium, at which point the strategy loses money.
- This is also known as "Gamma scalping" (but from the short side — the hedger is short Gamma).
**Option Greeks for reference**:
- Θ = ∂V/∂t (Theta): time decay
- Δ = ∂V/∂S (Delta): sensitivity to underlying price
- Γ = ∂²V/∂S² (Gamma): sensitivity of Delta to underlying price
- ν = ∂V/∂σ (Vega): sensitivity to implied volatility
## Notes
- Index options (S&P 500) are better suited than single-stock options for this strategy because index options typically have higher volatility risk premia (see Section 6.3 on dispersion trading).
- A volatility spike (e.g., during a market selloff) causes both realized vol to rise and VIX to jump, producing large losses on both the Vega and Delta dimensions simultaneously.
- The strategy is sometimes described as "selling tail risk" — the premium earned in normal times compensates for large, infrequent losses.
- Gamma hedging reduces directional risk but cannot eliminate it for large moves; it also introduces transaction costs that reduce the effective premium earned.

View File

@@ -0,0 +1,53 @@
---
description: "Volatility skew risk reversal strategy buys an OTM call and sells an OTM put to exploit the empirical skew where put implied volatility exceeds call implied volatility, capturing a directional upside bias at reduced net premium cost."
tags: [volatility, skew, risk-reversal, options, put, call]
---
# Volatility Skew — Long Risk Reversal
**Section**: 7.5 | **Asset Class**: Volatility | **Type**: Volatility Skew / Directional
## Overview
OTM put options are empirically priced with higher implied volatility than OTM call options at the same distance from the current spot price. This volatility skew (puts more expensive than calls) reflects market demand for downside protection. The long risk reversal — buy an OTM call, sell an OTM put — captures this skew by selling the expensive put and buying the cheaper call, resulting in a net credit or reduced debit. However, the strategy has a directional component: it loses money if the underlying falls below the put strike.
## Construction / Mechanics
**Volatility skew setup**: with underlying S_0 = K (at-the-money), and OTM options at distance κ > 0:
- OTM put: strike K_put = K - κ; implied vol σ_put (higher)
- OTM call: strike K_call = K + κ; implied vol σ_call (lower)
- Skew: σ_put > σ_call (puts priced richer than calls at the same moneyness)
**Long risk reversal position**:
- **Buy** OTM call (strike K + κ): pays premium C_call
- **Sell** OTM put (strike K - κ): receives premium C_put > C_call
- Net premium received: C = C_put - C_call > 0 (net credit due to the skew)
Reference: see Section 2.12 of the book for the basic risk reversal option strategy.
## Payoff / Return Profile
- **If S_T > K + κ** (underlying rallies above call strike): call expires ITM; gain = S_T - (K+κ) + C
- **If K - κ < S_T < K + κ** (underlying stays between strikes): both options expire worthless; gain = C (the net premium received)
- **If S_T < K_put** (underlying falls below put strike): put expires ITM; loss = K_put - S_T - C; maximum loss when S_T 0 is K_put - C
- Break-even on the downside: S_T = K_put - C
The strategy profits when the underlying rises or stays stable, and loses when the underlying falls.
## Key Parameters / Signals
- K_put = K - κ: put strike (sold)
- K_call = K + κ: call strike (bought)
- κ: distance from ATM (moneyness)
- C = C_put - C_call: net premium received (positive due to skew)
- σ_put - σ_call: implied volatility skew the size of the mispricing being exploited
- K_put - C: downside break-even level
## Variations
- **Short risk reversal**: sell OTM call, buy OTM put a bearish, downside bet; profits if underlying falls below the put strike.
- **Skew trade without directional bias**: combine the risk reversal with a Delta hedge to isolate the pure skew component.
- **Different distances**: use asymmetric κ_put κ_call to fine-tune the net premium and directional exposure.
## Notes
- This is a directional strategy: it loses money if the price drops below K_put - C; the skew-capture is bundled with an implicit bullish bet.
- The strategy profits most clearly in a stable or rallying market with sustained volatility skew.
- The skew is typically larger for equity indexes than individual stocks (reflecting systematic put-buying for portfolio hedging).
- To isolate the pure skew trade (without directional exposure), the position should be Delta-hedged dynamically, which introduces transaction costs and complexity.
- Risk reversals are commonly used by FX traders where the skew direction can differ from equities (e.g., EURUSD calls can be more expensive than puts in certain regimes).