Create README.mdREADME.md
Browse files- README.mdREADME.md +58 -0
README.mdREADME.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Time-Series-Crypto-Transformer
|
| 2 |
+
|
| 3 |
+
## Overview
|
| 4 |
+
`Time-Series-Crypto-Transformer` is a dedicated encoder-decoder Transformer model optimized for multivariate time series forecasting, specifically predicting the 7-day future closing price trend for major cryptocurrencies. The model incorporates both temporal features (price, volume, volatility) and static categorical features (Asset ID) to generate robust predictions.
|
| 5 |
+
|
| 6 |
+
This model is a custom implementation based on the architecture popularized by models like Informer and Autoformer, adapted for the financial domain's low-latency requirements.
|
| 7 |
+
|
| 8 |
+
## Model Architecture
|
| 9 |
+
The model uses a **Transformer Encoder-Decoder** structure.
|
| 10 |
+
* **Architecture:** Custom Transformer for Time Series (built using `HuggingFace-TS` principles).
|
| 11 |
+
* **Input Features (`input_size`=12):** [Close Price (Target), Open, High, Low, Volume, Log Returns, Moving Averages (2), Volatility (2), Time-of-Day, Day-of-Week].
|
| 12 |
+
* **Context Length (`context_length`):** 90 time steps (equivalent to 90 days of look-back).
|
| 13 |
+
* **Prediction Length (`prediction_length`):** 7 time steps (7-day forecast).
|
| 14 |
+
* **Dimensionality:** $d_{model}=256$, $n_{layers}=4$ (Encoder & Decoder), $n_{heads}=8$.
|
| 15 |
+
* **Static Features:** Asset ID (5 major cryptocurrencies: BTC, ETH, BNB, SOL, ADA).
|
| 16 |
+
|
| 17 |
+
## Intended Use
|
| 18 |
+
* **7-Day Price Trend Forecasting:** Predicting the direction and magnitude of the close price for the next week.
|
| 19 |
+
* **Algorithmic Trading Signals:** Integrating forecasts into a larger trading system for entry/exit points.
|
| 20 |
+
* **Risk Management:** Quantifying future price volatility to manage portfolio risk exposures.
|
| 21 |
+
* **Benchmarking:** Serving as a strong baseline model for comparison with other time-series models (e.g., ARIMA, LSTMs) in the crypto domain.
|
| 22 |
+
|
| 23 |
+
## Limitations
|
| 24 |
+
* **Black Swan Events:** The model relies on historical patterns and may fail to accurately predict sudden, high-impact events (e.g., major regulatory changes, exchange failures) that are not represented in the training data.
|
| 25 |
+
* **Data Stationarity:** Performance assumes a certain degree of non-stationarity in the time series, but extreme shifts in market structure may degrade accuracy.
|
| 26 |
+
* **Feature Dependence:** Accuracy is highly dependent on the quality and preprocessing of the 12 input features. Missing or noisy data will significantly impact results.
|
| 27 |
+
|
| 28 |
+
## Example Code (Python - Conceptual)
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
import pandas as pd
|
| 32 |
+
from transformers import AutoConfig, TimeSeriesModel
|
| 33 |
+
|
| 34 |
+
model_name = "Quant/Time-Series-Crypto-Transformer"
|
| 35 |
+
config = AutoConfig.from_pretrained(model_name)
|
| 36 |
+
model = TimeSeriesModel(config)
|
| 37 |
+
|
| 38 |
+
# --- Conceptual Data Preparation ---
|
| 39 |
+
# Your input data should be a 3D tensor: [Batch Size, Context Length, Input Size (Features)]
|
| 40 |
+
# Example:
|
| 41 |
+
# Historical data for 90 days (context_length) of 5 assets (batch size 5) with 12 features (input_size)
|
| 42 |
+
historical_data = torch.randn(5, config.context_length, config.input_size)
|
| 43 |
+
static_features = torch.tensor([0, 1, 2, 3, 4]) # Asset IDs
|
| 44 |
+
|
| 45 |
+
# --- Inference ---
|
| 46 |
+
# The forward pass returns the distribution or point estimate for the prediction_length (7 days)
|
| 47 |
+
outputs = model(
|
| 48 |
+
past_target=historical_data[..., 0].unsqueeze(-1), # Close price is the target
|
| 49 |
+
past_observed_mask=torch.ones_like(historical_data[..., 0].unsqueeze(-1)),
|
| 50 |
+
past_feat_dynamic_real=historical_data[..., 1:], # Other dynamic features
|
| 51 |
+
static_categorical_features=static_features
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
# Output is a distribution object (e.g., Gaussian) or a tensor of shape [Batch, Prediction Length, Output Size]
|
| 55 |
+
# For a point estimate:
|
| 56 |
+
forecast = outputs.prediction
|
| 57 |
+
print(f"Shape of 7-day forecast for 5 assets: {forecast.shape}")
|
| 58 |
+
# Expected output: torch.Size([5, 7, 1])
|