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,83 @@
---
description: "Futures momentum strategy that weights positions proportionally to the sign of recent returns scaled by historical volatility, equivalent to a diagonal-covariance mean-variance optimisation."
tags: [futures, momentum, trend-following, time-series, volatility-scaled]
---
# Trend Following (Momentum)
**Section**: 10.4 | **Asset Class**: Futures | **Type**: Momentum / Trend-Following
## Overview
Trend-following constructs a futures portfolio by going long instruments with positive recent returns and short those with negative returns, with position sizes inversely proportional to volatility. This is equivalent to a mean-variance optimisation using a diagonal covariance matrix (ignoring cross-futures correlations) and expected returns proportional to the sign of recent performance. It is one of the most widely used and robust strategies in futures markets.
## Construction / Mechanics
Let R_i be the return of futures i (i = 1,...,N) over a look-back period T. Define the trend signal:
```
η_i = sign(R_i) (475)
```
The portfolio weights are:
```
w_i = γ × (η_i / σ_i) (474)
```
where σ_i are the historical volatilities (computed over T or another window) and γ > 0 is fixed via:
```
Σ |w_i| = 1 (476)
```
**Dollar-neutral version**: demeaning the weights to achieve Σ w_i = 0:
```
w_i = γ [η_i/σ_i - (1/N) Σ η_j/σ_j] (477)
```
**Balanced long/short version**: when the number of long positions N+ ≈ number of short positions N- (i.e., N+ = |H+| ≈ N- = |H-|), use separate normalisation constants γ+ and γ-:
```
w_i = γ+ × η_i/σ_i, i ∈ H+ (η_i > 0) (478)
w_i = γ- × η_i/σ_i, i ∈ H- (η_i < 0) (479)
```
satisfying Eq. (476) and the dollar-neutrality condition:
```
Σ w_i = 0 (480)
```
**Demeaned returns variant**: replace R_i with R̃_i = R_i - R_m (market-adjusted returns, where R_m is Eq. (469)) to remove the common market factor and prevent skewed η_i distribution.
**Signal smoothing**: to avoid instability when |R_i| is small relative to σ_i (causing η_i to flip on minor changes), replace sign(R_i) with:
```
η_i = tanh(R_i / κ)
```
where κ is a smoothing parameter (e.g., the cross-sectional standard deviation of R_i).
## Return Profile
Profits when futures trend: long positions appreciate as upward trends continue, short positions benefit from sustained downward trends. The volatility scaling ensures that each position contributes roughly equal risk regardless of individual futures volatility. The strategy does not profit from mean-reversion.
## Key Parameters / Signals
| Parameter | Description |
|-----------|-------------|
| T | Look-back period for R_i and σ_i (days, weeks, or months) |
| η_i = sign(R_i) | Trend signal; +1 for uptrend, -1 for downtrend |
| σ_i | Historical volatility; normalises position size |
| γ | Scaling constant fixed by normalisation condition |
| κ | Smoothing parameter for tanh signal variant |
## Variations
- **Cumulative return signal**: use E_i = R_i directly (rather than sign) for expected returns; more continuous but potentially noisy.
- **Non-diagonal covariance**: use a full covariance matrix C_ij for more accurate portfolio optimisation (see Section 3.18, Eq. 350).
- **Multiple time horizons**: combine short-term (days), medium-term (weeks), and long-term (months) trend signals to diversify across time scales.
- **Exponential moving averages / HP filter**: apply to returns to suppress noise before computing η_i (Sections 3, 8.1).
## Notes
- The simple sign-based weights are not dollar-neutral by default; demeaning (Eq. 477) or the balanced variant (Eqs. 478-479) is required for dollar neutrality.
- Signal instability: for small |R_i| (compared to σ_i), η_i can flip on minor return changes; tanh smoothing mitigates this.
- Transaction costs are a meaningful drag because the strategy trades weekly or monthly and may have high turnover in trending markets that reverse.
- The strategy is broadly equivalent to standard managed futures / CTA approaches and has shown positive long-run performance across many asset classes and time periods.