Update README.md
Browse files
README.md
CHANGED
@@ -8,40 +8,48 @@ tags:
|
|
8 |
library_name: torch
|
9 |
---
|
10 |
|
11 |
-
# Model
|
12 |
|
13 |
-
|
|
|
|
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
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 |
-
|
|
|
|
|
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 |
|
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 |
-
|
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 |
|
@@ -49,7 +57,15 @@ Forecasting with Kronos is straightforward using the `KronosPredictor` class. It
|
|
49 |
|
50 |
Here is a step-by-step guide to making your first forecast.
|
51 |
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
First, load a pre-trained Kronos model and its corresponding tokenizer from the Hugging Face Hub.
|
55 |
|
@@ -61,7 +77,7 @@ tokenizer = KronosTokenizer.from_pretrained("NeoQuasar/Kronos-Tokenizer-base")
|
|
61 |
model = Kronos.from_pretrained("NeoQuasar/Kronos-small")
|
62 |
```
|
63 |
|
64 |
-
|
65 |
|
66 |
Create an instance of `KronosPredictor`, passing the model, tokenizer, and desired device.
|
67 |
|
@@ -70,7 +86,7 @@ Create an instance of `KronosPredictor`, passing the model, tokenizer, and desir
|
|
70 |
predictor = KronosPredictor(model, tokenizer, device="cuda:0", max_context=512)
|
71 |
```
|
72 |
|
73 |
-
|
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.
|
@@ -80,7 +96,7 @@ The `predict` method requires three main inputs:
|
|
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 |
|
@@ -94,7 +110,7 @@ x_timestamp = df.loc[:lookback-1, 'timestamps']
|
|
94 |
y_timestamp = df.loc[lookback:lookback+pred_len-1, 'timestamps']
|
95 |
```
|
96 |
|
97 |
-
|
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 |
|
@@ -116,30 +132,34 @@ print(pred_df.head())
|
|
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 |
-
|
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://
|
127 |
</p>
|
128 |
|
129 |
-
Additionally,
|
130 |
|
131 |
-
##
|
132 |
|
133 |
-
If you use Kronos in your research, we would appreciate a citation to our [paper](https://
|
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 |
-
```
|
|
|
|
|
|
|
|
|
|
8 |
library_name: torch
|
9 |
---
|
10 |
|
11 |
+
# Kronos: A Foundation Model for the Language of Financial Markets
|
12 |
|
13 |
+
[](https://arxiv.org/abs/2508.02739)
|
14 |
+
[](https://shiyu-coder.github.io/Kronos-demo/)
|
15 |
+
[](https://github.com/shiyu-coder/Kronos)
|
16 |
|
17 |
+
<p align="center">
|
18 |
+
<img src="https://github.com/shiyu-coder/Kronos/blob/master/figures/logo.jpeg?raw=true" alt="Kronos Logo" width="100">
|
19 |
+
</p>
|
20 |
+
|
21 |
+
**Kronos** is the **first open-source foundation model** for financial candlesticks (K-lines), trained on data from over **45 global exchanges**. It is designed to handle the unique, high-noise characteristics of financial data.
|
22 |
+
|
23 |
+
## Introduction
|
24 |
+
|
25 |
+
Kronos is a family of decoder-only foundation models, pre-trained specifically for the "language" of financial marketsβK-line sequences. It leverages a novel two-stage framework:
|
26 |
+
1. A specialized tokenizer first quantizes continuous, multi-dimensional K-line data (OHLCV) into **hierarchical discrete tokens**.
|
27 |
+
2. A large, autoregressive Transformer is then pre-trained on these tokens, enabling it to serve as a unified model for diverse quantitative tasks.
|
28 |
+
|
29 |
+
<p align="center">
|
30 |
+
<img src="https://github.com/shiyu-coder/Kronos/blob/master/figures/overview.png?raw=true" alt="Kronos Overview" align="center" width="700px" />
|
31 |
+
</p>
|
32 |
+
|
33 |
+
The success of large-scale pre-training paradigm, exemplified by Large Language Models (LLMs), has inspired the development of Time Series Foundation Models (TSFMs). Kronos addresses existing limitations by introducing a specialized tokenizer that discretizes continuous market information into token sequences, preserving both price dynamics and trade activity patterns. We pre-train Kronos 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. Kronos excels in a zero-shot setting across a diverse set of financial tasks, including price series forecasting, volatility forecasting, and synthetic data generation.
|
34 |
|
35 |
+
## Live Demo
|
36 |
|
|
|
37 |
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.
|
38 |
|
39 |
+
π [Access the Live Demo Here](https://shiyu-coder.github.io/Kronos-demo/)
|
40 |
+
|
41 |
+
## Model Zoo
|
42 |
|
|
|
43 |
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.
|
44 |
|
45 |
+
| Model | Tokenizer | Context length | Param | Hugging Face Model Card |
|
46 |
+
|--------------|---------------------------------------------------------------------------------| -------------- | ------ |--------------------------------------------------------------------------|
|
47 |
| Kronos-mini | [Kronos-Tokenizer-2k](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-2k) | 2048 | 4.1M | β
[NeoQuasar/Kronos-mini](https://huggingface.co/NeoQuasar/Kronos-mini) |
|
48 |
| Kronos-small | [Kronos-Tokenizer-base](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base) | 512 | 24.7M | β
[NeoQuasar/Kronos-small](https://huggingface.co/NeoQuasar/Kronos-small) |
|
49 |
| Kronos-base | [Kronos-Tokenizer-base](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base) | 512 | 102.3M | β
[NeoQuasar/Kronos-base](https://huggingface.co/NeoQuasar/Kronos-base) |
|
50 |
+
| Kronos-large | [Kronos-Tokenizer-base](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base) | 512 | 499.2M | β Not yet publicly available |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
## Getting Started: Making Forecasts
|
53 |
|
54 |
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.
|
55 |
|
|
|
57 |
|
58 |
Here is a step-by-step guide to making your first forecast.
|
59 |
|
60 |
+
### Installation
|
61 |
+
|
62 |
+
1. Install Python 3.10+, and then install the dependencies from the [GitHub repository's `requirements.txt`](https://github.com/shiyu-coder/Kronos/blob/main/requirements.txt):
|
63 |
+
|
64 |
+
```shell
|
65 |
+
pip install -r requirements.txt
|
66 |
+
```
|
67 |
+
|
68 |
+
### 1. Load the Tokenizer and Model
|
69 |
|
70 |
First, load a pre-trained Kronos model and its corresponding tokenizer from the Hugging Face Hub.
|
71 |
|
|
|
77 |
model = Kronos.from_pretrained("NeoQuasar/Kronos-small")
|
78 |
```
|
79 |
|
80 |
+
### 2. Instantiate the Predictor
|
81 |
|
82 |
Create an instance of `KronosPredictor`, passing the model, tokenizer, and desired device.
|
83 |
|
|
|
86 |
predictor = KronosPredictor(model, tokenizer, device="cuda:0", max_context=512)
|
87 |
```
|
88 |
|
89 |
+
### 3. Prepare Input Data
|
90 |
|
91 |
The `predict` method requires three main inputs:
|
92 |
- `df`: A pandas DataFrame containing the historical K-line data. It must include columns `['open', 'high', 'low', 'close']`. `volume` and `amount` are optional.
|
|
|
96 |
```python
|
97 |
import pandas as pd
|
98 |
|
99 |
+
# Load your data (example data can be found in the GitHub repo)
|
100 |
df = pd.read_csv("./data/XSHG_5min_600977.csv")
|
101 |
df['timestamps'] = pd.to_datetime(df['timestamps'])
|
102 |
|
|
|
110 |
y_timestamp = df.loc[lookback:lookback+pred_len-1, 'timestamps']
|
111 |
```
|
112 |
|
113 |
+
### 4. Generate Forecasts
|
114 |
|
115 |
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.
|
116 |
|
|
|
132 |
|
133 |
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.
|
134 |
|
135 |
+
### 5. Example and Visualization
|
136 |
|
137 |
+
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) in the GitHub repository.
|
138 |
|
139 |
Running this script will generate a plot comparing the ground truth data against the model's forecast, similar to the one shown below:
|
140 |
|
141 |
<p align="center">
|
142 |
+
<img src="https://github.com/shiyu-coder/Kronos/blob/master/figures/prediction_example.png?raw=true" alt="Forecast Example" align="center" width="600px" />
|
143 |
</p>
|
144 |
|
145 |
+
Additionally, a script that makes predictions without Volume and Amount data can be found in [`examples/prediction_wo_vol_example.py`](https://github.com/shiyu-coder/Kronos/blob/main/examples/prediction_wo_vol_example.py).
|
146 |
|
147 |
+
## Citation
|
148 |
|
149 |
+
If you use Kronos in your research, we would appreciate a citation to our [paper](https://huggingface.co/papers/2508.02739):
|
150 |
|
151 |
+
```bibtex
|
152 |
@misc{shi2025kronos,
|
153 |
+
title={Kronos: A Foundation Model for the Language of Financial Markets},
|
154 |
author={Yu Shi and Zongliang Fu and Shuo Chen and Bohan Zhao and Wei Xu and Changshui Zhang and Jian Li},
|
155 |
year={2025},
|
156 |
eprint={2508.02739},
|
157 |
archivePrefix={arXiv},
|
158 |
primaryClass={q-fin.ST},
|
159 |
+
url={https://arxiv.org/abs/2508.02739},
|
160 |
}
|
161 |
+
```
|
162 |
+
|
163 |
+
## License
|
164 |
+
|
165 |
+
This project is licensed under the [MIT License](https://github.com/shiyu-coder/Kronos/blob/main/LICENSE).
|