Skip to content

Using Your Own Data ​

After finishing this section, you'll be able to feed the candlestick data of a stock you have into KiT: either place it into the demo data's directory structure and use the official scripts directly, or call it from your own Python code.

1. What the Data Looks Like ​

One parquet file per stock per granularity, with six columns:

ColumnTypeDescription
datetimedatetime64, no timezoneThe end time of this candlestick, e.g. for a 1-hour bar: 10:30, 11:30, 14:00, 15:00
open high low closefloat64Backward-adjusted prices
volumefloat64Volume

README says date, but the code uses datetime

The column name given in the "Using Your Own Data" section of the official README is date, but both the demo data and the code read datetime. Use datetime.

Place it in:

text
data/ashare/<粒度>/<代码>.parquet     例如 data/ashare/1d/600000.SH.parquet

Save one with pandas:

python
import pandas as pd
df = pd.read_csv("600000_daily.csv", parse_dates=["datetime"])   # 你自己的数据
df = df[["datetime", "open", "high", "low", "close", "volume"]].astype(
    {"open": "float64", "high": "float64", "low": "float64", "close": "float64", "volume": "float64"})
df.to_parquet("data/ashare/1d/600000.SH.parquet", index=False)

Key points:

  • Use backward-adjusted prices. On ex-dividend days, unadjusted prices would make the model think the price crashed by a huge amount.
  • Write daily bars' time as 15:00 close. That's how the demo data does it (2026-04-10 15:00:00).
  • No gaps allowed on suspension days. The script checks future timestamps against the trading calendar and rejects the anchor if they don't match.

2. instruments.json: Which Stock This Is ​

Every stock the model was trained on has an ID (vocab_index) that corresponds to a learned "identity" vector. The demo data's instruments.json has only 100 stocks:

json
"300368.SZ": {"market": "ashare", "sector": 0, "vocab_index": 1369}

The ckpt/step_market_284M/instruments.json that ships with the weights package has 4830 stocks (A-shares, US stocks, crypto). If your stock is in there, copy its entry over verbatim into data/instruments.json, without changing a single ID: the official model card specifically warns that these IDs select the trained identity vectors.

If it's not in there (e.g. a newly listed stock), use "sector": 0, "vocab_index": 0. 0 means "unknown", and the model predicts based on the candlesticks alone. During training, a fraction of samples deliberately had their identity replaced with "unknown" (the conditional dropout in Section 3.5 of the paper), so the model has learned this situation.

3. stats.json: Don't Recompute It Yourself ​

stats.json holds the scaling factors for each "market | granularity | feature" combination, e.g. ashare|1d|r_body. During training, the model used this set of scales to bring the five numbers into a comparable range; at inference you must use the same set, and also use it to convert predictions back afterward.

So: when using A-share data, just use the official stats.json. The code includes fit_stats which recomputes a set from the data — that's for training new models. Feeding a freshly computed set of scales to the official model would give inputs with a distribution different from what it learned.

4. Using the Official Scripts ​

Once the data and instruments.json are in place, it's the same as the demo data:

bash
python eval/infer_for_pred.py --case 600000.SH,1d,2026-03-10

This script requires real data after the anchor (it needs to check the answers). If you want to predict "beyond tomorrow" and don't have real data yet, use the Python interface below.

5. Calling It from Your Own Code ​

Save the following as my_forecast.py inside the KiT directory (it won't find kit_v1 if placed elsewhere), then run python my_forecast.py:

python
import json
from pathlib import Path
import torch
from kit_v1.data.calendar import load_trading_days
from kit_v1.data.normalize import load_stats
from kit_v1.infer import (load_model_and_config, prepare_inference_window,
                          flow_sample, denormalize_paths, paths_to_ohlcv)

data = Path("data")
stats = load_stats(data / "stats.json")
tdays = load_trading_days(data / "trade_dates.csv")
model, cfg = load_model_and_config("ckpt/step_market_284M.pt", "tiny", 0)
model.cuda().eval()

scale = "1d"
Lc, Lh = cfg.data.window_for(scale)                       # 日线:250, 20
inst = json.loads((data / "instruments.json").read_text())["300368.SZ"]
win = prepare_inference_window(
    data / "ashare" / scale / "300368.SZ.parquet", "ashare", scale, Lc, Lh, stats,
    soft_clip_c=cfg.data.soft_clip_c, half_life_days=cfg.data.vol_ema_half_life_days,
    end_ts=None,                                            # None = 用数据的最后一根当锚点
    sector_id=inst["sector"], inst_id=inst["vocab_index"], trading_days=tdays)

paths = flow_sample(model, win["x_ctx"], win["cond"], Lh=Lh, steps=32, n_paths=16,
                    precision="bf16", generator=torch.Generator().manual_seed(0))
feats = denormalize_paths(paths, "ashare", scale, stats, c=cfg.data.soft_clip_c)[0]
pred = paths_to_ohlcv(feats, win["prev_close"], win["prev_ema"], win["half_life_bars"])
print(win["future_timestamps"][0], pred["close"].shape)   # 第一根未来 K 线的时间,(16, 20)

You should see:

text
[info] loaded EMA weights (step=50000)
2026-04-13 15:00:00 (16, 20)

The last demo bar is 2026-04-10 (a Friday), so the first future bar is Monday, month 4, day 13. With end_ts=None, the anchor is the last bar of the data, and the timestamps of the next 20 bars are advanced along the trading calendar (trade_dates.csv must cover those dates, otherwise only weekends get skipped). pred contains the open, high, low, close, and volume for 16 paths, each as a (16, 20) array.

This is exactly the call sequence used internally by the official script; you can compare against eval/infer_for_pred.py.

Quiz timeYour stock isn't in the official instruments.json—how should you fill it in?

Quick Check ​

  • My parquet has the six columns datetime, open, high, low, close, volume, and the prices are backward-adjusted
  • I know the IDs in instruments.json must be copied verbatim from the weights package, or set to 0 if absent
  • I got a prediction array of shape (16, 20) from the Python interface

Next section: Model Architecture.

gaodong.aiAboutPrivacyContact

Independent tutorials, not affiliated with any product mentioned. Product names and trademarks belong to their owners. Check official pages for prices and policies.