quant-stock-prediction
Quantitative Financeqlibrigorous codebase
Description
Quantitative Stock Prediction on CSI300
Objective
Design and implement a stock prediction model that forecasts next-day returns for CSI300 stocks. Your code goes in custom_model.py. Three reference implementations (LightGBM, LSTM, Transformer) are provided as read-only.
Evaluation
Signal quality: IC, ICIR, Rank IC. Portfolio (TopkDropout, top 50, drop 5): Annualized Return, Max Drawdown, Information Ratio. Evaluation is automatic via qlib's workflow.
Workflow Configuration
workflow_config.yaml lines 13-25 and 31-44 are editable. This is the model plus input-adapter/preprocessor block: you may change the dataset class (e.g., to TSDatasetH) or processors if your model needs a different input view. Instruments, date ranges, train/valid/test splits, and evaluation settings are fixed.
Code
custom_model.py
EditableRead-only
1# Custom stock prediction model for MLS-Bench2#3# EDITABLE section: CustomModel class with fit() and predict() methods.4# FIXED sections: imports below.5import numpy as np6import pandas as pd7import torch8import torch.nn as nn9import torch.nn.functional as F10from qlib.model.base import Model11from qlib.data.dataset import DatasetH12from qlib.data.dataset.handler import DataHandlerLP1314DEVICE = "cuda" if torch.cuda.is_available() else "cpu"15
workflow_config.yaml
EditableRead-only
1# Qlib workflow configuration for CSI300 stock prediction benchmark.2# Used by run_workflow.py — matches Alpha360/CSI300 official benchmark settings.34qlib_init:5provider_uri: "~/.qlib/qlib_data/cn_data"6region: cn78sys:9rel_path:10- "." # So custom_model.py is importable via module_path1112task:13model:14class: CustomModel15module_path: custom_model
Additional context files (read-only):
qlib/qlib/model/base.py
Results
| Model | Type | ic csi300 ↑ | icir csi300 ↑ | rank ic csi300 ↑ | rank icir csi300 ↑ | annualized return csi300 ↑ | max drawdown csi300 ↓ | information ratio csi300 ↑ | ic csi100 ↑ | icir csi100 ↑ | rank ic csi100 ↑ | rank icir csi100 ↑ | annualized return csi100 ↑ | max drawdown csi100 ↓ | information ratio csi100 ↑ | ic csi300 recent ↑ | icir csi300 recent ↑ | rank ic csi300 recent ↑ | rank icir csi300 recent ↑ | annualized return csi300 recent ↑ | max drawdown csi300 recent ↓ | information ratio csi300 recent ↑ |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| lgbm | baseline | - | - | - | - | - | - | - | 0.036 | 0.220 | 0.044 | 0.277 | -0.017 | -0.158 | -0.334 | 0.025 | 0.182 | 0.041 | 0.302 | 0.020 | -0.076 | 0.266 |
| lgbm | baseline | 0.040 | 0.308 | 0.049 | 0.402 | 0.020 | -0.100 | 0.280 | 0.036 | 0.220 | 0.044 | 0.277 | -0.017 | -0.158 | -0.334 | 0.025 | 0.182 | 0.041 | 0.302 | 0.020 | -0.076 | 0.266 |
| lgbm | baseline | 0.041 | 0.307 | 0.050 | 0.403 | 0.013 | -0.116 | 0.188 | 0.037 | 0.220 | 0.046 | 0.278 | -0.015 | -0.164 | -0.269 | 0.024 | 0.178 | 0.041 | 0.301 | 0.056 | -0.062 | 0.781 |
| lgbm | baseline | 0.040 | 0.308 | 0.049 | 0.402 | 0.020 | -0.100 | 0.280 | 0.036 | 0.220 | 0.044 | 0.277 | -0.017 | -0.158 | -0.334 | 0.025 | 0.182 | 0.041 | 0.302 | 0.020 | -0.076 | 0.266 |
| lgbm | baseline | 0.040 | 0.308 | 0.049 | 0.402 | 0.020 | -0.100 | 0.280 | 0.036 | 0.220 | 0.044 | 0.277 | -0.017 | -0.158 | -0.334 | 0.025 | 0.182 | 0.041 | 0.302 | 0.020 | -0.076 | 0.266 |
| lstm | baseline | 0.047 | 0.370 | 0.058 | 0.467 | 0.085 | -0.104 | 1.031 | 0.039 | 0.213 | 0.044 | 0.246 | -0.016 | -0.176 | -0.258 | 0.031 | 0.238 | 0.043 | 0.313 | 0.070 | -0.069 | 0.885 |
| transformer | baseline | 0.012 | 0.074 | 0.035 | 0.245 | -0.036 | -0.166 | -0.440 | 0.020 | 0.109 | 0.034 | 0.191 | -0.059 | -0.282 | -1.012 | 0.001 | 0.010 | 0.027 | 0.183 | -0.085 | -0.160 | -1.091 |
| anthropic/claude-opus-4.6 | vanilla | 0.048 | 0.360 | 0.059 | 0.464 | 0.073 | -0.093 | 1.213 | 0.032 | 0.162 | 0.044 | 0.233 | -0.016 | -0.199 | -0.259 | 0.031 | 0.242 | 0.048 | 0.363 | 0.087 | -0.032 | 1.247 |
| google/gemini-3.1-pro-preview | vanilla | 0.046 | 0.336 | 0.057 | 0.441 | 0.083 | -0.058 | 1.267 | 0.034 | 0.182 | 0.046 | 0.261 | -0.002 | -0.198 | -0.028 | 0.028 | 0.208 | 0.042 | 0.319 | 0.045 | -0.046 | 0.670 |
| gpt-5.4-pro | vanilla | 0.007 | 0.035 | 0.026 | 0.132 | -0.055 | -0.357 | -0.491 | 0.006 | 0.026 | 0.018 | 0.080 | -0.096 | -0.340 | -1.411 | 0.007 | 0.049 | 0.034 | 0.231 | -0.058 | -0.144 | -0.788 |
| anthropic/claude-opus-4.6 | agent | 0.048 | 0.360 | 0.059 | 0.464 | 0.073 | -0.093 | 1.213 | 0.032 | 0.162 | 0.044 | 0.233 | -0.016 | -0.199 | -0.259 | 0.031 | 0.242 | 0.048 | 0.363 | 0.087 | -0.032 | 1.247 |
| google/gemini-3.1-pro-preview | agent | 0.049 | 0.337 | 0.064 | 0.467 | 0.083 | -0.110 | 1.057 | 0.048 | 0.258 | 0.059 | 0.338 | -0.001 | -0.115 | -0.012 | 0.029 | 0.225 | 0.048 | 0.351 | 0.098 | -0.050 | 1.435 |
| gpt-5.4-pro | agent | 0.040 | 0.311 | 0.051 | 0.411 | 0.032 | -0.098 | 0.464 | 0.033 | 0.195 | 0.043 | 0.256 | -0.028 | -0.180 | -0.518 | 0.023 | 0.161 | 0.041 | 0.291 | 0.017 | -0.071 | 0.224 |