Recipes

ML multi-factor stock strategy pipeline on VeighNa alpha with Qlib Alpha158 features

From README links · today

Money, Bills & BenefitsResearch & Knowledge

Built an end-to-end ML factor research and backtest pipeline in VeighNa.

What they did

They wanted a repeatable research loop rather than a one-off notebook, so they leaned on VeighNa's vnpy.alpha module, which ships a dataset layer, a model layer, and a strategy/backtest layer. First they configured the dataset component to compute Alpha158-style features — the Microsoft Qlib feature set covering candlestick patterns, price trends, and time-series volatility — over their local historical bar data, registering a couple of custom expression functions for their own factors and applying the built-in missing-value fill, infinity replacement, and cross-sectional standardization steps. Next they used the standardized model template to train three candidates behind one API: Lasso (L1 regularization for feature selection), LightGBM (the workhorse for tabular factor data), and an MLP for nonlinear interactions. They compared validation metrics across the three, then promoted the LightGBM model. Finally they wired the trained model's predictions into a portfolio construction and backtest flow inside VeighNa, checked turnover and drawdown, and ran the strategy in the platform's paper-trading mode against a simulated account before considering any live gateway.

How it went

The pipeline ran end to end: features generated in one call, three models trained and compared on identical splits, and the chosen model backtested with reasonable turnover. Paper trading surfaced a few rough edges — feature computation was slow on the full universe until they cached intermediate frames, and the MLP overfit quickly, which is why LightGBM won. Overall it is a solid research scaffold, not a production trading system.

Worth knowing

Alpha158 is a stock-market feature set; applying it to futures or crypto needs rework. Data quality and point-in-time correctness are on you — lookahead bias in feature computation will silently inflate backtest results. Live trading requires a broker gateway and real risk controls, and VeighNa's docs and community are largely Chinese-language. Nothing here constitutes investment advice.

Wiring

Order matters: data first, then features, then model, then strategy. (1) Install VeighNa 4.x on Python 3.10–3.13 and confirm vnpy.alpha imports. (2) Point the dataset layer at a local historical database (VeighNa's data recorder or a CSV/Parquet loader) and build the Alpha158 feature frame; register custom expression functions before dataset construction so they resolve. (3) Feed the feature frame plus forward-return labels into the model layer's unified API — Lasso, LightGBM, and MLP all share the same fit/predict interface, so swapping is a config change. (4) Pass the trained model's predictions to the strategy/backtest layer for portfolio construction and performance stats. (5) For paper trading, connect the strategy to VeighNa's simulated gateway; a live broker gateway is a separate install and should come only after risk limits are in place. Qlib is the upstream source of the Alpha158 feature definitions, so consult its docs when a factor's formula is unclear.

Try it yourself

Set up an ML factor research pipeline in this repo using VeighNa's vnpy.alpha module. Steps: (1) inspect vnpy/alpha/dataset and configure an Alpha158 feature dataset over the local historical bar data, adding one custom expression function and the standard missing-value/infinity/standardization processors; (2) using vnpy/alpha/model templates, train Lasso, LightGBM, and MLP models on identical train/validation splits and print a comparison table of validation metrics; (3) wire the best model's predictions into a portfolio backtest and report annualized return, Sharpe, max drawdown, and turnover; (4) add a config file so the model choice and feature list are swappable without code edits. Do not modify existing library code — add new files under a research/ directory and show me the diff.

Source

Tools in this stack

Run this stack

Install the stack into this project. It writes AGENTS.md and the manifest, merges the MCP servers into .mcp.json, and — with --yes — runs the tool installs.

npx runchr install runchr/stack-qlib-and-vnpy
No CLI?curl -s https://api.runchr.com/api/recipes/runchr/stack-qlib-and-vnpy/manifest

This stack has no prompt yet. You get the tools and the wiring, not the prompt.

The manifest is also at api.runchr.com/api/recipes/runchr/stack-qlib-and-vnpy/manifest.