shiyu-coder /
Kronos
Pre-trained Transformer models that forecast candlestick (K-line) price data
- 43.2k stars
- 3.4k stars since 3 Oct
- Python
- Updated 6 months ago
- Some experience
- Models & local AI
Financial candlestick charts are noisy, and general time-series models often handle them poorly. Kronos is built for this one kind of data. It treats sequences of K-lines (open, high, low, close, volume) like a language a model can learn to continue.
It works in two stages. A tokenizer first turns the continuous price numbers into hierarchical discrete tokens. Then an autoregressive Transformer, trained on those tokens, predicts what comes next. The README contrasts it with general-purpose time-series foundation models.
Four model sizes are listed, from 4.1M to 499.2M parameters. Mini, small and base are on Hugging Face. Large is not released. The repo also has a fine-tuning pipeline, shown with Chinese A-share data via Qlib, plus a simple backtest. The authors say it is a demo, not a production trading system.
What it does
Simple forecasting API
KronosPredictor takes a pandas DataFrame of K-lines plus timestamps. It handles normalization, prediction and inverse normalization, then returns a DataFrame of forecasts.
Sampling controls
Temperature, top-p and sample_count let you generate several forecast paths and average them.
Batch prediction
predict_batch forecasts many series in parallel on a GPU. All series need the same lookback and prediction length.
Several model sizes
Kronos-mini, small and base can be downloaded from Hugging Face. Context length is 2048 for mini and 512 for the others.
Fine-tuning pipeline
Scripts prepare Qlib data, fine-tune the tokenizer and predictor with torchrun on multiple GPUs, and run a top-K backtest.
What you could build
- Forecast the next hours of a crypto pair from its recent candles.
- Run batch forecasts across many stocks or time periods at once.
- Fine-tune a Kronos model on your own market's daily data.
- Backtest a simple top-K strategy using the model's predicted price changes.
- Compare Kronos forecasts with other time-series models as a research baseline.
Get started
Install Python 3.10+ and the requirements. Then load a tokenizer and model from Hugging Face, wrap them in KronosPredictor, and call predict on a DataFrame of candles. The examples/prediction_example.py script runs the whole flow and plots the result.
pip install -r requirements.txtCommands are copied from the project's README. Read it on GitHub for the full setup.
More in Models & local AI
transformers
Shared model definitions for text, vision, audio and multimodal AI models