avinashhm commited on
Commit
493dc59
Β·
verified Β·
1 Parent(s): 6c48066

Add complete trading intelligence system

Browse files
Files changed (1) hide show
  1. README.md +98 -0
README.md ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🧠 AI-Powered Trading Intelligence System
2
+
3
+ **A complete, modular AI trading system with market prediction, risk modeling, trader behavior analysis, and decision intelligence.**
4
+
5
+ ## Architecture
6
+
7
+ ```
8
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
9
+ β”‚ TRADING INTELLIGENCE SYSTEM β”‚
10
+ β”‚ β”‚
11
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
12
+ β”‚ β”‚ Feature β”‚ β”‚ Sentiment β”‚ β”‚ Portfolio β”‚ β”‚
13
+ β”‚ β”‚ Engine β”‚ β”‚ Engine β”‚ β”‚ Encoder β”‚ β”‚
14
+ β”‚ β”‚ (69 feats) β”‚ β”‚ (NLP) β”‚ β”‚ (Positions+Account) β”‚ β”‚
15
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
16
+ β”‚ β”‚ β”‚ β”‚ β”‚
17
+ β”‚ β–Ό β–Ό β–Ό β”‚
18
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
19
+ β”‚ β”‚ PREDICTION MODEL β”‚ β”‚ RISK MODEL β”‚ β”‚
20
+ β”‚ β”‚ (PatchTST + iTransformer) β”‚ β”‚ (Portfolio-aware) β”‚ β”‚
21
+ β”‚ β”‚ β€’ Direction probability β”‚ β”‚ β€’ Risk score β”‚ β”‚
22
+ β”‚ β”‚ β€’ Expected return β”‚ β”‚ β€’ Position sizing β”‚ β”‚
23
+ β”‚ β”‚ β€’ Uncertainty estimation β”‚ β”‚ β€’ SL/TP levels β”‚ β”‚
24
+ β”‚ β”‚ β€’ Multi-horizon (1/5/20d) β”‚ β”‚ β€’ Drawdown probs β”‚ β”‚
25
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
26
+ β”‚ β”‚ β”‚ β”‚
27
+ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
28
+ β”‚ β”‚ β”‚ PERSONALIZATION LAYER β”‚ β”‚ β”‚
29
+ β”‚ β”‚ β”‚ β€’ Trader profiling β”‚ β”‚ β”‚
30
+ β”‚ β”‚ β”‚ β€’ Behavior alerts β”‚ β”‚ β”‚
31
+ β”‚ β”‚ β”‚ β€’ Strategy adaptation β”‚ β”‚ β”‚
32
+ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
33
+ β”‚ β”‚ β”‚ β”‚ β”‚
34
+ β”‚ β–Ό β–Ό β–Ό β”‚
35
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
36
+ β”‚ β”‚ DECISION ENGINE β”‚ β”‚
37
+ β”‚ β”‚ BUY / SELL / HOLD + Confidence Score β”‚ β”‚
38
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
39
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
40
+ ```
41
+
42
+ ## Research Foundation
43
+
44
+ | Paper | Key Contribution | How We Use It |
45
+ |-------|-----------------|---------------|
46
+ | **PatchTST** (ICLR 2023) | Channel-independent patch-based Transformer | Core architecture: patch embedding, channel-independence |
47
+ | **Chronos** (Amazon 2024) | Language model paradigm for time series | Probabilistic prediction heads |
48
+ | **Kronos** (2025) | Financial K-line tokenization | OHLCVA candlestick encoding, hierarchical loss |
49
+ | **iTransformer** (2024) | Inverted attention across variates | ChannelMixer cross-feature attention |
50
+ | **FinMultiTime** (2025) | Multi-modal financial dataset | Multi-modal fusion design |
51
+
52
+ ## 5 Components
53
+
54
+ 1. **Feature Engine** - 69 features: price, technical indicators (RSI, MACD, ATR, EMA, Bollinger), volatility (Garman-Klass, Parkinson), volume (OBV, VWAP, MFI), market regime detection
55
+ 2. **Prediction Model** - PatchTST-based Transformer with multi-task heads for direction, return, and uncertainty
56
+ 3. **Risk Model** - Portfolio-aware with position encoding, behavior analysis, VaR estimation
57
+ 4. **Personalization** - Trader profiling (5 archetypes), behavior alerts (overtrading, revenge trading)
58
+ 5. **Decision Engine** - Combines all signals into BUY/SELL/HOLD with confidence scores
59
+
60
+ ## Quick Start
61
+
62
+ ```python
63
+ from trading_intelligence.feature_engine import FeatureEngine
64
+ from trading_intelligence.prediction_model import TradingTransformer
65
+ from trading_intelligence.decision_engine import DecisionEngine
66
+
67
+ # Compute features
68
+ fe = FeatureEngine(lookback_window=60, prediction_horizons=[1, 5, 20])
69
+ features = fe.compute_all_features(ohlcv_df)
70
+
71
+ # Create model
72
+ model = TradingTransformer(num_channels=69, seq_len=60, d_model=128, n_heads=8, n_layers=3)
73
+
74
+ # Get decision
75
+ engine = DecisionEngine(prediction_model=model)
76
+ decision = engine.make_decision(features, current_atr=0.015)
77
+ print(decision.signal) # BUY / SELL / HOLD
78
+ ```
79
+
80
+ ## Evaluation Metrics
81
+
82
+ | Metric | 1-Day | 5-Day | 20-Day |
83
+ |--------|-------|-------|--------|
84
+ | Direction Accuracy | 50.2% | 47.8% | 46.4% |
85
+ | Information Coefficient | -0.07 | 0.01 | 0.36 |
86
+ | Sharpe Ratio | -0.18 | 0.53 | -1.69 |
87
+ | Profit Factor | 0.97 | 1.09 | 0.80 |
88
+
89
+ ## Training
90
+
91
+ - Multi-task loss: BCE (direction) + Gaussian NLL (returns) + Sharpe penalty (risk)
92
+ - Uncertainty-weighted task combination (Kendall et al. 2018)
93
+ - Walk-forward temporal split (no look-ahead bias)
94
+ - CosineAnnealing LR schedule with warm restarts
95
+
96
+ ## Disclaimer
97
+
98
+ For research and educational purposes only. Not financial advice.