Improve model card: add detailed overview, usage, model zoo, and correct license

#1
by nielsr HF Staff - opened
Files changed (1) hide show
  1. README.md +149 -3
README.md CHANGED
@@ -1,12 +1,158 @@
1
  ---
2
- license: apache-2.0
3
  pipeline_tag: time-series-forecasting
4
  tags:
5
  - Finance
6
  - Candlestick
7
  - K-line
 
8
  ---
9
- # Model Card for Kronos
10
 
 
11
 
12
- For details on how to use this model, please visit our [GitHub page](https://github.com/shiyu-coder/Kronos).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: mit
3
  pipeline_tag: time-series-forecasting
4
  tags:
5
  - Finance
6
  - Candlestick
7
  - K-line
8
+ - time-series
9
  ---
 
10
 
11
+ # Kronos: A Foundation Model for the Language of Financial Markets
12
 
13
+ **Kronos** is a unified, scalable pre-training framework tailored to financial K-line (candlestick) modeling. It introduces a specialized tokenizer that discretizes continuous market information into token sequences, preserving both price dynamics and trade activity patterns. Kronos is pre-trained using an autoregressive objective on a massive, multi-market corpus of over 12 billion K-line records from 45 global exchanges, enabling it to learn nuanced temporal and cross-asset representations.
14
+
15
+ Kronos excels in a zero-shot setting across a diverse set of financial tasks. On benchmark datasets, Kronos boosts price series forecasting RankIC by 93% over the leading Time Series Foundation Model (TSFM) and 87% over the best non-pre-trained baseline. It also achieves a 9% lower MAE in volatility forecasting and a 22% improvement in generative fidelity for synthetic K-line sequences. These results establish Kronos as a robust, versatile foundation model for end-to-end financial time series analysis.
16
+
17
+ For more details, refer to our paper: [Kronos: A Foundation Model for the Language of Financial Markets](https://huggingface.co/papers/2508.02739).
18
+
19
+ Live Demo: [Kronos Live Demo](https://shiyu-coder.github.io/Kronos-demo/)
20
+ Code: [GitHub Repository](https://github.com/shiyu-coder/Kronos)
21
+
22
+ <p align="center">
23
+ <img src="https://github.com/shiyu-coder/Kronos/raw/main/figures/overview.png" alt="Kronos Overview" align="center" width="700px" />
24
+ </p>
25
+
26
+ ## Introduction
27
+
28
+ Kronos is the **first open-source foundation model** for financial candlesticks (K-lines), trained on data from over **45 global exchanges**.
29
+
30
+ Kronos is a family of decoder-only foundation models, pre-trained specifically for the "language" of financial markets—K-line sequences. Unlike general-purpose TSFMs, Kronos is designed to handle the unique, high-noise characteristics of financial data. It leverages a novel two-stage framework:
31
+ 1. A specialized tokenizer first quantizes continuous, multi-dimensional K-line data (OHLCV) into **hierarchical discrete tokens**.
32
+ 2. A large, autoregressive Transformer is then pre-trained on these tokens, enabling it to serve as a unified model for diverse quantitative tasks.
33
+
34
+ ## Model Zoo
35
+ 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.
36
+
37
+ | Model | Tokenizer | Context length | Param | Open-source |
38
+ |--------------|---------------------------------------------------------------------------------| -------------- | ------ |---------------------------------------------------------------------------|
39
+ | Kronos-mini | [Kronos-Tokenizer-2k](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-2k) | 2048 | 4.1M | ✅ [NeoQuasar/Kronos-mini](https://huggingface.co/NeoQuasar/Kronos-mini) |
40
+ | Kronos-small | [Kronos-Tokenizer-base](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base) | 512 | 24.7M | ✅ [NeoQuasar/Kronos-small](https://huggingface.co/NeoQuasar/Kronos-small) |
41
+ | Kronos-base | [Kronos-Tokenizer-base](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base) | 512 | 102.3M | ✅ [NeoQuasar/Kronos-base](https://huggingface.co/NeoQuasar/Kronos-base) |\
42
+ | Kronos-large | [Kronos-Tokenizer-base](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base) | 512 | 499.2M | ❌ |
43
+
44
+ ## Getting Started
45
+
46
+ ### Installation
47
+
48
+ 1. Install Python 3.10+, and then install the dependencies:
49
+
50
+ ```shell
51
+ pip install -r requirements.txt
52
+ ```
53
+
54
+ ### Making Forecasts
55
+
56
+ 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.
57
+
58
+ **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.
59
+
60
+ Here is a step-by-step guide to making your first forecast.
61
+
62
+ #### 1. Load the Tokenizer and Model
63
+
64
+ First, load a pre-trained Kronos model and its corresponding tokenizer from the Hugging Face Hub.
65
+
66
+ ```python
67
+ from model import Kronos, KronosTokenizer, KronosPredictor
68
+
69
+ # Load from Hugging Face Hub
70
+ tokenizer = KronosTokenizer.from_pretrained("NeoQuasar/Kronos-Tokenizer-base")
71
+ model = Kronos.from_pretrained("NeoQuasar/Kronos-small")
72
+ ```
73
+
74
+ #### 2. Instantiate the Predictor
75
+
76
+ Create an instance of `KronosPredictor`, passing the model, tokenizer, and desired device.
77
+
78
+ ```python
79
+ # Initialize the predictor
80
+ predictor = KronosPredictor(model, tokenizer, device="cuda:0", max_context=512)
81
+ ```
82
+
83
+ #### 3. Prepare Input Data
84
+
85
+ The `predict` method requires three main inputs:
86
+ - `df`: A pandas DataFrame containing the historical K-line data. It must include columns `['open', 'high', 'low', 'close']`. `volume` and `amount` are optional.
87
+ - `x_timestamp`: A pandas Series of timestamps corresponding to the historical data in `df`.
88
+ - `y_timestamp`: A pandas Series of timestamps for the future periods you want to predict.
89
+
90
+ ```python
91
+ import pandas as pd
92
+
93
+ # Load your data
94
+ df = pd.read_csv("./data/XSHG_5min_600977.csv")
95
+ df['timestamps'] = pd.to_datetime(df['timestamps'])
96
+
97
+ # Define context window and prediction length
98
+ lookback = 400
99
+ pred_len = 120
100
+
101
+ # Prepare inputs for the predictor
102
+ x_df = df.loc[:lookback-1, ['open', 'high', 'low', 'close', 'volume', 'amount']]
103
+ x_timestamp = df.loc[:lookback-1, 'timestamps']
104
+ y_timestamp = df.loc[lookback:lookback+pred_len-1, 'timestamps']
105
+ ```
106
+
107
+ #### 4. Generate Forecasts
108
+
109
+ 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.
110
+
111
+ ```python
112
+ # Generate predictions
113
+ pred_df = predictor.predict(
114
+ df=x_df,
115
+ x_timestamp=x_timestamp,
116
+ y_timestamp=y_timestamp,
117
+ pred_len=pred_len,
118
+ T=1.0, # Temperature for sampling
119
+ top_p=0.9, # Nucleus sampling probability
120
+ sample_count=1 # Number of forecast paths to generate and average
121
+ )
122
+
123
+ print("Forecasted Data Head:")
124
+ print(pred_df.head())
125
+ ```
126
+
127
+ 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.
128
+
129
+ #### 5. Example and Visualization
130
+
131
+ 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).
132
+
133
+ Running this script will generate a plot comparing the ground truth data against the model's forecast, similar to the one shown below:
134
+
135
+ <p align="center">
136
+ <img src="https://github.com/shiyu-coder/Kronos/raw/main/figures/prediction_example.png" alt="Forecast Example" align="center" width="600px" />
137
+ </p>
138
+
139
+ 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).
140
+
141
+ ## Citation
142
+
143
+ If you use Kronos in your research, we would appreciate a citation to our [paper](https://arxiv.org/abs/2508.02739):
144
+
145
+ ```bibtex
146
+ @misc{shi2025kronos,
147
+ title={Kronos: A Foundation Model for the Language of Financial Markets},
148
+ author={Yu Shi and Zongliang Fu and Shuo Chen and Bohan Zhao and Wei Xu and Changshui Zhang and Jian Li},
149
+ year={2025},
150
+ eprint={2508.02739},
151
+ archivePrefix={arXiv},
152
+ primaryClass={q-fin.ST},
153
+ url={https://arxiv.org/abs/2508.02739},
154
+ }
155
+ ```
156
+
157
+ ## License
158
+ This project is licensed under the [MIT License](https://github.com/shiyu-coder/Kronos/blob/main/LICENSE).