Enhance model card with paper details, demo, usage, and model zoo
#1
by
nielsr
HF Staff
- opened
README.md
CHANGED
|
@@ -5,8 +5,141 @@ tags:
|
|
| 5 |
- Finance
|
| 6 |
- Candlestick
|
| 7 |
- K-line
|
|
|
|
| 8 |
---
|
|
|
|
| 9 |
# Model Card for Kronos
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
- Finance
|
| 6 |
- Candlestick
|
| 7 |
- K-line
|
| 8 |
+
library_name: torch
|
| 9 |
---
|
| 10 |
+
|
| 11 |
# Model Card for Kronos
|
| 12 |
|
| 13 |
+
**Kronos** is a unified, scalable pre-training framework tailored to financial candlestick (K-line) modeling. It introduces a specialized tokenizer that discretizes continuous market information into token sequences, preserving both price dynamics and trade activity patterns. Pre-trained on a massive, multi-market corpus of over 12 billion K-line records from 45 global exchanges, Kronos learns nuanced temporal and cross-asset representations. Kronos excels in a zero-shot setting across a diverse set of financial tasks, boosting price series forecasting RankIC by 93%, achieving a 9% lower MAE in volatility forecasting, and a 22% improvement in generative fidelity for synthetic K-line sequences.
|
| 14 |
+
|
| 15 |
+
This model was presented in the paper: [Kronos: A Foundation Model for the Language of Financial Markets](https://huggingface.co/papers/2508.02739).
|
| 16 |
+
|
| 17 |
+
For full details on how to use this model, please visit our [GitHub page](https://github.com/shiyu-coder/Kronos).
|
| 18 |
+
|
| 19 |
+
## β¨ Live Demo
|
| 20 |
+
We have set up a live demo to visualize Kronos's forecasting results. The webpage showcases a forecast for the **BTC/USDT** trading pair over the next 24 hours.
|
| 21 |
+
|
| 22 |
+
**π [Access the Live Demo Here](https://shiyu-coder.github.io/Kronos-demo/)**
|
| 23 |
+
|
| 24 |
+
## π¦ Model Zoo
|
| 25 |
+
We release a family of pre-trained models with varying capacities to suit different computational and application needs. All models are readily accessible from the Hugging Face Hub.
|
| 26 |
+
|
| 27 |
+
| Model | Tokenizer | Context length | Param | Open-source |
|
| 28 |
+
|--------------|---------------------------------------------------------------------------------| -------------- | ------ |---------------------------------------------------------------------------|
|
| 29 |
+
| Kronos-mini | [Kronos-Tokenizer-2k](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-2k) | 2048 | 4.1M | β
[NeoQuasar/Kronos-mini](https://huggingface.co/NeoQuasar/Kronos-mini) |
|
| 30 |
+
| Kronos-small | [Kronos-Tokenizer-base](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base) | 512 | 24.7M | β
[NeoQuasar/Kronos-small](https://huggingface.co/NeoQuasar/Kronos-small) |
|
| 31 |
+
| Kronos-base | [Kronos-Tokenizer-base](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base) | 512 | 102.3M | β
[NeoQuasar/Kronos-base](https://huggingface.co/NeoQuasar/Kronos-base) |
|
| 32 |
+
| Kronos-large | [Kronos-Tokenizer-base](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base) | 512 | 499.2M | β |
|
| 33 |
+
|
| 34 |
+
## π Getting Started
|
| 35 |
+
|
| 36 |
+
### Installation
|
| 37 |
+
|
| 38 |
+
1. Install Python 3.10+, and then install the dependencies:
|
| 39 |
+
|
| 40 |
+
```shell
|
| 41 |
+
pip install -r requirements.txt
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
### π Making Forecasts
|
| 45 |
+
|
| 46 |
+
Forecasting with Kronos is straightforward using the `KronosPredictor` class. It handles data preprocessing, normalization, prediction, and inverse normalization, allowing you to get from raw data to forecasts in just a few lines of code.
|
| 47 |
+
|
| 48 |
+
**Important Note**: The `max_context` for `Kronos-small` and `Kronos-base` is **512**. This is the maximum sequence length the model can process. For optimal performance, it is recommended that your input data length (i.e., `lookback`) does not exceed this limit. The `KronosPredictor` will automatically handle truncation for longer contexts.
|
| 49 |
+
|
| 50 |
+
Here is a step-by-step guide to making your first forecast.
|
| 51 |
+
|
| 52 |
+
#### 1. Load the Tokenizer and Model
|
| 53 |
+
|
| 54 |
+
First, load a pre-trained Kronos model and its corresponding tokenizer from the Hugging Face Hub.
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
from model import Kronos, KronosTokenizer, KronosPredictor
|
| 58 |
+
|
| 59 |
+
# Load from Hugging Face Hub
|
| 60 |
+
tokenizer = KronosTokenizer.from_pretrained("NeoQuasar/Kronos-Tokenizer-base")
|
| 61 |
+
model = Kronos.from_pretrained("NeoQuasar/Kronos-small")
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
#### 2. Instantiate the Predictor
|
| 65 |
+
|
| 66 |
+
Create an instance of `KronosPredictor`, passing the model, tokenizer, and desired device.
|
| 67 |
+
|
| 68 |
+
```python
|
| 69 |
+
# Initialize the predictor
|
| 70 |
+
predictor = KronosPredictor(model, tokenizer, device="cuda:0", max_context=512)
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
#### 3. Prepare Input Data
|
| 74 |
+
|
| 75 |
+
The `predict` method requires three main inputs:
|
| 76 |
+
- `df`: A pandas DataFrame containing the historical K-line data. It must include columns `['open', 'high', 'low', 'close']`. `volume` and `amount` are optional.
|
| 77 |
+
- `x_timestamp`: A pandas Series of timestamps corresponding to the historical data in `df`.
|
| 78 |
+
- `y_timestamp`: A pandas Series of timestamps for the future periods you want to predict.
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
import pandas as pd
|
| 82 |
+
|
| 83 |
+
# Load your data
|
| 84 |
+
df = pd.read_csv("./data/XSHG_5min_600977.csv")
|
| 85 |
+
df['timestamps'] = pd.to_datetime(df['timestamps'])
|
| 86 |
+
|
| 87 |
+
# Define context window and prediction length
|
| 88 |
+
lookback = 400
|
| 89 |
+
pred_len = 120
|
| 90 |
+
|
| 91 |
+
# Prepare inputs for the predictor
|
| 92 |
+
x_df = df.loc[:lookback-1, ['open', 'high', 'low', 'close', 'volume', 'amount']]
|
| 93 |
+
x_timestamp = df.loc[:lookback-1, 'timestamps']
|
| 94 |
+
y_timestamp = df.loc[lookback:lookback+pred_len-1, 'timestamps']
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
#### 4. Generate Forecasts
|
| 98 |
+
|
| 99 |
+
Call the `predict` method to generate forecasts. You can control the sampling process with parameters like `T`, `top_p`, and `sample_count` for probabilistic forecasting.
|
| 100 |
+
|
| 101 |
+
```python
|
| 102 |
+
# Generate predictions
|
| 103 |
+
pred_df = predictor.predict(
|
| 104 |
+
df=x_df,
|
| 105 |
+
x_timestamp=x_timestamp,
|
| 106 |
+
y_timestamp=y_timestamp,
|
| 107 |
+
pred_len=pred_len,
|
| 108 |
+
T=1.0, # Temperature for sampling
|
| 109 |
+
top_p=0.9, # Nucleus sampling probability
|
| 110 |
+
sample_count=1 # Number of forecast paths to generate and average
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
print("Forecasted Data Head:")
|
| 114 |
+
print(pred_df.head())
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
The `predict` method returns a pandas DataFrame containing the forecasted values for `open`, `high`, `low`, `close`, `volume`, and `amount`, indexed by the `y_timestamp` you provided.
|
| 118 |
+
|
| 119 |
+
#### 5. Example and Visualization
|
| 120 |
+
|
| 121 |
+
For a complete, runnable script that includes data loading, prediction, and plotting, please see [`examples/prediction_example.py`](https://github.com/shiyu-coder/Kronos/blob/main/examples/prediction_example.py).
|
| 122 |
+
|
| 123 |
+
Running this script will generate a plot comparing the ground truth data against the model's forecast, similar to the one shown below:
|
| 124 |
+
|
| 125 |
+
<p align="center">
|
| 126 |
+
<img src="https://huggingface.co/NeoQuasar/Kronos-mini/resolve/main/figures/prediction_example.png" alt="Forecast Example" align="center" width="600px" />
|
| 127 |
+
</p>
|
| 128 |
+
|
| 129 |
+
Additionally, we also provide a script that makes predictions without Volume and Amount data, which can be found in [`examples/prediction_wo_vol_example.py`](https://github.com/shiyu-coder/Kronos/blob/main/examples/prediction_wo_vol_example.py).
|
| 130 |
+
|
| 131 |
+
## π Citation
|
| 132 |
+
|
| 133 |
+
If you use Kronos in your research, we would appreciate a citation to our [paper](https://arxiv.org/abs/2508.02739):
|
| 134 |
|
| 135 |
+
```
|
| 136 |
+
@misc{shi2025kronos,
|
| 137 |
+
title={Kronos: A Foundation Model for the Language of Financial Markets},
|
| 138 |
+
author={Yu Shi and Zongliang Fu and Shuo Chen and Bohan Zhao and Wei Xu and Changshui Zhang and Jian Li},
|
| 139 |
+
year={2025},
|
| 140 |
+
eprint={2508.02739},
|
| 141 |
+
archivePrefix={arXiv},
|
| 142 |
+
primaryClass={q-fin.ST},
|
| 143 |
+
url={https://arxiv.org/abs/2508.02739},
|
| 144 |
+
}
|
| 145 |
+
```
|