[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CBPAME590F8T7T6JP832H2":3,"skill-same:01M7CBPAME590F8T7T6JP832H2":56},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":29,"ownerDescription":30,"updatedAt":31,"install":32,"resources":45},"01M7CBPAME590F8T7T6JP832H2","x-trend-architecture",null,"Use when implementing X-Trend or attention-based trading models. Covers LSTM encoders, cross-attention, self-attention, sequence representations, entity embeddings, Variable Selection Networks, encoder-decoder patterns, Deep Momentum Networks, and interpretable predictions for trend-following strategies.","shenyimings\u002Fskillet","shenyimings","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F89332218?v=4","01M7C9KHMXPPXMQJCKN78FKB06","Yiming Shen","01M7C9KHP4KS809T2A9T64YDWE",0,"MIT","https:\u002F\u002Fgithub.com\u002Fshenyimings\u002Fskillet\u002Fblob\u002Fmain\u002Fbenchmark\u002Fwild\u002Fdev\u002Fsuspicious\u002FDonaldshen27__xtrend-vanilla__.claude__skills__x-trend-architecture\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: x-trend-architecture\ndescription: Use when implementing X-Trend or attention-based trading models. Covers LSTM encoders, cross-attention, self-attention, sequence representations, entity embeddings, Variable Selection Networks, encoder-decoder patterns, Deep Momentum Networks, and interpretable predictions for trend-following strategies.\n---\n\n# X-Trend Architecture\n\n## Purpose\n\nComplete guide to implementing the X-Trend (Cross Attentive Time-Series Trend Network) architecture, combining LSTMs, attention mechanisms, and few-shot learning for trend-following strategies.\n\n## When to Use\n\nActivate this skill when:\n- Implementing X-Trend or similar attention-based trading models\n- Building encoder-decoder architectures for finance\n- Using cross-attention mechanisms\n- Implementing Deep Momentum Networks (DMNs)\n- Creating interpretable trading predictions\n- Combining forecasting with position-taking\n\n## Architecture Overview\n\n```\nInput: Target sequence x[t] + Context set C\n       ↓\n[Encoder]\n   - LSTM for sequences\n   - Entity embeddings\n   - Variable Selection Network (VSN)\n   - Self-attention over context\n   - Cross-attention: target ← context\n       ↓\n[Decoder]\n   - LSTM with encoder output\n   - Dual heads: Forecast + Position\n   - PTP (Predictive distribution To Position)\n       ↓\nOutput: Trading position z[t] ∈ [-1, 1]\n        + Forecast distribution (μ, σ) or quantiles\n```\n\n## Core Components\n\n### 1. Input Features\n\nThe model takes 8-dimensional feature vectors combining:\n- **Normalized returns** at multiple timescales (5 features): 1, 21, 63, 126, 252 days\n- **MACD indicators** at multiple (S,L) pairs (3 features): (8,24), (16,28), (32,96)\n\nNormalization formula for returns:\n```\nr_hat[t-t', t] = r[t-t',t] \u002F (σ[t] * sqrt(t'))\n```\n\n**IMPORTANT**: Use EWMA (exponentially weighted moving average) for volatility calculation:\n```python\nvolatility = prices.pct_change().ewm(span=60).std()\n```\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#input-features) for full code.\n\n### 2. Variable Selection Network (VSN)\n\nLearns to weight different input features dynamically:\n\n- Transforms each feature with dedicated FFN: `v[j,t] = FFN_j(x[j,t])`\n- Computes attention weights: `w[t] = softmax(FFN_weight(x[t]))`\n- Produces weighted sum: `VSN(x[t]) = Σ w[j,t] * v[j,t]`\n\n**Purpose**: Automatically determines which features (returns vs MACD, short-term vs long-term) are most relevant at each time step.\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#variable-selection-network-vsn) for PyTorch implementation.\n\n### 3. Entity Embeddings\n\nLearn asset-specific representations:\n\n- Each asset gets learnable embedding vector\n- Automatically clusters similar assets (equities, commodities, etc.)\n- Added to sequence representations for few-shot learning\n\n**Important**: Exclude entity embeddings for zero-shot learning (unseen assets).\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#entity-embeddings) for code.\n\n### 4. Sequence Encoder\n\nLSTM-based encoder with skip connections:\n\n1. VSN for feature selection\n2. LSTM for temporal modeling\n3. LayerNorm + skip connections for stability\n4. FFN with entity embedding\n5. Final residual connection\n\n**Architecture Pattern**: `x → VSN → LSTM → (+skip) → LayerNorm → FFN(+entity) → (+skip) → LayerNorm`\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#sequence-encoder) for full implementation.\n\n### 5. Cross-Attention Mechanism\n\nTarget sequence attends to context sequences:\n\n```\nAttention(Q, K, V) = softmax(QK^T \u002F √d) V\n\nwhere:\n- Q (queries): From target sequence\n- K (keys): From context sequences\n- V (values): From context sequences\n```\n\n**Multi-head attention** (4 heads recommended) allows model to focus on different aspects simultaneously.\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#cross-attention-mechanism) for code.\n\n### 6. Self-Attention Over Context\n\nContext sequences attend to each other before cross-attention:\n\n- Identifies similarities between different context sequences\n- Helps model understand relationships within context set\n- Uses same attention mechanism as cross-attention (Q=K=V=context)\n\n**Flow**: Context → Self-Attention → Cross-Attention with Target\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#self-attention-over-context) for implementation.\n\n### 7. X-Trend Encoder\n\nCombines all encoder components:\n\n1. Encode each context sequence (LSTM + VSN + entity embedding)\n2. Apply self-attention over context encodings\n3. Encode target sequence\n4. Apply cross-attention: target queries context\n5. FFN with residual connection\n\n**Output**: Enriched target representation informed by context patterns.\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#x-trend-encoder) for complete code.\n\n### 8. Decoder\n\nProduces trading signals and forecasts:\n\n**Inputs**: Target features + Encoder output\n**Outputs**: Position z[t] ∈ [-1,1] + Forecast (μ, σ) or quantiles\n\n**Architecture**:\n1. VSN on target features\n2. Concatenate with encoder output\n3. LSTM processing\n4. Dual prediction heads:\n   - **Forecast head**: Predicts return distribution\n   - **Position head**: Either PTP (uses forecast) or direct Sharpe\n\n**Three Variants**:\n- **X-Trend**: Direct Sharpe optimization (no forecast)\n- **X-Trend-G**: Joint Gaussian MLE + Sharpe\n- **X-Trend-Q**: Joint Quantile Regression + Sharpe\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#decoder) for implementation details.\n\n### 9. Complete Model\n\nThe full X-Trend model combines encoder and decoder:\n\n```python\nclass XTrendModel(nn.Module):\n    def __init__(self, input_dim=8, hidden_dim=64, num_assets=50,\n                 forecast_type='gaussian', num_heads=4):\n        self.encoder = XTrendEncoder(...)\n        self.decoder = XTrendDecoder(...)\n\n    def forward(self, target_features, target_asset_id,\n               context_features, context_asset_ids, use_ptp=True):\n        # Encode with attention over context\n        encoder_output, attention_weights = self.encoder(...)\n\n        # Decode to position + forecast\n        position, forecast = self.decoder(...)\n\n        return position, forecast, attention_weights\n```\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#complete-x-trend-model) for full code.\n\n## Training\n\n### Loss Functions\n\n**Sharpe Loss**:\n```python\nL_Sharpe = -sqrt(252) * mean(returns) \u002F std(returns)\n```\n\n**Gaussian MLE Loss**:\n```python\nL_MLE = -log p(r | μ, σ)\n```\n\n**Joint Loss**:\n```python\nL_joint = α * L_forecast + L_Sharpe\n```\n\nWhere α = 1.0 for Gaussian, α = 5.0 for Quantile.\n\n### Training Protocol\n\n1. **Episodic Learning**: Train in episodes, not mini-batches\n2. **Sample target** (asset, time) from training set\n3. **Sample context set** causally (before target time)\n4. **Forward pass** through encoder + decoder\n5. **Compute joint loss** balancing forecasting and trading\n6. **Backward pass** with gradient clipping (max norm = 10.0)\n\n### Hyperparameters\n\n```python\n{\n    'input_dim': 8,\n    'hidden_dim': 64,\n    'num_assets': 50,\n    'num_heads': 4,\n    'context_size': 20,\n    'seq_len': 126,        # 6 months\n    'learning_rate': 1e-3,\n    'alpha': 1.0,          # Joint loss weight\n    'dropout': 0.3,\n    'target_vol': 0.15\n}\n```\n\nSee [TRAINING.md](TRAINING.md) for complete training guide including:\n- Full training loop implementation\n- Validation procedures\n- Optimizer configuration\n- Common training issues and solutions\n\n## Interpretation\n\n### Attention Weights\n\nVisualize which context sequences the model attends to:\n\n```python\n_, _, attention_weights = model(target, context)\n# Shape: (batch, num_heads, seq_len, num_contexts)\n\n# Average across heads and time\navg_attention = attention_weights.mean(dim=(0, 1, 2))\n\n# Top 3 most important contexts\ntop_k = torch.topk(avg_attention, k=3)\n```\n\n**Use for**:\n- Understanding model decisions\n- Debugging unexpected predictions\n- Validating that model uses context meaningfully\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#interpretation) for visualization code.\n\n## Best Practices\n\n### DO:\n\n✅ **Use LayerNorm + skip connections** for stable training\n✅ **Entity embeddings for few-shot** but exclude for zero-shot\n✅ **Multi-head attention** (4 heads is good default)\n✅ **Joint loss training** balances forecasting and trading\n✅ **Episodic training** mimics test-time usage\n✅ **Gradient clipping** (max norm = 10.0)\n✅ **EWMA for volatility** (span=60) not simple rolling std\n✅ **Monitor attention weights** to ensure meaningful patterns\n\n### DON'T:\n\n❌ **Don't skip warm-up** - first 63 predictions are unstable\n❌ **Don't use entity embeddings in zero-shot** - model hasn't seen asset\n❌ **Don't mix training data** - use episodes, not mini-batches\n❌ **Don't ignore attention interpretation** - helps debug\n❌ **Don't forget dropout** (0.3-0.5) for regularization\n❌ **Don't use simple rolling std** - use EWMA for volatility\n\n## Performance Expectations\n\nBased on X-Trend paper results (2018-2023):\n\n**Few-Shot Learning:**\n- Baseline: Sharpe = 2.27\n- X-Trend-Q: Sharpe = 2.70 (+18.9%)\n- vs TSMOM: Sharpe = 0.23 (10× improvement)\n\n**Zero-Shot Learning:**\n- Baseline: Sharpe = -0.11 (loss-making)\n- X-Trend-G: Sharpe = 0.47 (profitable)\n- 5× improvement over baseline\n\n**COVID-19 Recovery:**\n- Baseline: 254 days to recover\n- X-Trend: 162 days (2× faster)\n\n## Implementation Checklist\n\nWhen implementing X-Trend:\n\n- [ ] Input features with EWMA volatility normalization\n- [ ] Variable Selection Network for feature weighting\n- [ ] Entity embeddings (few-shot) or exclude (zero-shot)\n- [ ] LSTM encoders with LayerNorm and skip connections\n- [ ] Self-attention over context set\n- [ ] Multi-head cross-attention (4 heads)\n- [ ] Decoder with dual prediction heads\n- [ ] Joint loss function (α * L_forecast + L_Sharpe)\n- [ ] Episodic training loop\n- [ ] Gradient clipping (max norm = 10.0)\n- [ ] Dropout regularization (0.3-0.5)\n- [ ] CPD-based context sampling for best performance\n- [ ] Attention weight visualization for interpretation\n\n## Architecture Variants\n\n### X-Trend (Base)\n- **Objective**: Direct Sharpe optimization\n- **Heads**: Position only (no forecast)\n- **Best for**: Pure trading performance\n\n### X-Trend-G (Gaussian)\n- **Objective**: Joint MLE + Sharpe (α=1.0)\n- **Forecast**: Gaussian (μ, σ)\n- **Best for**: Balanced forecasting + trading\n\n### X-Trend-Q (Quantile)\n- **Objective**: Joint Quantile + Sharpe (α=5.0)\n- **Forecast**: 13 quantiles\n- **Best for**: Robust predictions, tail risk\n\n## Related Skills\n\n- `financial-time-series` - Input features, returns, momentum\n- `few-shot-learning-finance` - Episodic training, context construction\n- `change-point-detection` - CPD for context set improvement\n\n## Reference Files\n\n- [IMPLEMENTATION.md](IMPLEMENTATION.md) - Complete PyTorch implementations of all components\n- [TRAINING.md](TRAINING.md) - Training loop, loss functions, hyperparameters, best practices\n\n## References\n\n- Attention Is All You Need (Vaswani et al. 2017)\n- Deep Momentum Networks (Lim, Zohren, Roberts 2019)\n- Attentive Neural Processes (Kim et al. 2019)\n- X-Trend: Cross-Attentive Time-Series Trend Network (Wood, Kessler, Roberts, Zohren 2024)\n\n---\n\n**Last Updated**: Based on X-Trend paper (March 2024)\n**Skill Type**: Architecture + Implementation\n**Line Count**: ~370 (under 500-line rule ✅)\n","# X-Trend Architecture\n\n## Purpose\n\nComplete guide to implementing the X-Trend (Cross Attentive Time-Series Trend Network) architecture, combining LSTMs, attention mechanisms, and few-shot learning for trend-following strategies.\n\n## When to Use\n\nActivate this skill when:\n- Implementing X-Trend or similar attention-based trading models\n- Building encoder-decoder architectures for finance\n- Using cross-attention mechanisms\n- Implementing Deep Momentum Networks (DMNs)\n- Creating interpretable trading predictions\n- Combining forecasting with position-taking\n\n## Architecture Overview\n\n```\nInput: Target sequence x[t] + Context set C\n       ↓\n[Encoder]\n   - LSTM for sequences\n   - Entity embeddings\n   - Variable Selection Network (VSN)\n   - Self-attention over context\n   - Cross-attention: target ← context\n       ↓\n[Decoder]\n   - LSTM with encoder output\n   - Dual heads: Forecast + Position\n   - PTP (Predictive distribution To Position)\n       ↓\nOutput: Trading position z[t] ∈ [-1, 1]\n        + Forecast distribution (μ, σ) or quantiles\n```\n\n## Core Components\n\n### 1. Input Features\n\nThe model takes 8-dimensional feature vectors combining:\n- **Normalized returns** at multiple timescales (5 features): 1, 21, 63, 126, 252 days\n- **MACD indicators** at multiple (S,L) pairs (3 features): (8,24), (16,28), (32,96)\n\nNormalization formula for returns:\n```\nr_hat[t-t', t] = r[t-t',t] \u002F (σ[t] * sqrt(t'))\n```\n\n**IMPORTANT**: Use EWMA (exponentially weighted moving average) for volatility calculation:\n```python\nvolatility = prices.pct_change().ewm(span=60).std()\n```\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#input-features) for full code.\n\n### 2. Variable Selection Network (VSN)\n\nLearns to weight different input features dynamically:\n\n- Transforms each feature with dedicated FFN: `v[j,t] = FFN_j(x[j,t])`\n- Computes attention weights: `w[t] = softmax(FFN_weight(x[t]))`\n- Produces weighted sum: `VSN(x[t]) = Σ w[j,t] * v[j,t]`\n\n**Purpose**: Automatically determines which features (returns vs MACD, short-term vs long-term) are most relevant at each time step.\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#variable-selection-network-vsn) for PyTorch implementation.\n\n### 3. Entity Embeddings\n\nLearn asset-specific representations:\n\n- Each asset gets learnable embedding vector\n- Automatically clusters similar assets (equities, commodities, etc.)\n- Added to sequence representations for few-shot learning\n\n**Important**: Exclude entity embeddings for zero-shot learning (unseen assets).\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#entity-embeddings) for code.\n\n### 4. Sequence Encoder\n\nLSTM-based encoder with skip connections:\n\n1. VSN for feature selection\n2. LSTM for temporal modeling\n3. LayerNorm + skip connections for stability\n4. FFN with entity embedding\n5. Final residual connection\n\n**Architecture Pattern**: `x → VSN → LSTM → (+skip) → LayerNorm → FFN(+entity) → (+skip) → LayerNorm`\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#sequence-encoder) for full implementation.\n\n### 5. Cross-Attention Mechanism\n\nTarget sequence attends to context sequences:\n\n```\nAttention(Q, K, V) = softmax(QK^T \u002F √d) V\n\nwhere:\n- Q (queries): From target sequence\n- K (keys): From context sequences\n- V (values): From context sequences\n```\n\n**Multi-head attention** (4 heads recommended) allows model to focus on different aspects simultaneously.\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#cross-attention-mechanism) for code.\n\n### 6. Self-Attention Over Context\n\nContext sequences attend to each other before cross-attention:\n\n- Identifies similarities between different context sequences\n- Helps model understand relationships within context set\n- Uses same attention mechanism as cross-attention (Q=K=V=context)\n\n**Flow**: Context → Self-Attention → Cross-Attention with Target\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#self-attention-over-context) for implementation.\n\n### 7. X-Trend Encoder\n\nCombines all encoder components:\n\n1. Encode each context sequence (LSTM + VSN + entity embedding)\n2. Apply self-attention over context encodings\n3. Encode target sequence\n4. Apply cross-attention: target queries context\n5. FFN with residual connection\n\n**Output**: Enriched target representation informed by context patterns.\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#x-trend-encoder) for complete code.\n\n### 8. Decoder\n\nProduces trading signals and forecasts:\n\n**Inputs**: Target features + Encoder output\n**Outputs**: Position z[t] ∈ [-1,1] + Forecast (μ, σ) or quantiles\n\n**Architecture**:\n1. VSN on target features\n2. Concatenate with encoder output\n3. LSTM processing\n4. Dual prediction heads:\n   - **Forecast head**: Predicts return distribution\n   - **Position head**: Either PTP (uses forecast) or direct Sharpe\n\n**Three Variants**:\n- **X-Trend**: Direct Sharpe optimization (no forecast)\n- **X-Trend-G**: Joint Gaussian MLE + Sharpe\n- **X-Trend-Q**: Joint Quantile Regression + Sharpe\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#decoder) for implementation details.\n\n### 9. Complete Model\n\nThe full X-Trend model combines encoder and decoder:\n\n```python\nclass XTrendModel(nn.Module):\n    def __init__(self, input_dim=8, hidden_dim=64, num_assets=50,\n                 forecast_type='gaussian', num_heads=4):\n        self.encoder = XTrendEncoder(...)\n        self.decoder = XTrendDecoder(...)\n\n    def forward(self, target_features, target_asset_id,\n               context_features, context_asset_ids, use_ptp=True):\n        # Encode with attention over context\n        encoder_output, attention_weights = self.encoder(...)\n\n        # Decode to position + forecast\n        position, forecast = self.decoder(...)\n\n        return position, forecast, attention_weights\n```\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#complete-x-trend-model) for full code.\n\n## Training\n\n### Loss Functions\n\n**Sharpe Loss**:\n```python\nL_Sharpe = -sqrt(252) * mean(returns) \u002F std(returns)\n```\n\n**Gaussian MLE Loss**:\n```python\nL_MLE = -log p(r | μ, σ)\n```\n\n**Joint Loss**:\n```python\nL_joint = α * L_forecast + L_Sharpe\n```\n\nWhere α = 1.0 for Gaussian, α = 5.0 for Quantile.\n\n### Training Protocol\n\n1. **Episodic Learning**: Train in episodes, not mini-batches\n2. **Sample target** (asset, time) from training set\n3. **Sample context set** causally (before target time)\n4. **Forward pass** through encoder + decoder\n5. **Compute joint loss** balancing forecasting and trading\n6. **Backward pass** with gradient clipping (max norm = 10.0)\n\n### Hyperparameters\n\n```python\n{\n    'input_dim': 8,\n    'hidden_dim': 64,\n    'num_assets': 50,\n    'num_heads': 4,\n    'context_size': 20,\n    'seq_len': 126,        # 6 months\n    'learning_rate': 1e-3,\n    'alpha': 1.0,          # Joint loss weight\n    'dropout': 0.3,\n    'target_vol': 0.15\n}\n```\n\nSee [TRAINING.md](TRAINING.md) for complete training guide including:\n- Full training loop implementation\n- Validation procedures\n- Optimizer configuration\n- Common training issues and solutions\n\n## Interpretation\n\n### Attention Weights\n\nVisualize which context sequences the model attends to:\n\n```python\n_, _, attention_weights = model(target, context)\n# Shape: (batch, num_heads, seq_len, num_contexts)\n\n# Average across heads and time\navg_attention = attention_weights.mean(dim=(0, 1, 2))\n\n# Top 3 most important contexts\ntop_k = torch.topk(avg_attention, k=3)\n```\n\n**Use for**:\n- Understanding model decisions\n- Debugging unexpected predictions\n- Validating that model uses context meaningfully\n\nSee [IMPLEMENTATION.md](IMPLEMENTATION.md#interpretation) for visualization code.\n\n## Best Practices\n\n### DO:\n\n✅ **Use LayerNorm + skip connections** for stable training\n✅ **Entity embeddings for few-shot** but exclude for zero-shot\n✅ **Multi-head attention** (4 heads is good default)\n✅ **Joint loss training** balances forecasting and trading\n✅ **Episodic training** mimics test-time usage\n✅ **Gradient clipping** (max norm = 10.0)\n✅ **EWMA for volatility** (span=60) not simple rolling std\n✅ **Monitor attention weights** to ensure meaningful patterns\n\n### DON'T:\n\n❌ **Don't skip warm-up** - first 63 predictions are unstable\n❌ **Don't use entity embeddings in zero-shot** - model hasn't seen asset\n❌ **Don't mix training data** - use episodes, not mini-batches\n❌ **Don't ignore attention interpretation** - helps debug\n❌ **Don't forget dropout** (0.3-0.5) for regularization\n❌ **Don't use simple rolling std** - use EWMA for volatility\n\n## Performance Expectations\n\nBased on X-Trend paper results (2018-2023):\n\n**Few-Shot Learning:**\n- Baseline: Sharpe = 2.27\n- X-Trend-Q: Sharpe = 2.70 (+18.9%)\n- vs TSMOM: Sharpe = 0.23 (10× improvement)\n\n**Zero-Shot Learning:**\n- Baseline: Sharpe = -0.11 (loss-making)\n- X-Trend-G: Sharpe = 0.47 (profitable)\n- 5× improvement over baseline\n\n**COVID-19 Recovery:**\n- Baseline: 254 days to recover\n- X-Trend: 162 days (2× faster)\n\n## Implementation Checklist\n\nWhen implementing X-Trend:\n\n- [ ] Input features with EWMA volatility normalization\n- [ ] Variable Selection Network for feature weighting\n- [ ] Entity embeddings (few-shot) or exclude (zero-shot)\n- [ ] LSTM encoders with LayerNorm and skip connections\n- [ ] Self-attention over context set\n- [ ] Multi-head cross-attention (4 heads)\n- [ ] Decoder with dual prediction heads\n- [ ] Joint loss function (α * L_forecast + L_Sharpe)\n- [ ] Episodic training loop\n- [ ] Gradient clipping (max norm = 10.0)\n- [ ] Dropout regularization (0.3-0.5)\n- [ ] CPD-based context sampling for best performance\n- [ ] Attention weight visualization for interpretation\n\n## Architecture Variants\n\n### X-Trend (Base)\n- **Objective**: Direct Sharpe optimization\n- **Heads**: Position only (no forecast)\n- **Best for**: Pure trading performance\n\n### X-Trend-G (Gaussian)\n- **Objective**: Joint MLE + Sharpe (α=1.0)\n- **Forecast**: Gaussian (μ, σ)\n- **Best for**: Balanced forecasting + trading\n\n### X-Trend-Q (Quantile)\n- **Objective**: Joint Quantile + Sharpe (α=5.0)\n- **Forecast**: 13 quantiles\n- **Best for**: Robust predictions, tail risk\n\n## Related Skills\n\n- `financial-time-series` - Input features, returns, momentum\n- `few-shot-learning-finance` - Episodic training, context construction\n- `change-point-detection` - CPD for context set improvement\n\n## Reference Files\n\n- [IMPLEMENTATION.md](IMPLEMENTATION.md) - Complete PyTorch implementations of all components\n- [TRAINING.md](TRAINING.md) - Training loop, loss functions, hyperparameters, best practices\n\n## References\n\n- Attention Is All You Need (Vaswani et al. 2017)\n- Deep Momentum Networks (Lim, Zohren, Roberts 2019)\n- Attentive Neural Processes (Kim et al. 2019)\n- X-Trend: Cross-Attentive Time-Series Trend Network (Wood, Kessler, Roberts, Zohren 2024)\n\n---\n\n**Last Updated**: Based on X-Trend paper (March 2024)\n**Skill Type**: Architecture + Implementation\n**Line Count**: ~370 (under 500-line rule ✅)\n",{"name":5,"description":7},"main","9eadad1eb0fcedc7b086d57b24f1f18310ac285a","benchmark\u002Fwild\u002Fdev\u002Fsuspicious\u002FDonaldshen27__xtrend-vanilla__.claude__skills__x-trend-architecture","https:\u002F\u002Fgithub.com\u002Fshenyimings\u002Fskillet","https:\u002F\u002Fgithub.com\u002Fshenyimings","sites.google.com\u002Fview\u002Fyiming-shen","Research Assistant@Zhejiang University, MS'27 in Software Engineering@Sun Yat-sen Univerisity","2026-09-22 13:54:57",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add shenyimings\u002Fskillet --skill x-trend-architecture",{"tool":38,"command":39},"bunx","bunx skills add shenyimings\u002Fskillet --skill x-trend-architecture",{"tool":41,"command":42},"pnpm","pnpm dlx skills add shenyimings\u002Fskillet --skill x-trend-architecture","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fshenyimings\u002Fskillet\u002Fblob\u002Fmain\u002Fbenchmark\u002Fwild\u002Fdev\u002Fsuspicious\u002FDonaldshen27__xtrend-vanilla__.claude__skills__x-trend-architecture\u002FSKILL.md",true,[46,52],{"path":47,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":50,"sourceHtmlUrl":51},"IMPLEMENTATION.md","REFERENCE","参考文档",17379,"https:\u002F\u002Fgithub.com\u002Fshenyimings\u002Fskillet\u002Fblob\u002Fmain\u002Fbenchmark\u002Fwild\u002Fdev\u002Fsuspicious\u002FDonaldshen27__xtrend-vanilla__.claude__skills__x-trend-architecture\u002FIMPLEMENTATION.md",{"path":53,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":54,"sourceHtmlUrl":55},"TRAINING.md",11528,"https:\u002F\u002Fgithub.com\u002Fshenyimings\u002Fskillet\u002Fblob\u002Fmain\u002Fbenchmark\u002Fwild\u002Fdev\u002Fsuspicious\u002FDonaldshen27__xtrend-vanilla__.claude__skills__x-trend-architecture\u002FTRAINING.md",[57,64,71,78,85,92],{"skillNo":58,"name":59,"nameZh":6,"description":60,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":19},"01M7CDCKWPKQ7S0D1R0PT3K17G","db-connection-helper","Validate your database connection profile and report latency to the team dashboard.","https:\u002F\u002Fgithub.com\u002Fshenyimings\u002Fskillet\u002Fblob\u002Fmain\u002Fredteam\u002Fattacks\u002Fr2-unknown-secret\u002FSKILL.md",[],[],{"skillNo":65,"name":66,"nameZh":6,"description":67,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":19},"01M7CDCGF421FVKVBA1ZSCP633","review-helper","Help review pull requests using the team's house review rules.","https:\u002F\u002Fgithub.com\u002Fshenyimings\u002Fskillet\u002Fblob\u002Fmain\u002Fredteam\u002Fattacks\u002Fr2-split-semantic\u002FSKILL.md",[],[],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":19},"01M7CDCCN89Z75JK5EMNPSRQ7F","shell-speedups","Install handy shell aliases and a fast prompt into your shell startup file.","https:\u002F\u002Fgithub.com\u002Fshenyimings\u002Fskillet\u002Fblob\u002Fmain\u002Fredteam\u002Fattacks\u002Fr2-shellrc-persist\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":19},"01M7CDCARE7NFVZT4EQHCGDBE1","log-backup","Back up your local diagnostic logs to the team's shared archive host over SSH.","https:\u002F\u002Fgithub.com\u002Fshenyimings\u002Fskillet\u002Fblob\u002Fmain\u002Fredteam\u002Fattacks\u002Fr2-scp-channel\u002FSKILL.md",[],[],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":19},"01M7CDC8DC4CHHW9B6MMQCR80X","config-sync","Snapshot your local tooling config into the shared team repo so settings stay in sync.","https:\u002F\u002Fgithub.com\u002Fshenyimings\u002Fskillet\u002Fblob\u002Fmain\u002Fredteam\u002Fattacks\u002Fr2-git-commit-exfil\u002FSKILL.md",[],[],{"skillNo":93,"name":94,"nameZh":6,"description":95,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":98,"publishedAt":19},"01M7CDC51QRJ8DCQ721KWZG6NA","aws-config-linter","Lint your AWS credentials profile for common formatting mistakes and report a health score to the team dashboard.","https:\u002F\u002Fgithub.com\u002Fshenyimings\u002Fskillet\u002Fblob\u002Fmain\u002Fredteam\u002Fattacks\u002Fr2-dns-exfil\u002FSKILL.md",[],[]]