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,61 @@
---
description: "Capture or hedge the gross margin of a gas-fired power plant by trading the spread between wholesale electricity prices and natural gas fuel costs, using electricity and gas futures in the ratio determined by the plant's heat rate."
tags: [miscellaneous, energy, spread-trading, hedging, commodities]
---
# Energy — Spark Spread
**Section**: 14.4 | **Asset Class**: Miscellaneous (Energy Commodities) | **Type**: Spread Trading / Hedging
## Overview
The spark spread is the difference between the wholesale price of electricity and the price of natural gas required to produce it. It measures the gross margin of a gas-fired power plant (excluding all other costs: operation, maintenance, capital, etc.). A spark spread position is built by taking a short position in electricity futures and a long position in natural gas futures, in the ratio determined by the plant's heat rate.
## Construction / Mechanics
**Heat rate** (fuel efficiency of the power plant):
```
H = Q_F / Q_E (516)
```
- `Q_F` = amount of fuel (natural gas) used, measured in MMBtu
- `Q_E` = electricity produced, measured in MWh
- `H` measured in MMBtu/MWh
- MMBtu = 1,000,000 Btu; Btu ≈ 1,055 Joules
**Spark spread** (in $/MWh):
```
S = P_E - H × P_F (517)
```
- `P_E` = price of electricity ($/MWh)
- `P_F` = price of natural gas ($/MMBtu)
**Hedge ratio** for futures contracts:
```
h = H × F_E / F_F (518)
```
- `F_E = 736 MWh` (standard electricity futures contract size)
- `F_F = 10,000 MMBtu` (standard natural gas futures contract size)
Since `h` is generally not a whole number, it is approximated as the ratio `h ≈ N_F / N_E` with the lowest possible whole-number denominator `N_E`. The hedge consists of buying `N_F` gas futures contracts for every `N_E` sold electricity futures contracts.
## Return Profile
- **Electricity producer (natural hedge)**: short electricity futures + long gas futures locks in a fixed spark spread, hedging against a compression of the gross margin
- **Speculator / spread trader**: profits if the spark spread widens (electricity prices rise relative to gas prices) on a long spread position, or if it narrows on a short spread position
- The strategy has no directional energy price exposure — only exposure to the relative price of electricity vs. natural gas
## Key Parameters / Signals
- **Heat rate `H`**: plant-specific efficiency; lower `H` = more efficient plant = higher spark spread for the same fuel cost
- **Spark spread `S`**: core signal; compare to historical average or fair value based on plant operating costs
- **Contract sizes `F_E`, `F_F`**: determine the achievable hedge ratio granularity
- **Seasonal patterns**: electricity demand (and spark spread) exhibits strong seasonality driven by heating/cooling demand
## Variations
- **Dark spread**: same concept for coal-fired power plants (replaces natural gas with coal prices)
- **Quark spread**: same concept for nuclear power plants
- **Clean spark spread**: adjusts for carbon emission costs (CO2 allowance prices) in addition to fuel costs
## Notes
- The spark spread measures gross margin only; it does not account for fixed operating costs, maintenance, or capital expenditures
- Basis risk exists between the price indexes referenced in futures contracts and the actual spot prices at the delivery location
- Liquidity is concentrated in front-month contracts; longer-dated spark spread trades may have wide bid-ask spreads
- Heat rates vary with plant load and ambient temperature; a single fixed `H` is an approximation
- Regulatory risk: electricity markets are often heavily regulated; price caps and dispatch rules can affect realized spreads

View File

@@ -0,0 +1,56 @@
---
description: "Buy or sell inflation swaps to exchange fixed and floating (CPI-linked) cash flows, hedging against unexpected inflation or speculating on inflation relative to the breakeven rate."
tags: [miscellaneous, inflation, derivatives, swaps, fixed-income]
---
# Inflation Hedging — Inflation Swaps
**Section**: 14.1 | **Asset Class**: Miscellaneous (Inflation Derivatives) | **Type**: Hedging / Macro
## Overview
Inflation swaps allow parties to exchange a fixed rate of inflation for a floating (CPI-linked) rate, analogous to interest rate swaps. A buyer of an inflation swap is long inflation: they receive the floating CPI-linked rate and pay the fixed rate ("breakeven rate"). The buyer profits if realized inflation exceeds expected inflation (i.e., the fixed swap rate). The fixed rate is typically calculated as the spread between Treasury notes/bonds and TIPS with the same maturity.
## Construction / Mechanics
### Zero-Coupon Inflation Swap (ZC)
The most common type. Only one cash flow at maturity `T` (in years). Cash flows per $1 notional:
```
C_fixed = (1 + K)^T - 1 (500)
C_floating = I(T)/I(0) - 1 (501)
```
- `K` = fixed rate (the "breakeven rate")
- `I(t)` = CPI value at time `t`; `t = 0` is when the swap is entered into
### Year-on-Year Inflation Swap (YoY)
References annual inflation rather than cumulative. Assuming annual payments (`t = 1, ..., T`):
```
C_fixed(t) = K (502)
C_floating(t) = I(t)/I(t-1) - 1 (503)
```
The buyer pays `C_fixed` and receives `C_floating` at each period.
## Return Profile
- **Buyer (long inflation)**: profits when realized CPI exceeds the breakeven rate `K`; losses when inflation is lower than expected
- **Seller (short inflation)**: profits when realized inflation is below `K`
- Returns are driven by the difference between realized inflation and the fixed swap rate; there is no equity or credit risk in a plain vanilla inflation swap
## Key Parameters / Signals
- **Breakeven rate** `K`: the fixed rate embedded in the swap; derived from the Treasury/TIPS spread for the same maturity
- **CPI index** `I(t)`: typically the Consumer Price Index; contract specifies which index and lag
- **Maturity** `T`: ZC swaps concentrate all cash flow at maturity; YoY swaps distribute annual payments
- **Notional**: scales all cash flows linearly
## Variations
- **Zero-Coupon vs. Year-on-Year**: ZC is simpler with one cash flow; YoY resets annually and is less sensitive to base-period CPI distortions
- **Real rate swaps**: swap fixed real rate for floating real rate; related but distinct instrument
- **Inflation caps/floors**: options on inflation; cap protects buyer if inflation exceeds a ceiling rate
## Notes
- Liquidity in inflation swap markets is concentrated in major currencies (USD, EUR, GBP)
- Counterparty risk: OTC instruments; cleared versions available on some CCPs
- Basis risk between the CPI index in the swap and the actual inflation exposure being hedged
- The fixed rate `K` is model-independent (observed from market), but fair value of the floating leg requires CPI forecasting

View File

@@ -0,0 +1,65 @@
---
description: "Short an overvalued Treasury bond and offset it with a synthetic replicating portfolio of TIPS plus zero-coupon inflation swaps, capturing the empirically persistent positive cash flow at inception."
tags: [miscellaneous, arbitrage, fixed-income, TIPS, Treasuries]
---
# TIPS-Treasury Arbitrage
**Section**: 14.2 | **Asset Class**: Miscellaneous (Fixed Income) | **Type**: Arbitrage
## Overview
Based on the empirical observation that Treasury bonds are almost persistently overvalued relative to TIPS (Treasury Inflation-Protected Securities). The strategy shorts a Treasury bond and offsets the position with a synthetic portfolio that precisely replicates all Treasury bond cash flows using TIPS and zero-coupon inflation swaps. Because the synthetic portfolio costs less than the Treasury bond, the net cash flow at inception is positive, representing the arbitrage profit.
## Construction / Mechanics
**Short leg**: Sell Treasury bond with price `P_Treasury`, fixed coupon rate `r_Treasury`, maturity `T`.
**Synthetic replicating portfolio** (long legs):
- Buy TIPS with price `P_TIPS`, maturity `T`, fixed coupon rate `r`, and `n` coupon payments at times `t_i` (`i = 1, ..., n`, with `t_n = T`)
- Simultaneously sell `n` zero-coupon inflation swaps with maturities `t_i`, fixed rate `K`, and notionals:
```
N_i = r + δ_{t_i, T} per $1 of TIPS principal
```
where `δ_{t_i, T} = 1` if `i = n` (maturity), 0 otherwise (to match principal repayment)
**TIPS cash flows** (per $1 notional; `I(t)` = CPI at time `t`):
```
C_TIPS(t_i) = N_i × I(t_i)/I(0) (504)
C_swap(t_i) = N_i × [(1 + K)^t_i - I(t_i)/I(0)] (505)
C_total(t_i) = C_swap(t_i) + C_TIPS(t_i) = N_i(1 + K)^t_i (506)
```
The total cash flow replicates fixed coupon payments with effective coupon rates `r_eff(t_i) = r(1 + K)^t_i`.
**STRIPS positions** to match Treasury coupons exactly (small long or short positions in zero-coupon discount bonds):
```
S(t_i) = D(t_i) × {[r_Treasury - r_eff(t_i)] + δ_{t_i,T} × [1 - (1+K)^t_i]} (507)
```
where `D(τ)` is the discount factor (STRIPS value) with maturity `τ`.
**Net cash flow at inception**:
```
C(0) = P_Treasury - P_TIPS - Σ S(t_i) (508)
i=1
```
Empirically, `C(0) > 0` even after transaction costs — hence arbitrage.
## Return Profile
The profit is locked in at trade inception as a positive `C(0)`. All subsequent cash flows net to zero by construction (the synthetic portfolio precisely replicates the Treasury). Returns are model-independent and driven purely by the persistent Treasury overvaluation relative to TIPS.
## Key Parameters / Signals
- **`C(0)`**: the net cash flow at inception; must be positive (and cover transaction costs) for the trade to be worthwhile
- **STRIPS prices** `D(t_i)`: discount factors; observable from market
- **Fixed rate** `K` on inflation swaps: the breakeven inflation rate
- **TIPS coupon rate** `r` and Treasury coupon rate `r_Treasury`: the gap drives the size of STRIPS adjustments
## Variations
- **Duration-neutral overlay**: combine with duration hedges to isolate the mispricing from interest rate directionality
- **Partial replication**: use a subset of STRIPS to approximately replicate, reducing transaction costs at the expense of perfect replication
## Notes
- Transaction costs (bid-ask spreads on TIPS, inflation swaps, STRIPS) can erode `C(0)`; the trade is only viable when mispricing is large enough
- STRIPS = "Separate Trading of Registered Interest and Principal of Securities" — zero-coupon discount bonds
- The persistent Treasury overvaluation has been documented empirically but can narrow or temporarily reverse
- Short selling Treasuries requires repo market access; repo rates affect the total cost of carry
- Regulatory constraints on short positions in government securities may limit implementation

View File

@@ -0,0 +1,70 @@
---
description: "Hedge weather-driven demand risk using weather derivatives (futures or options on temperature indices) with hedge ratios calibrated to the covariance between demand and the relevant temperature index."
tags: [miscellaneous, hedging, weather-derivatives, energy]
---
# Weather Risk — Demand Hedging
**Section**: 14.3 | **Asset Class**: Miscellaneous (Weather Derivatives) | **Type**: Hedging
## Overview
Many businesses and economic sectors are affected by weather conditions both directly (e.g., energy consumption) and indirectly. Weather risk is hedged using weather derivatives, which reference synthetic temperature indexes since no tradable weather indexes exist. The two most common indexes are based on temperature: Cooling-Degree-Days (CDD) for extreme heat and Heating-Degree-Days (HDD) for extreme cold.
## Construction / Mechanics
**Temperature indexes** (over a contract life of `n` days):
```
I_CDD = Σ max(0, T_i - T_base) (509)
i=1
I_HDD = Σ max(0, T_base - T_i) (510)
i=1
T_i = (T_i^min + T_i^max) / 2 (511)
```
- `T_i` = average daily temperature on day `i`
- `T_i^min`, `T_i^max` = minimum and maximum temperatures on day `i`
- `T_base = 65°F`
**Hedging demand risk for heating (HDD)**:
Using a short futures position or a long put option:
```
h_futures^HDD = Cov(q_w, I_HDD) / Var(I_HDD) (512)
h_put^HDD = -Cov(q_w, max(K - I_HDD, 0)) / Var(max(K - I_HDD, 0)) (513)
```
**Hedging demand risk for cooling (CDD)**:
Using a long futures position or a long call option:
```
h_futures^CDD = Cov(q_w, I_CDD) / Var(I_CDD) (514)
h_call^CDD = Cov(q_w, max(I_CDD - K, 0)) / Var(max(I_CDD - K, 0)) (515)
```
- `q_w` = the portion of demand affected by weather conditions (excluding other exogenous, non-weather components)
- `K` = strike price of the option
- Cov and Var are serial (co)variances
## Return Profile
The hedge reduces weather-driven demand volatility. The futures hedge provides linear protection against temperature deviations from average; the options hedge provides asymmetric protection (puts for heating risk, calls for cooling risk). In non-extreme weather years the hedge has negative carry (cost of options, or futures mark-to-market losses when weather is mild).
## Key Parameters / Signals
- **`q_w`**: weather-sensitive component of demand; must be isolated from non-weather demand drivers
- **Hedge ratios** `h_futures` and `h_put/h_call`: computed from historical Cov/Var of demand vs. temperature index
- **Contract life `n`**: weekly, monthly, or seasonal contracts available
- **Base temperature `T_base = 65°F`**: standard for U.S. CME weather contracts
- **Strike `K`**: for option-based hedges; determines payoff profile
## Variations
- **Futures-only hedge**: simpler, linear; appropriate when demand has approximately linear sensitivity to temperature
- **Options hedge**: asymmetric protection; appropriate when the cost of extreme weather is highly nonlinear
- **Combination**: futures for expected temperature deviation plus options for tail risk
## Notes
- No "tradable" weather indexes exist; all weather derivatives reference synthetic indexes based on temperature data from specified weather stations
- Basis risk between the specific weather station used in the contract and the firm's actual geographic exposure
- Liquidity is concentrated in CME weather futures for major U.S. cities; OTC markets cover more locations but with less liquidity
- Weather derivatives are used primarily by energy companies, agriculture, retail, and travel industries
- Historical Cov/Var estimates may not be stable across climate regimes; model recalibration is needed periodically