Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Workflow:Shiyu coder Kronos Single Series Prediction

From Leeroopedia


Knowledge Sources
Domains Financial_Forecasting, Time_Series, LLMs
Last Updated 2026-02-09 14:00 GMT

Overview

End-to-end process for generating candlestick (K-line) price forecasts on a single financial time series using a pre-trained Kronos foundation model.

Description

This workflow covers the complete inference pipeline for predicting future OHLCV (Open, High, Low, Close, Volume, Amount) candlestick data from historical market data. It loads a pre-trained KronosTokenizer and Kronos model pair from HuggingFace Hub, wraps them in the high-level KronosPredictor interface, prepares a pandas DataFrame of historical price data with timestamps, runs autoregressive token-by-token generation with configurable sampling parameters (temperature, top-p, sample count), and returns a DataFrame of predicted future candlesticks. The predictor handles all internal normalization, tokenization, generation, and denormalization transparently.

Usage

Execute this workflow when you have historical OHLCV candlestick data for a single financial instrument (stock, crypto, index) stored as a pandas DataFrame and need to generate future price forecasts. The input DataFrame must contain at minimum the columns open, high, low, close (volume and amount are optional and will be zero-filled if missing). You also need to provide historical timestamps and desired future prediction timestamps as pandas Series.

Execution Steps

Step 1: Load Tokenizer and Model

Load a pre-trained KronosTokenizer and Kronos model from the HuggingFace Hub using the from_pretrained class method. The tokenizer converts continuous OHLCV data into hierarchical discrete tokens via Binary Spherical Quantization (BSQ). The model is a decoder-only autoregressive Transformer that predicts token sequences. Both components use PyTorchModelHubMixin for seamless loading.

Key considerations:

  • The tokenizer and model must be a matched pair (e.g., Kronos-Tokenizer-base with Kronos-small or Kronos-base)
  • Available model sizes: mini (4.1M params, 2048 context), small (24.7M, 512 context), base (102.3M, 512 context)
  • Models are automatically downloaded and cached from HuggingFace on first use

Step 2: Instantiate Predictor

Create a KronosPredictor instance that wraps the tokenizer and model into a single high-level interface. The predictor manages device placement (auto-detects CUDA, MPS, or CPU), sets the maximum context window, and configures the clipping threshold for normalization.

Key considerations:

  • Set max_context to match the model capacity (512 for small/base, 2048 for mini)
  • The predictor automatically moves both tokenizer and model to the selected device
  • The clip parameter (default 5.0) controls how aggressively normalized values are clamped

Step 3: Prepare Input Data

Prepare three inputs: a pandas DataFrame of historical OHLCV data, a Series of historical timestamps (x_timestamp), and a Series of future timestamps to predict (y_timestamp). The DataFrame must contain at least open, high, low, close columns. Volume and amount are optional.

Key considerations:

  • Input length (lookback) should not exceed the model's max_context for optimal performance
  • Timestamps are converted to temporal features (minute, hour, weekday, day, month) internally
  • The predictor will auto-truncate if the input exceeds max_context
  • Ensure timestamps are datetime objects, not strings

Step 4: Generate Forecast

Call the predict method with the prepared data and sampling parameters. Internally, the method normalizes the input data (instance-level mean/std), computes temporal features, tokenizes the normalized series into hierarchical s1/s2 token pairs, runs autoregressive inference token-by-token for the specified prediction length, decodes the generated tokens back to continuous values, and denormalizes to the original scale.

Key considerations:

  • Temperature (T) controls randomness: lower values produce more deterministic forecasts
  • top_p (nucleus sampling) filters unlikely tokens; 0.9 is a good default
  • sample_count generates multiple forecast paths and averages them for smoother predictions
  • The method returns a DataFrame with columns open, high, low, close, volume, amount indexed by y_timestamp

Step 5: Visualize Results

Plot the historical ground truth alongside the predicted values to visually assess forecast quality. Typically, close price and volume are plotted on separate subplots sharing the same time axis.

Key considerations:

  • Align prediction indices with the corresponding historical data for proper overlay
  • Compare predicted close prices and volumes against actual values in the forecast window
  • Use this step for qualitative assessment of prediction quality

Execution Diagram

GitHub URL

Workflow Repository