← 返回日报
🌐 机器翻译 · DeepSeek · GitHub

shiyu-coder Kronos


Kronos:金融市场语言的基础模型

Deutsch | Español | Français | 日本語 | 한국어 | Português | Русский | 中文

Kronos 是首个面向金融K线(K-lines)的开源基础模型,基于全球超过45个交易所的数据训练而成。

📰 新闻

🚩 [2025.11.10] Kronos 已被 AAAI 2026 接收。

🚩 [2025.08.17] 我们发布了微调脚本!查看这些脚本,将 Kronos 适配到你自己的任务中。

🚩 [2025.08.02] 我们的论文现已在 arXiv 上发布!

📜 简介

Kronos 是一系列仅解码器(decoder-only)基础模型,专门针对金融市场的“语言”——K线序列进行预训练。与通用的时间序列基础模型(TSFM)不同,Kronos 旨在处理金融数据特有的高噪声特征。它采用新颖的两阶段框架:首先,专用分词器将连续的多维K线数据(OHLCV)量化为分层离散 token。然后,一个大型自回归 Transformer 在这些 token 上进行预训练,使其能够作为统一模型服务于多样化的量化任务。

✨ 在线演示

我们搭建了一个在线演示,用于可视化 Kronos 的预测结果。网页展示了 BTC/USDT 交易对未来24小时的预测。

👉 点击此处访问在线演示

📦 模型库

我们发布了一系列不同规模的预训练模型,以满足不同的计算和应用需求。所有模型均可从 Hugging Face Hub 直接获取。

| 模型 | 分词器 | 上下文长度 | 参数量 | 开源 | |------|--------|-----------|--------|------| | Kronos-mini | Kronos-Tokenizer-2k | 2048 | 4.1M | ✅ NeoQuasar/Kronos-mini | | Kronos-small | Kronos-Tokenizer-base | 512 | 24.7M | ✅ NeoQuasar/Kronos-small | | Kronos-base | Kronos-Tokenizer-base | 512 | 102.3M | ✅ NeoQuasar/Kronos-base | | Kronos-large | Kronos-Tokenizer-base | 512 | 499.2M | ❌ |

🚀 快速开始

安装

安装 Python 3.10+,然后安装依赖:

pip install -r requirements.txt

📈 进行预测

使用 KronosPredictor 类进行 Kronos 预测非常简单。它处理数据预处理、归一化、预测和反归一化,让你只需几行代码即可从原始数据得到预测结果。

重要提示:Kronos-small 和 Kronos-base 的 max_context 为 512。这是模型能够处理的最大序列长度。为获得最佳性能,建议输入数据长度(即 lookback)不超过此限制。KronosPredictor 会自动对更长的上下文进行截断处理。

以下是进行首次预测的分步指南。

  1. 加载分词器和模型

首先,从 Hugging Face Hub 加载预训练的 Kronos 模型及其对应的分词器。

from model import Kronos, KronosTokenizer, KronosPredictor

# Load from Hugging Face Hub
tokenizer = KronosTokenizer.from_pretrained("NeoQuasar/Kronos-Tokenizer-base")
model = Kronos.from_pretrained("NeoQuasar/Kronos-small")
  1. 实例化预测器

创建 KronosPredictor 实例,传入模型、分词器和目标设备。

# Initialize the predictor
predictor = KronosPredictor(model, tokenizer, max_context=512)
  1. 准备输入数据

predict 方法需要三个主要输入:

  1. 生成预测

调用 predict 方法生成预测。你可以通过 T、top_p 和 sample_count 等参数控制采样过程,以实现概率预测。

# Generate predictions
pred_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())

predict 方法返回一个 pandas DataFrame,包含 open、high、low、close、volume 和 amount 的预测值,以你提供的 y_timestamp 为索引。

为高效处理多个时间序列,Kronos 提供了 predict_batch 方法,可同时对多个数据集进行并行预测。当你需要一次性预测多个资产或多个时间段时,这尤其有用。

# Prepare multiple datasets for batch prediction
df_list = [df1, df2, df3]  # List of DataFrames
x_timestamp_list = [x_ts1, x_ts2, x_ts3]  # List of historical timestamps
y_timestamp_list = [y_ts1, y_ts2, y_ts3]  # List of future timestamps

# Generate batch predictions
pred_df_list = predictor.predict_batch(
    df_list=df_list,
    x_timestamp_list=x_timestamp_list,
    y_timestamp_list=y_timestamp_list,
    pred_len=pred_len,
    T=1.0,
    top_p=0.9,
    sample_count=1,
    verbose=True
)

# pred_df_list contains prediction results in the same order as input
for i, pred_df in enumerate(pred_df_list):
    print(f"Predictions for series {i}:")
    print(pred_df.head())

批量预测的重要要求:

📖 阅读原文 →