Duplicate from NeoQuasar/Kronos-Tokenizer-base
Browse filesCo-authored-by: ShiYu <NeoQuasar@users.noreply.huggingface.co>
Files changed (4)
- .gitattributesAdded+35
- README.mdAdded+169
- config.jsonAdded+18
- model.safetensorsAdded+3
1234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169---license: mitpipeline_tag: time-series-forecastingtags:- Finance- Candlestick- K-linelibrary_name: pytorch---
# Kronos: A Foundation Model for the Language of Financial Markets
[](https://arxiv.org/abs/2508.02739)[](https://shiyu-coder.github.io/Kronos-demo/)[](https://github.com/shiyu-coder/Kronos)
<p align="center"> <img src="https://github.com/shiyu-coder/Kronos/blob/master/figures/logo.png?raw=true" alt="Kronos Logo" width="100"></p>
**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.
## Introduction
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:1. A specialized tokenizer first quantizes continuous, multi-dimensional K-line data (OHLCV) into **hierarchical discrete tokens**.2. A large, autoregressive Transformer is then pre-trained on these tokens, enabling it to serve as a unified model for diverse quantitative tasks.
<p align="center"> <img src="https://github.com/shiyu-coder/Kronos/blob/master/figures/overview.png?raw=true" alt="Kronos Overview" align="center" width="700px" /></p>
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.
## Live Demo
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.
👉 [Access the Live Demo Here](https://shiyu-coder.github.io/Kronos-demo/)
## Model Zoo
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.
| Model | Tokenizer | Context length | Param | Hugging Face Model Card ||--------------|---------------------------------------------------------------------------------| -------------- | ------ |--------------------------------------------------------------------------|| Kronos-mini | [Kronos-Tokenizer-2k](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-2k) | 2048 | 4.1M | ✅ [NeoQuasar/Kronos-mini](https://huggingface.co/NeoQuasar/Kronos-mini) || Kronos-small | [Kronos-Tokenizer-base](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base) | 512 | 24.7M | ✅ [NeoQuasar/Kronos-small](https://huggingface.co/NeoQuasar/Kronos-small) || Kronos-base | [Kronos-Tokenizer-base](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base) | 512 | 102.3M | ✅ [NeoQuasar/Kronos-base](https://huggingface.co/NeoQuasar/Kronos-base) || Kronos-large | [Kronos-Tokenizer-base](https://huggingface.co/NeoQuasar/Kronos-Tokenizer-base) | 512 | 499.2M | ❌ Not yet publicly available |
## Getting Started: Making Forecasts
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.
**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.
Here is a step-by-step guide to making your first forecast.
### Installation
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):
```shell pip install -r requirements.txt ```
### 1. Load the Tokenizer and Model
First, load a pre-trained Kronos model and its corresponding tokenizer from the Hugging Face Hub.
```pythonfrom model import Kronos, KronosTokenizer, KronosPredictor
# Load from Hugging Face Hubtokenizer = KronosTokenizer.from_pretrained("NeoQuasar/Kronos-Tokenizer-base")model = Kronos.from_pretrained("NeoQuasar/Kronos-small")```
### 2. Instantiate the Predictor
Create an instance of `KronosPredictor`, passing the model, tokenizer, and desired device.
```python# Initialize the predictorpredictor = KronosPredictor(model, tokenizer, device="cuda:0", max_context=512)```
### 3. Prepare Input Data
The `predict` method requires three main inputs:- `df`: A pandas DataFrame containing the historical K-line data. It must include columns `['open', 'high', 'low', 'close']`. `volume` and `amount` are optional.- `x_timestamp`: A pandas Series of timestamps corresponding to the historical data in `df`.- `y_timestamp`: A pandas Series of timestamps for the future periods you want to predict.
```pythonimport pandas as pd
# Load your data (example data can be found in the GitHub repo)df = pd.read_csv("./data/XSHG_5min_600977.csv")df['timestamps'] = pd.to_datetime(df['timestamps'])
# Define context window and prediction lengthlookback = 400pred_len = 120
# Prepare inputs for the predictorx_df = df.loc[:lookback-1, ['open', 'high', 'low', 'close', 'volume', 'amount']]x_timestamp = df.loc[:lookback-1, 'timestamps']y_timestamp = df.loc[lookback:lookback+pred_len-1, 'timestamps']```
### 4. Generate Forecasts
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.
```python# Generate predictionspred_df = predictor.predict( df=x_df, x_timestamp=x_timestamp, y_timestamp=y_timestamp, pred_len=pred_len, T=1.0, # Temperature for sampling top_p=0.9, # Nucleus sampling probability sample_count=1 # Number of forecast paths to generate and average)
print("Forecasted Data Head:")print(pred_df.head())```
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.
### 5. Example and Visualization
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.
Running this script will generate a plot comparing the ground truth data against the model's forecast, similar to the one shown below:
<p align="center"> <img src="https://github.com/shiyu-coder/Kronos/blob/master/figures/prediction_example.png?raw=true" alt="Forecast Example" align="center" width="600px" /></p>
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).
## 🔧 Finetuning on Your Own Data (A-Share Market Example)
Refer to the [README](https://github.com/shiyu-coder/Kronos) of GitHub repository.
## Citation
If you use Kronos in your research, we would appreciate a citation to our [paper](https://huggingface.co/papers/2508.02739):
```bibtex@misc{shi2025kronos, title={Kronos: A Foundation Model for the Language of Financial Markets}, author={Yu Shi and Zongliang Fu and Shuo Chen and Bohan Zhao and Wei Xu and Changshui Zhang and Jian Li}, year={2025}, eprint={2508.02739}, archivePrefix={arXiv}, primaryClass={q-fin.ST}, url={https://arxiv.org/abs/2508.02739}, }```
## License
This project is licensed under the [MIT License](https://github.com/shiyu-coder/Kronos/blob/main/LICENSE).123456789101112131415161718{ "attn_dropout_p": 0.0, "beta": 0.05, "d_in": 6, "d_model": 256, "ff_dim": 512, "ffn_dropout_p": 0.0, "gamma": 1.1, "gamma0": 1.0, "group_size": 4, "n_dec_layers": 4, "n_enc_layers": 4, "n_heads": 4, "resid_dropout_p": 0.0, "s1_bits": 10, "s2_bits": 10, "zeta": 0.05}123version https://git-lfs.github.com/spec/v1oid sha256:59d85f6af76a2c3b8240ea06cb21db4213b4eeca053f246b23e29cf832fc6beesize 15842368.gitattributesAdded+35
README.mdAdded+169
config.jsonAdded+18
model.safetensorsAdded+3