Skip to main content
Back to Tutorial
AdvancedCNML15 min readUpdated 2026-02-11

LightGBM Factor Stack · CSI 300

Gradient-boosted nonlinear factor interactions on A-shares, with proper walk-forward validation and turnover caps. A working production ML template.

Most "ML in quant" tutorials are data leakage with extra steps. This template shows the validation discipline that separates a deployable model from a cherry-picked backtest.

Fork the template to follow along:
TemplateCNML
LightGBM Factor Stack · CSI 300

GBDT factor stack, walk-forward on CSI 300

Sharpe
1.67
Return
+22.1%
Max DD
−14.1%
Forks
54

Why this works

Tree-based models capture nonlinear interactions between factors that linear Fama–French style regressions miss — for example, the interaction between accrual quality and momentum in A-shares. Walk-forward training is the key discipline: fitting once on the whole history leaks future information. Turnover cap is what turns a paper strategy into something deployable with 15 bp round-trip costs.

Common pitfalls

  1. Training on the full history at once. Even with cross-validation, temporal leakage destroys out-of-sample Sharpe.
  2. Forgetting the T+1 rule on A-shares. Same-day close-to-open fills are illegal; your backtest must respect it.
  3. Letting turnover run free. Without the cap the model wants 600% yearly turnover; nobody pays for that edge.

Try it yourself

Fork the template into your workspace. The entire configuration — code, parameters, backtest window, cost model — lands in a new private session. Tweak it, break it, and see how robust the edge actually is.

Backtest result

Sharpe
1.67
Return
+22.1%
Max drawdown
−14.1%
Win rate
+55.2%
Trades
624
Days
500

Equity curve

Strategy
Benchmark

Walk-forward 3y train / 6m test. Top/bottom decile long/short. Cost model: 15bp round-trip for A-shares. Rebalanced monthly.

Ready to learn?

Fork it into your workspace.

The whole template — code, parameters, backtest config — lands in a new private session. Tweak it, run it, break it, learn.