deep-learning-trading
Skill16 starsChanged 8 months agoMITView on GitHub
name: deep-learning-trading description: Deep learning for trading — LSTM, transformers, sequence models for price prediction. Use when applying neural networks to financial data. Deep learning excels when: - Large dataset available (millions of samples — e.g., tick data, cross-sectional panels) - Complex non-linear patterns exist that tree models cannot capture - Sequential/temporal structure matters (order book dynamics, intraday patterns) - Multi-modal data needs integration (text + price + fundamentals) Deep learning is often NOT worth it when: - Small dataset…
In this repository83 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- live-trading-monitoringSkill
- monte-carlo-simulationSkill
- overfitting-preventionSkill
- research-notebooksSkill
- strategy-evaluationSkill
- walk-forward-optimizationSkill
- cross-chain-arbitrageSkill
- crypto-derivativesSkill
- defi-protocolsSkill
- mev-strategiesSkill
- on-chain-analyticsSkill
- stablecoin-analysisSkill
- tokenomicsSkill
- yield-farmingSkill
- alternative-dataSkill
- data-qualitySkill
- data-vendorsSkill
- feature-engineeringSkill
- sentiment-analysisSkill
- web-scraping-financeSkill
- binomial-treesSkill
- black-scholesSkill
- credit-derivativesSkill
- exotic-optionsSkill
- hedging-strategiesSkill
- interest-rate-derivativesSkill
- monte-carlo-pricingSkill
- structured-productsSkill
- vol-surfacesSkill
- vol-tradingSkill
- execution-algosSkill
- latency-optimizationSkill
- market-microstructure-theorySkill
- order-flow-analysisSkill
- performance-metricsSkill
- smart-order-routingSkill
- tick-data-processingSkill
- transaction-cost-analysisSkill
- central-bank-analysisSkill
- commodities-fundamentalsSkill
- economic-indicatorsSkill
- fx-fundamentalsSkill
- geopolitical-riskSkill
- yield-curve-analysisSkill
- alternative-allocationsSkill
- benchmark-trackingSkill
- black-littermanSkill
- factor-investingSkill
- markowitz-optimizationSkill
- portfolio-attributionSkill
- rebalancing-strategiesSkill
- risk-paritySkill
- alpha-researchSkill
- bayesian-methodsSkill
- factor-modelsSkill
- kalman-filtersSkill
- ml-for-financeSkill
- regime-detectionSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 79
Use returns not prices as inputs (stationarity)
- Distinctive: line 148
Use class weights inversely proportional to frequency
- Distinctive: line 192
Use for feature importance ranking and per-prediction explanations
- Distinctive: line 242
Before deploying a deep learning model for trading:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Deep Learning for Trading
name: deep-learning-trading description: Deep learning for trading — LSTM, transformers, sequence models for price prediction. Use when applying neural networks to financial data.
When to Activate
- User wants to apply neural networks to financial time series prediction
- Building sequence models (LSTM, Transformer) for return or volatility forecasting
- Exploring attention mechanisms for capturing temporal dependencies
- Implementing deep learning for limit order book or high-frequency data
- Evaluating transfer learning or pre-trained models for financial applications
First Questions
- What is the prediction task (regression on returns, classification of direction, volatility forecasting)?
- What data is available (price/volume only, fundamentals, alternative data, order book)?
- What is the data frequency and sequence length you intend to model?
- What computational resources are available (GPU, training time budget)?
- Is model interpretability required, or is black-box acceptable?
Core Concepts
When Deep Learning Makes Sense in Finance
Deep learning excels when:
- Large dataset available (millions of samples — e.g., tick data, cross-sectional panels)
- Complex non-linear patterns exist that tree models cannot capture
- Sequential/temporal structure matters (order book dynamics, intraday patterns)
- Multi-modal data needs integration (text + price + fundamentals)
Deep learning is often NOT worth it when:
- Small dataset (< 10K samples): high overfitting risk
- Features are well-engineered: tree models match or beat DL with less complexity
- Interpretability is critical: neural networks are hard to explain
- Low signal-to-noise ratio with simple features: DL amplifies noise
Key Architecture Tradeoffs
| Architecture | Strengths | Weaknesses | Best For |
| LSTM/GRU | Sequential dependencies, variable length | Slow training, gradient issues | Mid-frequency time series |
| TCN | Parallel training, fixed receptive field | Fixed context window | Regular-frequency data |
| Transformer | Long-range dependencies, attention | Data hungry, positional encoding needed | Large datasets, multi-asset |
| CNN-1D | Fast, local pattern detection | Fixed kernel size | Technical pattern recognition |
| Autoencoder | Unsupervised feature learning | No direct prediction | Feature extraction, anomaly detection |
Detailed Methodology
LSTM for Financial Time Series
Long Short-Term Memory networks maintain a cell state that can capture long-range dependencies:
Architecture for return prediction:
Input: (batch_size, sequence_length, n_features)
Layer 1: LSTM(hidden_size=64, return_sequences=True)
Layer 2: Dropout(0.3)
Layer 3: LSTM(hidden_size=32, return_sequences=False)
Layer 4: Dropout(0.3)
Layer 5: Dense(16, activation='relu')
Layer 6: Dense(1, activation='linear') [regression]
Dense(3, activation='softmax') [classification: down/flat/up]
Key hyperparameters:
sequence_length: 20-60 for daily data (lookback window)
hidden_size: 32-128 (larger = more capacity, more overfit risk)
num_layers: 1-3 (deeper rarely helps for finance)
dropout: 0.2-0.5 (critical for regularization)
learning_rate: 1e-4 to 1e-3 (use scheduler with decay)
batch_size: 32-256GRU (Gated Recurrent Unit): Simpler than LSTM (2 gates vs 3), fewer parameters. Often performs comparably. Preferred when data is limited.
Training tips for financial LSTM:
- Normalize inputs per feature (z-score using rolling statistics, not full-sample)
- Use returns not prices as inputs (stationarity)
- Apply gradient clipping (max_norm = 1.0)
- Early stopping on validation loss (patience = 10-20 epochs)
- Weight decay (L2 regularization) = 1e-5 to 1e-4
Temporal Convolutional Networks (TCN)
Dilated causal convolutions that can process sequences in parallel:
Architecture:
Input: (batch_size, n_features, sequence_length)
Residual Block 1: Conv1D(filters=64, kernel=3, dilation=1) + ReLU + Dropout
Residual Block 2: Conv1D(filters=64, kernel=3, dilation=2)
Residual Block 3: Conv1D(filters=64, kernel=3, dilation=4)
Residual Block 4: Conv1D(filters=64, kernel=3, dilation=8)
Global Average Pooling
Dense(1)
Receptive field = sum of dilations * (kernel_size - 1) + 1
With 4 blocks, dilation [1,2,4,8], kernel=3: receptive field = 31
Advantages over LSTM:
- Parallelizable (much faster training)
- Fixed receptive field (predictable memory)
- No vanishing gradient problem
- Often matches LSTM performance on financial dataTransformer Architecture for Finance
Self-attention mechanism captures relationships across any positions in the sequence:
Architecture:
Input Embedding: Linear(n_features, d_model=64)
Positional Encoding: Learnable or sinusoidal
Transformer Encoder (N=2-4 layers):
Multi-Head Attention(heads=4, d_model=64)
Feed-Forward(d_ff=256, dropout=0.1)
Layer Normalization
Output Head:
Global Average Pooling or [CLS] token
Dense(1)
Financial adaptations:
- Use CAUSAL attention mask (prevent looking into the future)
- Relative positional encoding (handles variable-length sequences better)
- Small model (d_model=32-128) — financial data cannot support GPT-scale models
- Cross-asset attention: attend across assets at each time stepAttention mechanism insight: Attention weights reveal which past time steps the model considers most important for prediction. This provides limited interpretability — inspect attention maps to verify the model is not attending to noise.
Training on Financial Data — Challenges
Non-stationarity mitigation:
1. Use returns, not prices (first-order stationarity)
2. Z-score features using ROLLING statistics (e.g., 252-day rolling mean/std)
3. Retrain periodically (quarterly or monthly) with expanding or rolling window
4. Use domain-specific normalization (e.g., normalize volume by ADV, volatility by long-run average)Handling class imbalance (for direction prediction):
- Up/down/flat classes are often imbalanced
- Use class weights inversely proportional to frequency
- Or define classes by threshold (e.g., |return| > 0.5% for up/down)
- Focal loss can help with hard-to-classify samples
Data augmentation (limited options in finance):
- Time series bootstrap (block bootstrap preserving autocorrelation)
- Noise injection (add small Gaussian noise to features)
- Synthetic data from fitted models (e.g., GAN-generated paths)
- Window slicing (different starting points for sequences)
- Caution: augmentation can introduce unrealistic patterns
Transfer Learning in Finance
Pre-train on a large related dataset, fine-tune on the target:
Approaches:
1. Cross-asset transfer: Pre-train on liquid assets (SPY, QQQ), fine-tune on illiquid
2. Cross-market transfer: Pre-train on US equities, fine-tune on EM equities
3. Cross-frequency: Pre-train on high-frequency, fine-tune on daily
4. Foundation models: Pre-train on broad market data, fine-tune for specific tasks
Practical considerations:
- Freeze early layers (general feature extraction), fine-tune later layers
- Use smaller learning rate for fine-tuning (1/10 of pre-training LR)
- Limited evidence of large transfer benefits in finance (unlike NLP/vision)
- Most useful when target dataset is very smallModel Interpretability
Attention analysis:
- Plot attention weights across time steps
- Identify which past periods the model focuses on
- Compare attention patterns across different market regimes
Gradient-based methods:
- Integrated Gradients: Attribute predictions to input features
- Saliency maps: Partial derivatives of output w.r.t. inputs
- SmoothGrad: Average gradients over noisy input copies
SHAP for neural networks:
- DeepSHAP: Combines DeepLIFT with Shapley values
- KernelSHAP: Model-agnostic but slow
- Use for feature importance ranking and per-prediction explanations
Templates / Examples
Deep Learning Model Evaluation Report
Model: 2-Layer LSTM (64/32 hidden units)
Task: Next-day return sign prediction
Universe: S&P 500 constituents
Features: 35 (technical + fundamental + sentiment)
Sequence Length: 40 trading days
Training: 2012-2019 | Validation: 2020-2021 | Test: 2022-2024
GPU: NVIDIA A100 | Training time: 4.5 hours
--- Test Performance ---
AUC: 0.534
Directional Acc: 52.8%
IC (rank corr): 0.028
Top-Bottom Decile: 4.2% annualized (gross)
--- Baselines ---
LightGBM: AUC 0.531, IC 0.025
Linear Regression: AUC 0.519, IC 0.018
Buy-and-Hold: N/A (benchmark)
--- Resource vs Performance ---
LSTM training: 4.5 hours, IC = 0.028
LightGBM training: 12 minutes, IC = 0.025
Marginal IC gain: +0.003 for 22x compute cost
Verdict: Marginal improvement over tree models. DL justified only
if compute is cheap and the pipeline supports neural network ops.Architecture Selection Guide
Data Size | Frequency | Features | Recommended Architecture
< 5K samples | Daily | < 20 | DO NOT use deep learning. Use trees.
5K-50K | Daily | 20-100 | LSTM or TCN (small, heavy regularization)
50K-500K | Daily/Hour | 50-200 | TCN or Transformer (medium)
> 500K | Intraday | 100+ | Transformer (can scale)
Order book data | Tick | LOB | TCN or CNN-1D (fast inference needed)
Multi-asset | Any | Per-asset | Transformer with cross-asset attentionQuality Gate
Before deploying a deep learning model for trading:
- Baseline comparison: DL outperforms tree models and linear models on OOS data
- Purged walk-forward validation used (no data leakage)
- Training uses only causal features and labels (no look-ahead)
- Model is not overfit: training and validation loss curves examined
- Regularization applied (dropout, weight decay, early stopping)
- Feature normalization uses rolling statistics, not full-sample
- Inference latency is acceptable for production trading frequency
- Model retraining schedule defined (monthly/quarterly)
- Interpretability analysis performed (attention maps, SHAP, gradients)
- Compute cost justified by performance improvement over simpler models
- Monitoring for model decay is in place (rolling IC, performance dashboards)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

