Files
ai/gateway/knowledge/trading/strategies/stocks/statistical-arbitrage-optimization.md
Tim Olson 47471b7700 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
2026-04-28 15:05:15 -04:00

80 lines
4.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
description: "Optimizes portfolio weights by maximizing the Sharpe ratio given expected stock returns and a covariance matrix, with an optional dollar-neutrality constraint enforced via a Lagrange multiplier."
tags: [stocks, statistical-arbitrage, optimization, portfolio-construction, sharpe-ratio]
---
# Statistical Arbitrage — Optimization
**Section**: 3.18 / 3.18.1 | **Asset Class**: Stocks | **Type**: Statistical Arbitrage / Portfolio Optimization
## Overview
This strategy determines optimal portfolio weights by maximizing the Sharpe ratio given expected returns E_i and a covariance matrix C_ij for N stocks. The unconstrained solution gives a closed-form inverse-covariance-weighted portfolio. A dollar-neutrality constraint can be imposed via a Lagrange multiplier, yielding a modified allocation that suppresses positions by stock volatilities.
## Construction / Signal
Let `C_ij` be the N×N covariance matrix of stock returns, `D_i` the dollar holdings, `I` the total investment, and `w_i = D_i / I` the dimensionless weights.
**Portfolio P&L, volatility, and Sharpe ratio**:
```
P = sum_{i=1}^{N} E_i D_i (342)
V^2 = sum_{i,j=1}^{N} C_ij D_i D_j (343)
S = P / V (344)
```
Normalized: `P = I * P_tilde`, `V = I * V_tilde`, `S = P_tilde / V_tilde` where:
```
P_tilde = sum_{i=1}^{N} E_i w_i (347)
V_tilde^2 = sum_{i,j=1}^{N} C_ij w_i w_j (348)
```
with constraint `sum_{i=1}^{N} |w_i| = 1`.
**Unconstrained Sharpe maximization** (maximize S → max):
Solution:
```
w_i = gamma * sum_{j=1}^{N} C_ij^{-1} E_j (350)
```
where gamma is fixed by the normalization `sum |w_i| = 1`. These weights are not dollar-neutral in general.
## Entry / Exit Rules
- **Entry**: At each rebalance, solve for optimal weights w_i using expected returns E_i and covariance matrix C_ij; establish long positions for w_i > 0 and short positions for w_i < 0.
- **Exit**: Rebalance periodically (daily or at the signal horizon); close positions that change sign or fall below a threshold.
## Key Parameters
- **Expected returns E_i**: Can come from mean-reversion, momentum, ML signals, or other alpha sources
- **Covariance matrix C_ij**: Typically a multifactor risk model covariance (sample covariance is singular if T N+1)
- **Total investment I**: Scales all positions
- **Rebalance frequency**: Depends on signal horizon
## Variations
### 3.18.1 — Dollar-Neutrality
To enforce dollar-neutrality (`sum w_i = 0`), use the Sharpe ratio's scale invariance to reformulate as a quadratic minimization with a Lagrange multiplier mu:
```
g(w, lambda) = (lambda/2) * sum_{i,j} C_ij w_i w_j - sum_i E_i w_i - mu * sum_i w_i (354)
g(w, mu, lambda) -> min (355)
```
Minimization w.r.t. w_i and mu gives:
```
lambda * sum_j C_ij w_j = E_i + mu (356)
sum_i w_i = 0 (357)
```
Dollar-neutral solution:
```
w_i = (1/lambda) * [sum_j C_ij^{-1} E_j - C_ij^{-1} * (sum_{k,l} C_kl^{-1} E_l) / (sum_{k,l} C_kl^{-1})] (358)
```
Lambda is fixed by the normalization `sum |w_i| = 1`. The weights w_i are approximately suppressed by stock volatilities sigma_i (since C_ii = sigma_i^2 and typically |E_i| ~ sigma_i), providing built-in risk management.
## Notes
- The sample covariance matrix is singular if T N+1 (T = number of time observations); in practice a model covariance matrix (positive-definite, stable out-of-sample) is required.
- Eq. (350) is the unconstrained mean-variance (Markowitz, 1952) optimal portfolio.
- The dollar-neutrality solution (Eq. 358) removes market beta and is equivalent to imposing the constraint as a linear homogeneous condition on the quadratic objective.
- Expected returns E_i can be any alpha signal: mean-reversion residuals, momentum scores, ML predictions, etc.
- With a multifactor model C_ij, positions are approximately neutral to factor exposures; exact neutrality is achieved in the zero specific-risk limit (which reduces to weighted regression, see Section 3.10).
- In practice, trading costs, position/trading bounds, and nonlinear constraints are added; this generally breaks the equivalence between Sharpe maximization and quadratic minimization.