quant-graph-stock
Quantitative Financeqlibrigorous codebase
Description
Graph-Based Multi-Stock Prediction on CSI300
Objective
Design and implement a graph-based stock prediction model that leverages inter-stock relationships through a stock-concept graph. Your code goes in custom_model.py. Three reference implementations (HIST, GATs, LightGBM) are provided as read-only.
Evaluation
Signal quality: IC, ICIR, Rank IC. Portfolio (TopkDropout, top 50, drop 5): Annualized Return, Max Drawdown, Information Ratio. Automatic via qlib's workflow.
Workflow Configuration
workflow_config.yaml lines 14-26 and 32-45 are editable. This covers the model plus dataset adapter/preprocessor configuration. Instruments, date ranges, train/valid/test splits, and evaluation settings are fixed.
Code
custom_model.py
EditableRead-only
1# Custom graph-based stock prediction model for MLS-Bench2#3# EDITABLE section: CustomModel class with fit() and predict() methods.4# FIXED sections: imports and stock-concept graph loading below.5import os6import numpy as np7import pandas as pd8import torch9import torch.nn as nn10import torch.nn.functional as F11from qlib.model.base import Model12from qlib.data.dataset import DatasetH13from qlib.data.dataset.handler import DataHandlerLP1415DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
workflow_config.yaml
EditableRead-only
1# Qlib workflow configuration for CSI300 graph-based stock prediction benchmark.2# Used by run_workflow.py — matches Alpha360/CSI300 official benchmark settings.3# Alpha360: 6 base features x 60 days = 360 features, flattened as DatasetH.45qlib_init:6provider_uri: "~/.qlib/qlib_data/cn_data"7region: cn89sys:10rel_path:11- "." # So custom_model.py is importable via module_path1213task:14model:15class: CustomModel
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 ↑ |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| gats | baseline | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| gats | baseline | 0.050 | 0.376 | 0.060 | 0.474 | 0.106 | -0.067 | 1.362 | 0.047 | 0.260 | 0.052 | 0.304 | -0.014 | -0.203 | -0.252 | 0.029 | 0.214 | 0.045 | 0.328 | 0.103 | -0.044 | 1.324 |
| gats | baseline | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| gats | baseline | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| hist | baseline | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| hist | baseline | 0.053 | 0.349 | 0.066 | 0.438 | 0.088 | -0.051 | 1.250 | 0.052 | 0.282 | 0.058 | 0.328 | -0.001 | -0.171 | -0.010 | 0.036 | 0.251 | 0.052 | 0.340 | 0.093 | -0.059 | 1.194 |
| hist | baseline | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| hist | baseline | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| lgbm | baseline | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| lgbm | baseline | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| 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.014 | -0.163 | -0.267 | 0.024 | 0.178 | 0.041 | 0.301 | 0.056 | -0.062 | 0.781 |
| lgbm | baseline | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| lgbm | baseline | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| 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 | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| lgbm | baseline | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| 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 |
| anthropic/claude-opus-4.6 | vanilla | 0.044 | 0.297 | 0.060 | 0.419 | 0.045 | -0.091 | 0.585 | 0.044 | 0.223 | 0.057 | 0.301 | -0.014 | -0.196 | -0.229 | 0.037 | 0.283 | 0.048 | 0.361 | 0.116 | -0.053 | 1.441 |
| google/gemini-3.1-pro-preview | vanilla | 0.024 | 0.153 | 0.039 | 0.240 | -0.016 | -0.184 | -0.164 | 0.037 | 0.186 | 0.047 | 0.241 | -0.041 | -0.227 | -0.656 | 0.028 | 0.206 | 0.047 | 0.329 | 0.075 | -0.085 | 0.938 |
| gpt-5.4-pro | vanilla | 0.031 | 0.229 | 0.041 | 0.303 | 0.008 | -0.116 | 0.121 | 0.027 | 0.149 | 0.039 | 0.204 | -0.048 | -0.200 | -0.864 | 0.020 | 0.140 | 0.037 | 0.249 | 0.030 | -0.061 | 0.448 |
| anthropic/claude-opus-4.6 | agent | 0.045 | 0.348 | 0.057 | 0.413 | 0.037 | -0.098 | 0.478 | 0.037 | 0.210 | 0.049 | 0.259 | 0.003 | -0.210 | 0.043 | 0.012 | 0.077 | 0.040 | 0.252 | -0.031 | -0.096 | -0.389 |
| google/gemini-3.1-pro-preview | agent | 0.049 | 0.354 | 0.064 | 0.463 | 0.083 | -0.061 | 1.239 | 0.034 | 0.176 | 0.049 | 0.257 | -0.045 | -0.232 | -0.770 | 0.034 | 0.266 | 0.051 | 0.366 | 0.033 | -0.061 | 0.517 |
| gpt-5.4-pro | agent | 0.034 | 0.266 | 0.039 | 0.325 | 0.021 | -0.146 | 0.261 | 0.037 | 0.199 | 0.039 | 0.217 | -0.016 | -0.162 | -0.289 | 0.018 | 0.129 | 0.035 | 0.257 | 0.041 | -0.078 | 0.481 |