Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Shiyu coder Kronos TopkDropoutStrategy Usage

From Leeroopedia


Field Value
Implementation Name TopkDropoutStrategy_Usage
Repository Shiyu_coder_Kronos
Repository URL https://github.com/shiyu-coder/Kronos
Type External Tool Doc
Source External -- qlib.contrib.strategy.TopkDropoutStrategy (not defined in this repo)
Used In finetune/qlib_test.py:L120-125
Implements Principle Principle:Shiyu_coder_Kronos_Topk_Dropout_Portfolio_Strategy
External Docs https://qlib.readthedocs.io/
Last Updated 2026-02-09 14:00 GMT

Overview

TopkDropoutStrategy is an external trading strategy class from the Qlib quantitative investment framework. It is used in the Kronos backtesting pipeline to convert model prediction signals into portfolio allocation decisions. This class is not defined in the Kronos repository but is imported and configured within it.

Import

from qlib.contrib.strategy import TopkDropoutStrategy

API

strategy = TopkDropoutStrategy(
    topk: int,
    n_drop: int,
    hold_thresh: int,
    signal: pd.Series
) -> TopkDropoutStrategy

Parameters

Parameter Type Kronos Default Description
topk int 50 Number of stocks to hold in the portfolio at each rebalancing step
n_drop int 5 Number of positions to randomly drop from the held pool at each rebalance
hold_thresh int 5 Minimum holding period (in trading days) before a position is eligible for dropout
signal pd.Series (from model) Prediction scores as a MultiIndex Series with levels (instrument, datetime)

Input: Signal Series

The signal parameter expects a pandas Series with a MultiIndex of (instrument, datetime) and float prediction scores as values. In the Kronos pipeline, this signal is generated from model inference:

# From finetune/qlib_test.py -- signal construction
pred_series = pred_df.stack()
pred_series.index.names = ['datetime', 'instrument']
pred_series = pred_series.swaplevel().sort_index()

# pred_series is now indexed as (instrument, datetime) with prediction scores

Output

The strategy object is passed to qlib.backtest.backtest() which uses it to generate portfolio allocation decisions at each time step. The backtest returns portfolio metrics including returns, costs, and benchmark comparisons.

Configuration in Kronos

The strategy parameters are configured via the Kronos Config class in finetune/config.py:

# From finetune/config.py
self.backtest_n_symbol_hold = 50   # Number of symbols to hold in the portfolio.
self.backtest_n_symbol_drop = 5    # Number of symbols to drop from the pool.
self.backtest_hold_thresh = 5      # Minimum holding period for a stock.

Usage in Kronos Backtesting

The complete usage pattern from finetune/qlib_test.py (L120-125):

from qlib.contrib.strategy import TopkDropoutStrategy
from qlib.backtest import backtest, executor

# Create strategy from prediction signals
strategy = TopkDropoutStrategy(
    topk=self.config.backtest_n_symbol_hold,
    n_drop=self.config.backtest_n_symbol_drop,
    hold_thresh=self.config.backtest_hold_thresh,
    signal=signal_series,
)

# Configure executor
executor_config = {
    "time_per_step": "day",
    "generate_portfolio_metrics": True,
    "delay_execution": True,
}

# Configure backtest
backtest_config = {
    "start_time": self.config.backtest_time_range[0],
    "end_time": self.config.backtest_time_range[1],
    "account": 100_000_000,
    "benchmark": self.config.backtest_benchmark,
    "exchange_kwargs": {
        "freq": "day",
        "limit_threshold": 0.095,
        "deal_price": "open",
        "open_cost": 0.001,
        "close_cost": 0.0015,
        "min_cost": 5,
    },
    "executor": executor.SimulatorExecutor(**executor_config),
}

# Run backtest
portfolio_metric_dict, _ = backtest(strategy=strategy, **backtest_config)

Signal Types

The Kronos inference pipeline generates multiple signal types from the same model predictions:

Signal Type Computation Description
last preds[:, -1, 3] - last_day_close Predicted close price change at the last prediction step
mean np.mean(preds[:, :, 3], axis=1) - last_day_close Average predicted close price change across all prediction steps
max np.max(preds[:, :, 3], axis=1) - last_day_close Maximum predicted close price change
min np.min(preds[:, :, 3], axis=1) - last_day_close Minimum predicted close price change

Each signal type can be independently backtested to evaluate which prediction aggregation method yields the best trading performance.

External Documentation

For full documentation on TopkDropoutStrategy and the Qlib backtesting framework, refer to:

See Also

Environment & Heuristic Links

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment