Building an End-to-End AI Quant Trading Pipeline for China's A-Share Market

    This article presents a full-stack architecture for AI-driven quantitative trading in China's A-share market, where T+1 settlement, price limits, suspensions, and policy-driven regime shifts break traditional low-frequency linear factor models. It explains how large language models fit into the pipeline—not as price predictors, but as tools for unstructured information extraction, semantic labeling, hypothesis generation, and code assistance—across six closed-loop modules: data engineering, factor engineering, backtesting, strategy optimization, portfolio construction, and risk control with live execution. Readers will find concrete engineering practices and code skeletons for disclosure-date alignment, five factor admission gates, bias control (look-ahead, survivorship, limit-up/limit-down, T+1, impact cost), walk-forward validation, multi-objective optimization, and a real-time risk interception layer, plus a three-stage rollout path.

    1. Why A-Share Quant Needs a Rebuilt Technical Foundation

    The A-share market differs structurally from mature overseas markets. T+1 settlement prevents intraday round trips from closing, price limits truncate fills during extreme moves, individual stock suspensions break time series continuity, style rotation cycles are short, policy events are strong drivers, and the noise ratio is high. Traditional linear frameworks built around low-frequency multi-factor models are prone to factor crowding and rapid decay. Introducing large language models into this chain adds value not by “letting the model make decisions for humans,” but by filling three gaps in traditional engineering: unstructured information parsing, nonlinear relationship fitting, and end-to-end automated governance.

    The boundary must be stated up front: LLMs do not predict prices. They handle information extraction, semantic labeling, hypothesis generation, and code assistance. The actual source of returns remains rigorously validated factors and risk rules.

    The full pipeline splits into six modules that form a closed loop: data engineering → factor engineering → strategy backtesting → strategy optimization → portfolio construction → risk control and live execution, with feedback data flowing back to the data layer.

    Five core design principles apply: interpretability first, strictly no look-ahead functions, embedded trading-rule constraints, deployability in live trading, and balance between returns and transaction costs.

    2. Module 1: Data Engineering—Unified Governance of Semantics and Structure

    Traditional pain points concentrate on heterogeneous data, a high proportion of unstructured content, mixed missing and anomalous values, and timestamp misalignment that introduces look-ahead bias.

    On the structured side, the engineering focus is unifying timestamp semantics. Every field must distinguish the “reporting period” from the “actual disclosure date,” and factors may only use information available after disclosure. A schematic convention:

    1. # Key: use the disclosure date, not the reporting period, as the availability time
    2. def build_lag(df, field, asof_col="announce_date"):
    3. df = df.sort_values(["ts_code", asof_col])
    4. df[field + "_avail"] = df.groupby("ts_code")[field].shift(1)
    5. return df

    On the unstructured side, the general technical approach is: document parsing → chunking → vector retrieval → LLM extraction → structured storage. Extraction results must carry source location and a confidence score; low-confidence samples go into a manual review queue. Typical outputs include analyst consensus surprise, management tone, intensity of regulatory inquiries, and supply-chain price signals.

    For anomalies and missing values, isolation forest and clustering methods suit outlier detection, while time-series generative models and hybrid temporal networks suit imputation. One iron rule applies: imputation may only use data prior to the sample point, otherwise it is equivalent to manufacturing a look-ahead function. For high-dimensional screening, use tree-model feature importance for a coarse ranking first, then compress with a sparse autoencoder to avoid manual trial and error.

    On the implementation side, a distributed computing framework handles batch cleaning, a feature platform ensures offline/online consistency, object storage keeps raw snapshots, a message queue drives incremental updates, and monitoring alerts report data latency and stream interruptions in real time.

    3. Module 2: Factor Engineering—From Human Hypotheses to Machine Hypotheses

    The core value of LLMs here is hypothesis generation and semantic factor construction. The flow: the model proposes candidate hypotheses based on structured statistical features → factor expressions are generated automatically → they enter a standardized validation pipeline → those that pass are stored.

    Every candidate factor must pass five gates:

    1. Time gate: rolling out-of-window extrapolation; full-sample statistics are forbidden;
    2. Significance gate: joint evaluation of monotonic layered returns and turnover;
    3. Stability gate: variance of performance across market regimes (up/down/range-bound);
    4. Correlation gate: de-duplication against the existing factor library;
    5. Cost gate: still positive after deducting two-sided fees and impact cost.

    A schematic validation skeleton:

    1. def gate_check(factor, price, cost_bps=25):
    2. ic = rolling_ic(factor, price, window=252) # rolling information coefficient series
    3. if ic.mean() <= 0 or ic.std() / (ic.mean()+1e-9) > 0.8:
    4. return False # insufficient stability
    5. turnover = avg_turnover(factor)
    6. net = gross_return - cost_bps * turnover * 2
    7. return net > 0 # cost gate

    4. Module 3: Backtesting and Validation—Caging the Biases

    The engineering focus of the backtest layer is not the equity curve but a bias-control checklist:

    • Look-ahead bias: all features must be obtainable at the decision timestamp; financials aligned by disclosure date;
    • Survivorship bias: the stock pool must include delisted and long-suspended names;
    • Price-limit constraints: no buying at limit-up, no selling at limit-down; matching must be modeled explicitly;
    • T+1 constraint: shares bought today cannot be sold today; the position state machine must track sellable quantity;
    • Impact cost: modeled in segments by share of volume, avoiding small-cap capacity illusions.
    1. def can_trade(bar, side):
    2. if bar.limit_up and side == "buy": return False
    3. if bar.limit_down and side == "sell": return False
    4. if bar.suspended: return False
    5. return True

    For validation, use walk-forward analysis rather than a single split, and keep a fully isolated out-of-sample period. Also run a parameter plateau check: if returns hold only within an extremely narrow parameter range, the result should be judged as fitted noise.

    5. Modules 4 and 5: Strategy Optimization and Portfolio Construction

    The optimization objective should be multi-objective rather than single-objective: balancing expected return, turnover cost, industry and style exposure, and drawdown constraints. The common approach is mean-variance optimization under a risk-model constraint, with a turnover penalty term to suppress overtrading. LLMs can help draft constraints and code, but whether the constraints actually bind must be verified by backtest statistics.

    The portfolio layer must embed A-share rules: per-stock caps, industry deviation caps, automatic reallocation of weights rendered untradeable by suspensions or price limits, and unfilled funds treated as cash.

    6. Module 6: Risk Control and the Live Closed Loop

    Risk control must move forward into a real-time interception layer, not an after-the-fact report. Four lines of defense are recommended: pre-trade limit checks, intraday deviation monitoring, post-trade attribution, and model drift detection. When a factor’s rolling IC decays or a data stream interruption exceeds the threshold, automatically reduce leverage and alert. The only difference between live trading and backtesting should be confined to the execution layer, with signal-generation code fully reused, so that backtest conclusions remain transferable.

    The rollout path is suggested in three stages: first automate the data and factor pipelines, then connect portfolio and risk control, and finally run live trading with small capital in a canary release while continuously feeding trading feedback back. Interpretability, bias control, and cost awareness are the decisive factors for whether AI quant can survive in the long run.