Loading repository data…
Loading repository data…
yannpointud / repository
End-to-end crypto price direction prediction framework built on the Mamba Selective State Space architecture (Python/PyTorch). Covers the full lifecycle: data preparation, Triple Barrier labeling, training, evaluation & live inference — all from a single config. Linear-time sequence processing as a Transformer alternative.
Deep learning cryptocurrency market direction prediction using Mamba (Selective State Space Model)
| TensorBoard | Features Explorer | Evaluation Report | Live Dashboard |
|---|---|---|---|
| Confusion Matrix | Margin Distribution |
|---|---|
| PNL Simulation | Accuracy Timeline |
|---|---|
Daikoku is an end-to-end framework for cryptocurrency price direction prediction. It covers the complete lifecycle: data preparation, model training, evaluation, and live inference — all from a single centralized configuration.
The core model is built on the Mamba Selective State Space architecture, achieving linear-time sequence processing as an alternative to Transformers.
Controlled by PREDICTION_TARGET in config.py:
| Mode | Classes | Description |
|---|---|---|
triple | 3 | Bull / Bear / Uncertain — Triple Barrier with ATR-based TP/SL |
bull | 2 | Binary: Bull vs. not-Bull |
bear | 2 | Binary: Bear vs. not-Bear |
uncertain | 2 | Binary: Uncertain vs. directional |
close1 | 2 | Binary: next candle closes higher or lower |
close2 | 2 | Binary: price higher or lower after 2 candles |
close3 | 2 | Binary: price higher or lower after 3 candles |
The default triple mode uses Triple Barrier labeling with ATR-based dynamic take-profit and stop-loss levels (configurable multipliers). Each prediction defines a fixed risk per trade (1R = distance to stop-loss), and performance is evaluated in R-multiples, enabling consistent allocation regardless of volatility. The bull, bear and uncertain modes are binary variants of the same Triple Barrier labeling.
The close* modes provide simpler directional targets without explicit TP/SL levels: the number indicates how many candles ahead (1, 2 or 3) to determine whether the price closes higher or lower.
mamba_cpu.py) with JIT-compiled selective scan when CUDA is not available╔════════════════════════════════════════════════════════════════════╗
║ 1. DATA PREPARATION ║
╠════════════════════════════════════════════════════════════════════╣
║ ║
║ CSV (OHLCV) ║
║ │ ║
║ ▼ ║
║ Load & Validate ║
║ │ ║
║ ├──────────────────────────────┐ ║
║ ▼ ▼ ║
║ Triple Barrier Labels Log Transform ║
║ (on RAW data) 12 global features ║
║ Bear=0 / Uncertain=1 / Bull=2 ║
║ ║
╠════════════════════════════════════════════════════════════════════╣
║ 2. WINDOWING ║
╠════════════════════════════════════════════════════════════════════╣
║ ║
║ Sliding Windows (WINDOW_SIZE candles) ║
║ │ ║
║ ▼ ║
║ Per-Window Features (zigzag + 5 structural) ║
║ │ ║
║ ▼ ║
║ Median/IQR Normalization (first 7 features) ║
║ │ ║
║ ▼ ║
║ 23 features per window ║
║ ║
╠════════════════════════════════════════════════════════════════════╣
║ 3. MULTI-TIMEFRAME (optional) ║
╠════════════════════════════════════════════════════════════════════╣
║ ║
║ ┌─────────────────────┐ ┌──────────────────────────┐ ║
║ │ Primary Branch │ │ Secondary Branch │ ║
║ │ 23 feat (with time)│ │ 19 feat (no time) │ ║
║ │ original TF (1h) │ │ aggregated TF (4h) │ ║
║ └────────┬────────────┘ └────────────┬─────────────┘ ║
║ │ │ ║
║ ▼ ▼ ║
╠════════════════════════════════════════════════════════════════════╣
║ 4. MODEL ║
╠════════════════════════════════════════════════════════════════════╣
║ ║
║ ┌─────────────────────┐ ┌──────────────────────────┐ ║
║ │ Input Projection │ │ Input Projection │ ║
║ │ Linear (+CNN opt.) │ │ Linear │ ║
║ └────────┬────────────┘ └────────────┬─────────────┘ ║
║ │ │ ║
║ ▼ ▼ ║
║ ┌─────────────────────┐ ┌──────────────────────────┐ ║
║ │ Mamba Encoder │ │ Mamba Encoder │ ║
║ │ N_LAYERS blocks │ │ MTF_N_LAYERS blocks │ ║
║ │ (causal SSM) │ │ (causal SSM) │ ║
║ └────────┬────────────┘ └────────────┬─────────────┘ ║
║ │ │ ║
║ └──────────────┬────────────────────┘ ║
║ │ ║
║ ▼ ║
╠════════════════════════════════════════════════════════════════════╣
║ 5. FUSION & HEAD ║
╠════════════════════════════════════════════════════════════════════╣
║ ║
║ Attention Mode ? ║
║ │ ║
║ ┌──────┬───────────┼───────────┐ ║
║ ▼ ▼ ▼ ▼ ║
║ off pre_gate post_gate aligned ║
║ │ │ │ │ ║
║ ▼ ▼ ▼ ▼ ║
║ Unified Unified Unified AlignedFusion ║
║ Head Head Head (gated residual) ║
║ 2 paths 4 paths 3 paths → MLP head ║
║ +SelfAttn +CrossAttn ║
║ │ │ │ │ ║
║ └──────┴───────────┴───────────┘ ║
║ │ ║
║ ▼ ║
║ Logits (batch, 3) ║
║ Bear / Uncertain / Bull ║
║ ║
╠════════════════════════════════════════════════════════════════════╣
║ 6. TRAINING ║
╠════════════════════════════════════════════════════════════════════╣
║ ║
║ Logits ──► UnifiedLoss (Focal + Class Weights) ◄── Labels ║
║ │ ║
║ ▼ ║
║ AdamW + LR Scheduler (cosine/wsd) ║
║ │ ║
║ ▼ ║
║ Checkpoint (best balanced_accuracy) ║
║ ║
╚════════════════════════════════════════════════════════════════════╝
# 1. Clone
git clone https://github.com/yannpointud/Daikoku.git
cd Daikoku
# 2. Install (CUDA 12.4 required)
pip install torch==2.4.1 --index-url https://download.pytorch.org/whl/cu124
pip install -r requirements.txt
pip install mamba-ssm==2.3.0 causal-conv1d==1.5.2
# 3. Download data
python modules/tools/download_candles.py --exchange binance --pair BTC/USDT --timeframe 1h --start 2020-01-01 --output data/BTC_1h_bin.csv
# 4. Train
python main.py
# 5. Evaluate
python evaluate.py
# 6. Monitor
tensorboard --logdir runs/
All parameters are configured in a single file: config.py. For detailed installation instr