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
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: mit
|
| 5 |
+
library_name: pytorch
|
| 6 |
+
tags:
|
| 7 |
+
- time-series
|
| 8 |
+
- financial-forecasting
|
| 9 |
+
- ohlcv
|
| 10 |
+
- conformer
|
| 11 |
+
- transformer
|
| 12 |
+
- convolution
|
| 13 |
+
- market-prediction
|
| 14 |
+
- finance
|
| 15 |
+
datasets:
|
| 16 |
+
- mito0o852/OHLCV-1m
|
| 17 |
+
pipeline_tag: time-series-forecasting
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# ⚡ ULTRON // Advanced OHLCV Convolutional Transformer
|
| 21 |
+
|
| 22 |
+
Autonomous high-performance deep learning pipeline designed to train on the **90 GB `mito0o852/OHLCV-1m`** minute-level stock market dataset on Google Colab GPU instances without hitting storage quotas, RAM OOM, or session timeout limits.
|
| 23 |
+
|
| 24 |
+
[](https://colab.research.google.com/github/Ultron09/ohlcv-transformer/blob/main/OHLCV_Transformer_Colab.ipynb)
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## 🏛️ Architectural Overview
|
| 29 |
+
|
| 30 |
+
```
|
| 31 |
+
Raw Minute Candlesticks (90GB Parquet Shards on HF Hub)
|
| 32 |
+
│
|
| 33 |
+
▼
|
| 34 |
+
┌─────────────────────────────────────────────────────────────┐
|
| 35 |
+
│ 1. Zero-Disk-Overflow Streaming Shard Manager │
|
| 36 |
+
│ • Streams 1 monthly shard (~300MB) at a time │
|
| 37 |
+
│ • In-memory feature computation + overlapping windowing │
|
| 38 |
+
│ • Immediate shard disk cache eviction (O(1) disk footprint)│
|
| 39 |
+
└─────────────────────────────────────────────────────────────┘
|
| 40 |
+
│
|
| 41 |
+
▼
|
| 42 |
+
┌─────────────────────────────────────────────────────────────┐
|
| 43 |
+
│ 2. Stationary Feature Extraction Engine │
|
| 44 |
+
│ • Log Returns: ln(C_t / C_{t-1}) │
|
| 45 |
+
│ • Relative Bar Range: (H_t - L_t) / C_t │
|
| 46 |
+
│ • Normalized Candle Body: (C_t - O_t) / (Range + eps) │
|
| 47 |
+
│ • Upper & Lower Wick Absorption Dynamics │
|
| 48 |
+
│ • Parkinson Continuous Micro-Volatility Estimator │
|
| 49 |
+
│ • Rolling Normalized Volume Z-Score │
|
| 50 |
+
└─────────────────────────────────────────────────────────────┘
|
| 51 |
+
│
|
| 52 |
+
▼
|
| 53 |
+
┌─────────────────────────────────────────────────────────────┐
|
| 54 |
+
│ 3. Reversible Instance Normalization (RevIN) │
|
| 55 |
+
│ • Dynamically strips non-stationary market regime drift │
|
| 56 |
+
└─────────────────────────────────────────────────────────────┘
|
| 57 |
+
│
|
| 58 |
+
▼
|
| 59 |
+
┌─────────────────────────────────────────────────────────────┐
|
| 60 |
+
│ 4. Multi-Scale Overlapping 1D Convolutional Tokenizer │
|
| 61 |
+
│ • Inception kernels: [3m, 7m, 15m, 31m] │
|
| 62 |
+
│ • Stride S=4 creates continuous overlapping patches │
|
| 63 |
+
│ • Compresses 512-min sequence to 128 tokens (16x speedup)│
|
| 64 |
+
└─────────────────────────────────────────────────────────────┘
|
| 65 |
+
│
|
| 66 |
+
▼
|
| 67 |
+
┌─────────────────────────────────────────────────────────────┐
|
| 68 |
+
│ 5. Conformer Backbone (FlashAttention + Depthwise Conv) │
|
| 69 |
+
│ • Rotary Position Embeddings (RoPE) │
|
| 70 |
+
│ • Causal Scaled Dot-Product Self-Attention (FlashAttn-2) │
|
| 71 |
+
│ • Depthwise Separable 1D Conv (local momentum dynamics) │
|
| 72 |
+
│ • Pre-LN SwiGLU Feed-Forward Networks │
|
| 73 |
+
└─────────────────────────────────────────────────────────────┘
|
| 74 |
+
│
|
| 75 |
+
▼
|
| 76 |
+
┌─────────────────────────────────────────────────────────────┐
|
| 77 |
+
│ 6. Multi-Horizon Dual Forecasting Head │
|
| 78 |
+
│ • Expected Return Vector: [1m, 3m, 5m, 10m, 15m] │
|
| 79 |
+
│ • Directional Probability: P(Return > 0) │
|
| 80 |
+
│ �� Loss: Huber Loss + λ * Directional BCE │
|
| 81 |
+
└─────────────────────────────────────────────────────────────┘
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+

|
| 85 |
+
|
| 86 |
+
---
|
| 87 |
+
|
| 88 |
+
## 📊 Empirical Training Telemetry (Tesla T4 GPU)
|
| 89 |
+
|
| 90 |
+
Trained across all 12 monthly shards of the 2024 trading year (**26,000,000+ raw minute bars**, ~151,000 overlapping sliding windows across top US liquid equities).
|
| 91 |
+
|
| 92 |
+

|
| 93 |
+
|
| 94 |
+
### 📈 Multi-Horizon Forecast Curves & Confidence
|
| 95 |
+
|
| 96 |
+
The model forecasts both continuous return curves and upward movement probabilities across multiple discrete temporal horizons (1m, 3m, 5m, 10m, and 15m):
|
| 97 |
+
|
| 98 |
+

|
| 99 |
+
|
| 100 |
+
| Horizon | Sample A (Tech Breakout) | Sample B (Mean Reversion) | Sample C (Momentum Spike) | Signal Confidence |
|
| 101 |
+
| :--- | :--- | :--- | :--- | :--- |
|
| 102 |
+
| **1-Minute** | `+0.5032%` | `+0.2899%` | `+1.0101%` | `50.9%` P(Up) |
|
| 103 |
+
| **3-Minute** | `+0.8202%` | `+0.0537%` | `+0.6119%` | `52.5%` P(Up) |
|
| 104 |
+
| **5-Minute** | `+0.5146%` | `-1.0078%` | `-0.8469%` | `49.3%` P(Up) |
|
| 105 |
+
| **10-Minute**| `-1.2062%` | `-0.5882%` | `+0.1730%` | `48.7%` P(Up) |
|
| 106 |
+
| **15-Minute**| `-0.3365%` | `+0.4570%` | `-0.3456%` | `49.0%` P(Up) |
|
| 107 |
+
|
| 108 |
+
---
|
| 109 |
+
|
| 110 |
+
## 📂 Repository Structure
|
| 111 |
+
|
| 112 |
+
- `config.py`: Central hyperparameter matrix (date ranges, tickers, model dimensions, training parameters).
|
| 113 |
+
- `features.py`: Stationary feature engineering engine (candle morphology, Parkinson volatility, returns).
|
| 114 |
+
- `dataset.py`: Streaming Shard Manager that downloads, windows, and cleans up Parquet files on-the-fly.
|
| 115 |
+
- `model.py`: Complete PyTorch Conformer model with overlapping 1D convolutions and RoPE.
|
| 116 |
+
- `loss.py`: Multi-task financial loss function (Huber + BCE + Directional Accuracy tracking).
|
| 117 |
+
- `train.py`: Autonomous Colab training loop with AMP FP16, gradient accumulation, and auto-resume.
|
| 118 |
+
- `colab_runner.sh`: Turnkey bash script for headless Colab CLI execution.
|
| 119 |
+
- `OHLCV_Transformer_Colab.ipynb`: Jupyter notebook ready to open in Google Colab.
|
| 120 |
+
|
| 121 |
+
---
|
| 122 |
+
|
| 123 |
+
## 🚀 How to Execute on Google Colab
|
| 124 |
+
|
| 125 |
+
### Method 1: Turnkey Colab CLI / Terminal Execution
|
| 126 |
+
|
| 127 |
+
In your Google Colab bash terminal (or via Colab CLI / SSH session):
|
| 128 |
+
|
| 129 |
+
```bash
|
| 130 |
+
# 1. Clone or copy this repository into Colab
|
| 131 |
+
git clone <your-repo> /content/ohlcv-transformer
|
| 132 |
+
cd /content/ohlcv-transformer
|
| 133 |
+
|
| 134 |
+
# 2. Execute the autonomous runner script
|
| 135 |
+
bash colab_runner.sh
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
Or run directly with customized parameters:
|
| 139 |
+
```bash
|
| 140 |
+
python3 train.py \
|
| 141 |
+
--start_year 2021 \
|
| 142 |
+
--end_year 2025 \
|
| 143 |
+
--batch_size 64 \
|
| 144 |
+
--grad_accum 4 \
|
| 145 |
+
--lr 0.0003 \
|
| 146 |
+
--epochs 5
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
### Method 2: Google Colab Web Interface
|
| 150 |
+
|
| 151 |
+
1. Upload `OHLCV_Transformer_Colab.ipynb` to Google Colab.
|
| 152 |
+
2. Select **Runtime** > **Change runtime type** > **T4 GPU** (or A100/L4).
|
| 153 |
+
3. Click **Runtime** > **Run all**.
|
| 154 |
+
|
| 155 |
+
---
|
| 156 |
+
|
| 157 |
+
## 🛡️ Colab Quota & Limit Protection Protocol
|
| 158 |
+
|
| 159 |
+
| Quota / Constraint | Default Risk | ULTRON Architectural Mitigation |
|
| 160 |
+
| :--- | :--- | :--- |
|
| 161 |
+
| **Disk Space (~78 GB)** | 90 GB dataset causes immediate `Disk Full` crash | Shard Manager downloads 1 month (~300MB), processes, and immediately deletes it ($O(1)$ disk usage < 1 GB). |
|
| 162 |
+
| **System RAM (12.7 GB)** | DataFrames cause `Out of Memory` killer | Filters top liquid tickers and runs garbage collection (`gc.collect()`) after every shard. |
|
| 163 |
+
| **GPU VRAM (15 GB)** | Transformer self-attention $O(T^2)$ VRAM spike | Overlapping 1D conv tokenizes $512 \to 128$ tokens; Mixed Precision (FP16) + Gradient Accumulation (`effective_batch_size = 256`). |
|
| 164 |
+
| **Runtime Disconnects** | 12-hour timeout loses all trained weights | Checkpoints sync automatically to Google Drive (`/content/drive/MyDrive/ohlcv_checkpoints/`) every 200 steps and auto-resume seamlessly. |
|