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,46 @@
---
description: "Rotates into sector ETFs with the highest Jensen's alpha estimated from a Fama-French factor regression, replacing raw cumulative return momentum with factor-adjusted alpha as the ranking signal."
tags: [etfs, alpha, momentum, fama-french, rotation]
---
# Alpha Rotation
**Section**: 4.2 | **Asset Class**: ETFs | **Type**: Momentum / Factor-Adjusted Rotation
## Overview
Alpha rotation is structurally the same as the sector momentum rotation strategy (Section 4.1), but replaces cumulative ETF returns `R_i^cum` with ETF alphas `alpha_i`. These alphas are the Jensen's alpha regression coefficients from a serial regression of each ETF's returns on the Fama-French factors, representing the ETF's return unexplained by common risk factors.
## Construction / Signal
Run a serial regression of ETF returns `R_i(t)` on the 3 Fama-French factors (MKT, SMB, HML):
```
R_i(t) = alpha_i + beta_{1,i} MKT(t) + beta_{2,i} SMB(t) + beta_{3,i} HML(t) + epsilon_i(t) (364)
```
The regression coefficient `alpha_i` (Jensen's alpha) corresponds to the intercept and measures the ETF's risk-adjusted excess return relative to the Fama-French model. This alpha replaces `R_i^cum` as the ranking criterion.
ETFs are ranked by `alpha_i` (descending). Buy top-decile ETFs (highest alpha) and optionally short bottom-decile ETFs (lowest/most-negative alpha).
## Entry / Exit Rules
- **Entry**: At rebalance, estimate alpha for each ETF over the estimation period; rank and enter positions in top-decile (long) and optionally bottom-decile (short).
- **Exit**: Hold for the standard holding period; rebalance at next scheduled interval.
- **Estimation period**: Typically 1 year; returns `R_i(t)` are daily or weekly.
## Key Parameters
- **Factor model**: 3 Fama-French factors (MKT, SMB, HML); note alpha here is Jensen's alpha for ETF returns, not mutual fund alpha
- **Estimation period**: Typically 1 year
- **Return frequency for regression**: Daily or weekly `R_i(t)`
- **Holding period**: Same as sector momentum rotation (13 months)
- **Ranking criterion**: `alpha_i` (intercept of Fama-French regression)
## Variations
- **4-factor model**: Add Carhart momentum factor MOM(t) to regression for a 4-factor alpha
- **R-squared augmentation**: Combine alpha ranking with R-squared selectivity measure (see Section 4.3)
- **Long-only**: Buy only top-decile ETFs by alpha
## Notes
- Estimation period is typically 1 year with daily or weekly return data.
- Jensen's alpha here is defined for ETF returns (not mutual fund returns as in Jensen, 1968).
- Alpha rotation is analytically cleaner than raw momentum rotation as it removes systematic factor exposures from the ranking signal.
- The MA filter and dual-momentum variations from Section 4.1.1 and 4.1.2 can also be applied here.
- Can be combined with R-squared (Section 4.3) to further refine ETF selection.

View File

@@ -0,0 +1,49 @@
---
description: "Exploits the negative drift of leveraged ETF pairs by simultaneously shorting both a leveraged ETF and its inverse counterpart tracking the same index, capturing decay from daily rebalancing compounding."
tags: [etfs, leveraged-etf, letf, short-volatility, decay]
---
# Leveraged ETFs (LETFs)
**Section**: 4.5 | **Asset Class**: ETFs | **Type**: Short-Volatility / Structural Decay
## Overview
A leveraged (or inverse) ETF seeks to deliver a fixed multiple (2x, 3x) or the inverse (-1x, -2x, -3x) of the daily return of its underlying index. To maintain the target daily leverage, LETFs must rebalance every day — buying when the market is up and selling when it is down. This daily rebalancing creates a negative drift (volatility decay) in the long run, which can be exploited by shorting both a leveraged ETF and its corresponding leveraged inverse ETF on the same underlying index.
## Construction / Signal
A leveraged ETF with leverage factor L rebalances daily to maintain L × (daily index return). This requires:
- **On up days**: Buy more of the underlying index
- **On down days**: Sell the underlying index
The compounding of daily returns with daily rebalancing creates a path-dependent negative drift over time:
```
LETF cumulative return < L × (index cumulative return) [for L > 1 or L < -1]
```
**Strategy**: Short both a leveraged ETF (e.g., 2x) and its leveraged inverse ETF (-2x) on the same underlying index. Both positions decay in value over time due to daily rebalancing, generating profit from the combined negative drift.
Proceeds from both short positions can be invested in an uncorrelated asset (e.g., a Treasury ETF).
## Entry / Exit Rules
- **Entry**: Simultaneously short a leveraged ETF (e.g., 2x long) and its corresponding inverse leveraged ETF (e.g., 2x inverse) on the same underlying index.
- **Exit**: Positions are held as long as both ETFs continue to decay; may require periodic rebalancing of the short pair as relative prices change.
- **Capital deployment**: Invest the short proceeds into a Treasury ETF or other low-risk asset.
## Key Parameters
- **Leverage factor**: 2x or 3x (and their -2x or -3x inverses)
- **Underlying index**: Same index for both the leveraged and inverse leveraged ETF
- **Rebalancing of short pair**: Periodically rebalance the short positions to maintain equal dollar exposure
- **Volatility regime**: Decay is larger in high-volatility regimes
## Variations
- **3x pair**: Short a 3x leveraged ETF and its -3x inverse (higher decay, higher risk)
- **Single-leg short**: Short only the leveraged (not inverse) ETF when directional bias exists
- **Volatility regime filter**: Enter positions only in high-volatility environments where decay is expected to be larger
## Notes
- The negative drift from daily rebalancing is mathematically guaranteed over time for both the leveraged and inverse ETF, making this a structural (not purely alpha-dependent) source of return.
- **Key risk**: In the short term, if one leg of the short pair (e.g., the inverse ETF) has a large positive return (the market rallies strongly), the short position in the inverse ETF suffers a sizable loss. This short-term risk can be significant even though the long-term drift is negative.
- The strategy can have a significant downside in the short term if one short leg moves sharply against the position.
- Transaction costs (borrow costs for short selling LETFs, bid-ask spreads) must be carefully considered; LETF borrow rates can be elevated.
- Volatility decay is proportional to variance: approximately `L(L-1)/2 × sigma^2` per period for a leverage factor L.

View File

@@ -0,0 +1,57 @@
---
description: "Constructs a dollar-neutral ETF portfolio by selling ETFs with high Internal Bar Strength (IBS, close near daily high) and buying ETFs with low IBS (close near daily low), exploiting short-term mean-reversion."
tags: [etfs, mean-reversion, ibs, internal-bar-strength]
---
# Mean-Reversion (ETFs)
**Section**: 4.4 | **Asset Class**: ETFs | **Type**: Mean-Reversion
## Overview
This strategy applies mean-reversion to ETFs using the Internal Bar Strength (IBS) indicator, derived from the previous day's close, high, and low prices. ETFs with a close near their daily high (high IBS) are considered "rich" and likely to revert downward; ETFs with a close near their daily low (low IBS) are "cheap" and likely to revert upward. A dollar-neutral portfolio sells high-IBS ETFs and buys low-IBS ETFs.
## Construction / Signal
**Internal Bar Strength (IBS)**:
```
IBS = (P_C - P_L) / (P_H - P_L) (370)
```
Where:
- `P_C` = previous day's closing price
- `P_H` = previous day's high price
- `P_L` = previous day's low price
IBS ranges from 0 to 1:
- IBS close to 1: price closed near the daily high → ETF is "rich"
- IBS close to 0: price closed near the daily low → ETF is "cheap"
An equivalent symmetric measure: `Y = IBS - 1/2 = (P_C - P_*) / (P_H - P_L)` where `P_* = (P_H + P_L) / 2`; Y ranges from -1/2 to +1/2.
**Portfolio construction**:
- Sort ETFs cross-sectionally by IBS.
- Sell ETFs in the top decile (high IBS, "rich").
- Buy ETFs in the bottom decile (low IBS, "cheap").
- Dollar-neutral construction.
## Entry / Exit Rules
- **Entry**: Each day after the close, compute IBS for all ETFs, rank, and enter positions for the next day's open or close.
- **Exit**: Typically hold for 1 day (short-term mean-reversion); close at next day's close.
- **Rebalance**: Daily.
## Key Parameters
- **IBS computation**: Daily, using previous day's high, low, and close
- **Holding period**: Short-term (typically 1 day)
- **Portfolio construction**: Dollar-neutral long/short decile
- **Weights**: Uniform for all long and all short ETFs, or volatility-weighted
## Variations
- **Volatility-weighted positions**: Weight positions by historical ETF volatility rather than equal-weighting
- **Stock mean-reversion methods**: Mean-reversion strategies from Section 3 (cluster, weighted regression) can also be adapted to ETFs
- **IBS threshold**: Instead of top/bottom decile, use a fixed IBS threshold (e.g., IBS > 0.8 = short, IBS < 0.2 = long)
## Notes
- IBS is a simple, daily-bar indicator requiring only OHLC (open-high-low-close) data.
- Mean-reversion in ETFs can be stronger than in individual stocks because ETFs represent diversified baskets where idiosyncratic volatility is reduced, and market-maker arbitrage constrains large deviations from NAV.
- Holding period is very short (1 day); transaction costs can be significant for daily rebalancing.
- The strategy can be combined with other signals (e.g., sector momentum) for confirmation.
- All stock-based mean-reversion strategies (clusters, weighted regression) can be adapted for ETF universes.

View File

@@ -0,0 +1,70 @@
---
description: "Builds a long-only trend-following portfolio across multiple asset classes using ETFs, allocating weights proportional to cumulative momentum and optionally risk-adjusted by historical volatility, with an optional MA filter."
tags: [etfs, trend-following, multi-asset, momentum, long-only]
---
# Multi-Asset Trend Following
**Section**: 4.6 | **Asset Class**: ETFs | **Type**: Trend-Following / Multi-Asset
## Overview
ETFs allow efficient diversification across sectors, countries, asset classes, and factors in a relatively small number of instruments. This strategy constructs a long-only trend-following portfolio across multiple ETFs (and thus multiple asset classes) by allocating weights based on cumulative momentum, optionally filtered by a moving average, and weighted by historical volatility to manage risk.
## Construction / Signal
**Step 1 — Compute cumulative returns** over a T-month formation period (T = 612 months):
```
R_i^cum = P_i(t) / P_i(t+T) - 1
```
**Step 2 — Filter**: Keep only ETFs with positive `R_i^cum` (positive momentum required for long-only).
**Step 3 — Optional MA filter**: Additionally keep only ETFs whose last closing price P_i exceeds their moving average MA_i(T') (typically T' = 100200 days):
```
P_i > MA_i(T')
```
**Step 4 — Assign weights** to all surviving ETFs (not just top decile, since the universe is small):
Option A — proportional to cumulative return:
```
w_i = gamma_1 * R_i^cum (371)
```
Option B — momentum divided by volatility (Sharpe-like weighting):
```
w_i = gamma_2 * R_i^cum / sigma_i (372)
```
Option C — momentum divided by variance (Sharpe ratio optimization for diagonal covariance):
```
w_i = gamma_3 * R_i^cum / sigma_i^2 (373)
```
where `sigma_i` is historical ETF volatility and normalization coefficients `gamma_1`, `gamma_2`, `gamma_3` are computed to satisfy `sum_{i=1}^{N} w_i = 1` (N = number of ETFs with nonzero weights after filtering).
Option C (Eq. 373) optimizes the Sharpe ratio of the ETF portfolio assuming a diagonal covariance matrix `C_ij = diag(sigma_i^2)` (ignoring cross-ETF correlations).
## Entry / Exit Rules
- **Entry**: At each rebalance, apply momentum and MA filters, compute weights, and enter long positions in all surviving ETFs.
- **Exit**: Rebalance monthly (or per the formation period schedule); ETFs with negative cumulative momentum or below their MA are dropped (weight set to zero).
- **Position cap**: Bounds `w_i <= w_i^max` can be imposed to prevent overweighting of any single volatile ETF.
## Key Parameters
- **Formation period T**: 612 months
- **MA filter length T'**: 100200 days (optional; aligns with sector momentum rotation MA filter)
- **Weighting scheme**: Equal (Eq. 371), volatility-adjusted (Eq. 372), or variance-adjusted/Sharpe-optimal (Eq. 373)
- **Position cap**: Maximum weight per ETF (optional; mitigates concentration risk)
- **Holding period**: Monthly rebalancing typical
## Variations
- **No MA filter**: Use only positive cumulative return filter
- **With position caps**: Add `w_i <= w_i^max` to prevent overweighting high-momentum volatile ETFs
- **Sector rotation overlay**: Combine with sector momentum rotation (Section 4.1) by restricting the universe to top-ranked sectors
## Notes
- Eq. (371) is the simplest weighting; it overweights volatile ETFs since on average `R_i^cum ∝ sigma_i`.
- Eq. (372) mitigates volatility overweighting by dividing by sigma_i.
- Eq. (373) is the optimal Sharpe ratio solution under the assumption of uncorrelated (diagonal covariance) ETF returns.
- The key advantage of ETFs for multi-asset trend following: a small number of instruments (tens of ETFs) can provide exposure to many asset classes, sectors, geographies, and factors simultaneously.
- Long-only construction avoids shorting complexity; the MA filter prevents buying ETFs in absolute downtrends even if they have relative momentum.
- For some literature on multi-asset portfolios, dynamic asset allocation, and related topics: Bekkers, Doeswijk and Lam (2009), Black and Litterman (1992), Faber (2015, 2016), Mladina (2014).

View File

@@ -0,0 +1,63 @@
---
description: "Overweights ETFs with high selectivity (low R-squared against factor model) and high alpha, and underweights ETFs with low selectivity (high R-squared), using a two-dimensional sort on R-squared and alpha."
tags: [etfs, r-squared, alpha, selectivity, factor-model]
---
# R-Squared
**Section**: 4.3 | **Asset Class**: ETFs | **Type**: Factor-Based / Selectivity
## Overview
Empirical studies suggest that augmenting Jensen's alpha with an indicator based on R-squared from a factor model regression adds predictive value for future ETF returns. R-squared measures how much of an ETF's return variance is explained by common factors; low R-squared (high "selectivity") combined with high alpha predicts strong future performance. High R-squared (low selectivity) combined with low alpha predicts weak future performance.
## Construction / Signal
Run a serial regression of ETF returns `R_i(t)` on 4 factors (Fama-French 3 + Carhart momentum):
```
R_i(t) = alpha_i + beta_{1,i} MKT(t) + beta_{2,i} SMB(t) + beta_{3,i} HML(t) + beta_{4,i} MOM(t) + epsilon_i(t) (365)
```
Compute regression R-squared:
```
R^2 = 1 - SS_res / SS_tot (366)
SS_res = sum_{i=1}^{N} epsilon_i(t)^2 (367)
SS_tot = sum_{i=1}^{N} (R_i(t) - R_bar(t))^2 (368)
R_bar(t) = (1/N) * sum_{i=1}^{N} R_i(t) (369)
```
**Selectivity** = `1 - R^2` [Amihud and Goyenko, 2013]. High selectivity = low R-squared = returns less explained by common factors.
**Two-dimensional sort strategy**:
1. Sort ETFs into quintiles by R-squared (5 groups).
2. Within each R-squared quintile, sort ETFs into sub-quintiles by alpha (5 sub-groups).
3. This creates 25 groups of ETFs.
4. **Buy** ETFs in the group with lowest R-squared quintile and highest alpha sub-quintile.
5. **Sell** ETFs in the group with highest R-squared quintile and lowest alpha sub-quintile.
## Entry / Exit Rules
- **Entry**: At rebalance, run regression, compute R-squared and alpha for each ETF, perform 5×5 sort, enter long/short positions.
- **Exit**: Hold for estimation period or holding period; rebalance periodically.
- **Estimation period**: Same as alpha rotation (typically 1 year); longer estimation periods can be used, especially for monthly returns.
## Key Parameters
- **Factor model**: 4-factor (Fama-French 3 + Carhart MOM); 3-factor also usable
- **Estimation period**: Typically 1 year; can be longer for monthly return data
- **Sort dimensions**: R-squared quintiles × alpha sub-quintiles (5×5 = 25 groups)
- **Holding period**: Similar to alpha rotation strategy (13 months)
- **Selectivity definition**: `1 - R^2`
## Variations
- **3-factor model**: Use Fama-French 3 factors without momentum factor MOM
- **Different quintile splits**: Use deciles instead of quintiles for finer grouping
- **R-squared only**: Sort purely by R-squared without the alpha sub-sort
- **Estimation period alignment**: Use same estimation period as alpha rotation strategy (Section 4.2) for consistency
## Notes
- R-squared as a measure of active management: in Amihud and Goyenko (2013), R-squared is applied to mutual funds; Garyn-Tal (2014a, 2014b) applies it to actively managed ETFs.
- Low R-squared means the ETF has high "active share" — its returns are driven more by the manager's specific bets than by passive factor exposure.
- The estimation period and return frequency for R-squared can be the same as for alpha rotation (see Section 4.2 and fn. 77).
- Longer estimation periods are particularly appropriate if R_i(t) are monthly returns.
- Can be combined with the MA filter (Section 4.1.1) as an additional condition.

View File

@@ -0,0 +1,74 @@
---
description: "Overweights ETFs from outperforming sectors and underweights those from underperforming sectors based on T-month cumulative return momentum, with optional MA filter and dual-momentum variants."
tags: [etfs, momentum, sector-rotation]
---
# Sector Momentum Rotation
**Section**: 4.1 / 4.1.1 / 4.1.2 | **Asset Class**: ETFs | **Type**: Momentum / Sector Rotation
## Overview
Empirical evidence shows that the momentum effect exists not only for individual stocks but also for sectors and industries. The sector momentum rotation strategy overweights ETFs from outperforming sectors and underweights those from underperforming sectors, using ETFs concentrated in specific sectors/industries to implement sector/industry rotation without buying or selling large numbers of underlying stocks.
## Construction / Signal
Similarly to stock price-momentum (Section 3.1), use each sector ETF's cumulative return as the momentum measure. Let `P_i(t)` be the price of ETF labeled by i:
```
R_i^cum(t) = P_i(t) / P_i(t + T) - 1 (361)
```
Here `t + T` is T months in the past w.r.t. t. After time t, buy ETFs in the top decile by `R_i^cum(t)` and hold for a holding period (typically 13 months).
**Dollar-neutral construction**: Buy top-decile ETFs and short bottom-decile ETFs (ETFs can be shorted).
**Long-only construction**: Buy only top-decile ETFs, equal-weight or volatility-weight.
## Entry / Exit Rules
- **Entry**: At rebalance, rank all sector ETFs by cumulative return `R_i^cum`; buy top-decile, optionally short bottom-decile.
- **Exit**: Hold for 13 months; rebalance at the next scheduled interval.
- **Formation period T**: Typically 612 months.
## Key Parameters
- **Formation period T**: 612 months
- **Holding period**: 13 months
- **Portfolio construction**: Long-only (top decile) or dollar-neutral (top long, bottom short)
- **Weights**: Uniform or volatility-adjusted
## Variations
### 4.1.1 — Sector Momentum Rotation with MA Filter
A refinement that requires an ETF to pass a moving average filter before entering a position, preventing buys in sectors with downward price trends even if they rank high by relative momentum.
```
Rule = { Buy top-decile ETFs only if P > MA(T')
{ Short bottom-decile ETFs only if P < MA(T') (362)
```
- `P` = ETF's current price at transaction time
- `MA(T')` = moving average of ETF's daily prices over T' days (T' can differ from formation period T; typically T' = 100200 days)
This ensures the absolute price level (trend) also supports the trade direction.
### 4.1.2 — Dual-Momentum Sector Rotation
In long-only strategies, mitigates the risk of buying sector ETFs when the broad market is trending down. Augments relative (cross-sectional) momentum with absolute (time-series) momentum of a broad market index ETF:
```
Rule = { Buy top-decile ETFs if broad market P > MA(T')
{ Buy an uncorrelated ETF (e.g., gold, Treasury) if broad market P <= MA(T') (363)
```
- `P` = broad market index ETF's price at transaction time
- `MA(T')` = moving average of the broad market index ETF's price; typically T' = 100200 days
If the broad market is below its moving average (downtrend), capital is rotated into an ETF uncorrelated with the broad market (e.g., gold or Treasury ETF) instead of sector ETFs.
Reference: Antonacci (2014, 2017).
## Notes
- ETF-based sector rotation is simpler to implement than stock-level sector rotation: one ETF trade per sector instead of dozens of stock trades.
- The MA filter (4.1.1) reduces the chance of buying momentum in a sector that is in absolute decline.
- Dual-momentum (4.1.2) addresses the long-only strategy's vulnerability to broad market drawdowns.
- Typical formation period: 612 months; typical holding period: 13 months.
- Dollar-neutral construction removes broad market exposure but requires shorting ETFs (feasible in practice).