Update README.md
Browse files4 unmodified lines56789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354554 unmodified lines606162636465661 unmodified line686970717273742 unmodified lines777879808182837 unmodified lines9192939495969714 unmodified lines1121131141151161171181191201211221231241251261271281291301311321331341351361371381394 unmodified lines- Finance- Candlestick- K-linelibrary_name: Kronos---# Kronos: A Foundation Model for the Language of Financial MarketsKronos is the **first open-source foundation model** for financial candlesticks (K-lines), trained on data from over **45 global exchanges**. It was presented in the paper [Kronos: A Foundation Model for the Language of Financial Markets](https://huggingface.co/papers/2508.02739).For full details, including the complete codebase and additional examples, please visit our [GitHub page](https://github.com/shiyu-coder/Kronos).Try out our live demo showcasing Kronos's forecasting results for the BTC/USDT trading pair: [Access the Live Demo Here](https://shiyu-coder.github.io/Kronos-demo/)<p align="center"><img src="https://github.com/shiyu-coder/Kronos/raw/main/figures/overview.png" alt="Kronos Overview" width="700px" /></p>## AbstractThe success of large-scale pre-training paradigm, exemplified by Large Language Models (LLMs), has inspired the development of Time Series Foundation Models (TSFMs). However, their application to financial candlestick (K-line) data remains limited, often underperforming non-pre-trained architectures. Moreover, existing TSFMs often overlook crucial downstream tasks such as volatility prediction and synthetic data generation. To address these limitations, we propose Kronos, a unified, scalable pre-training framework tailored to financial K-line modeling. Kronos introduces 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. On benchmark datasets, Kronos boosts price series forecasting RankIC by 93% over the leading 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. Our pre-trained model is publicly available at this https URL.## Model ZooWe 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 | Open-source ||--------------|---------------------------------------------------------------------------------| -------------- | ------ |---------------------------------------------------------------------------|| 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 | ❌ |## Getting Started### Installation1. Install Python 3.10+, and then install the dependencies:```shellpip install -r requirements.txt```### Making ForecastsForecasting 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.#### 1. Load the Tokenizer and ModelFirst, load a pre-trained Kronos model and its corresponding tokenizer from the Hugging Face Hub.```python4 unmodified linesmodel = Kronos.from_pretrained("NeoQuasar/Kronos-small")```#### 2. Instantiate the PredictorCreate an instance of `KronosPredictor`, passing the model, tokenizer, and desired device.```python1 unmodified linepredictor = KronosPredictor(model, tokenizer, device="cuda:0", max_context=512)```#### 3. Prepare Input DataThe `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`.2 unmodified lines```pythonimport pandas as pd# Load your datadf = pd.read_csv("./data/XSHG_5min_600977.csv")df['timestamps'] = pd.to_datetime(df['timestamps'])7 unmodified linesy_timestamp = df.loc[lookback:lookback+pred_len-1, 'timestamps']```#### 4. Generate ForecastsCall the `predict` method to generate forecasts. You can control the sampling process with parameters like `T`, `top_p`, and `sample_count` for probabilistic forecasting.```python14 unmodified linesThe `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 VisualizationFor 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).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/raw/main/figures/prediction_example.png" alt="Forecast Example" width="600px" /></p>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).## CitationIf 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},}```4 unmodified lines5678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970714 unmodified lines76777879808182831 unmodified line85868788899091922 unmodified lines95969798991001017 unmodified lines10911011111211311411511614 unmodified lines1311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631644 unmodified lines- Finance- Candlestick- K-line---# 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.jpeg?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.## IntroductionKronos 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 DemoWe 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 ZooWe 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 ForecastsForecasting 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.### Installation1. 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):```shellpip install -r requirements.txt```### 1. Load the Tokenizer and ModelFirst, load a pre-trained Kronos model and its corresponding tokenizer from the Hugging Face Hub.```python4 unmodified linesmodel = Kronos.from_pretrained("NeoQuasar/Kronos-small")```### 2. Instantiate the PredictorCreate an instance of `KronosPredictor`, passing the model, tokenizer, and desired device.```python1 unmodified linepredictor = KronosPredictor(model, tokenizer, device="cuda:0", max_context=512)```### 3. Prepare Input DataThe `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`.2 unmodified lines```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'])7 unmodified linesy_timestamp = df.loc[lookback:lookback+pred_len-1, 'timestamps']```### 4. Generate ForecastsCall the `predict` method to generate forecasts. You can control the sampling process with parameters like `T`, `top_p`, and `sample_count` for probabilistic forecasting.```python14 unmodified linesThe `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 VisualizationFor 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).## CitationIf 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},}```## LicenseThis project is licensed under the [MIT License](https://github.com/shiyu-coder/Kronos/blob/main/LICENSE).
README.md+56-31