Engineering a Quant Research Agent for A-Share Markets: A Reproducible, Auditable Workflow
This article presents an engineering approach to turning quant research scripts into a runnable, auditable, and regression-testable system. It covers a seven-node DAG architecture with dual rule-based and LLM modes, a three-step announcement sentiment factor pipeline, a six-table persistence design for traceability, and a numeric verification step that constrains report generation. A negative sentiment-factor result is reported as-is, highlighting the value of reproducible validation over parameter tuning.
1. Problem Definition: Why Research Code Rarely Becomes a System
In A-share quantitative research, analysts usually accumulate a set of scripts: data fetching, factor calculation, model training, backtesting, and reporting. These scripts are typically written to “produce a result” and lack three engineering properties:
- Reproducibility: the same input produces different results at different times.
- Traceability: there is no way to answer “which table and which run produced this number.”
- Verifiability: conclusions are hard to validate, especially after introducing an LLM to generate research reports, where the text may read well but the numbers may not match.
This article is therefore not about how strong a particular model is. It addresses a more fundamental question: how to refactor a research workflow into a system that is runnable, auditable, and regression-testable. The system uses a general-purpose technology stack: a scripting language for computation and orchestration, a graph-based workflow engine for node scheduling, gradient boosted trees for structured data modeling, and a client compatible with a common chat API protocol to invoke LLM capabilities. The result is a dual-mode design of “rules + LLM”: rule mode guarantees determinism, while LLM mode handles summarization and expression.
2. Overall Architecture: Seven-Node Orchestration and Dual-Mode Switching
The system abstracts the research workflow into seven nodes forming a directed acyclic graph. Each node does one thing, with structured data as input and output, avoiding a single monolithic function.
- Data ingestion node: pulls market data, announcements, and research report metadata; unifies time zones, adjustment conventions, and field naming.
- Cleaning and alignment node: handles missing values, outliers, and trading halts; aligns by trading day and produces the analysis sample table.
- Factor calculation node: computes basic price-volume factors and announcement sentiment factors.
- Label generation node: builds supervised targets from future returns or quantile labels, with explicit in-sample/out-of-sample splits.
- Model training node: uses gradient boosted trees for cross-validation and prediction.
- Backtest and evaluation node: combines portfolios by layering or weighting, and outputs equity curves and metrics.
- Report generation node: rule mode outputs a fixed template; LLM mode generates interpretive text based on a “fact whitelist.”
Mode switching is configuration-driven. Rule mode is suited to nightly batch jobs that require strict reproduction; LLM mode is suited to interactive scenarios that require natural-language summarization. Both modes share the same intermediate result tables, ensuring that “text” and “numbers” come from the same source.
# Example: unified node interfacedef node(ctx: dict) -> dict:# ctx carries run_id, config, and the previous node's artifact pathdf = load_or_compute(ctx)persist(ctx, df) # persist to six tablesctx["artifact"] = dfreturn ctx
3. Announcement Sentiment Factor: From Text to a Computable Signal
The core of the announcement sentiment factor is not “call an LLM to assign a score,” but splitting text processing into three verifiable steps.
The first step is extraction: extract key sentences from announcement titles and body text, and remove boilerplate (such as “in accordance with relevant laws and regulations”). The second step is scoring: rule mode uses a positive/negative lexicon with a negation window; LLM mode uses few-shot prompts and requires structured labels (such as “positive/neutral/negative”) with a confidence score. The third step is aggregation: compute a weighted average by stock and trading day to obtain the daily sentiment value, then apply cross-sectional standardization and lagging to avoid future information leakage.
It is important to emphasize that the sentiment factor is not inherently effective. The measured results in the original work show a 5-fold average AUC of about 0.5024, an IC of about 0.0086, and a final equity value of about 0.8456; after removing the sentiment factor, the 254-row equity curve shows a row-by-row difference of 0.0. This negative result is valuable: it shows that, on the current dataset and split, the sentiment factor adds no incremental value. Engineering practice should persist such results faithfully rather than repeatedly tuning parameters to “produce” a positive result.
4. Six-Table Persistence and Numeric Verification: Making Conclusions Traceable
The system uses six tables to carry the entire workflow: a run table, a sample table, a factor table, a prediction table, a backtest table, and a report table. The run table records run_id, a configuration hash, and the code version; the sample table records stock, date, label, and split flags; the factor table stores factor values by column; the prediction table stores per-sample cross-validation predictions; the backtest table stores daily holdings and equity; the report table stores generated text and the fact IDs it references.
Numeric verification is a hard constraint in the report generation node. The process is:
- Read metrics such as equity, annualized return, and drawdown from the backtest table.
- Build a “fact whitelist” that allows the report to reference only numbers in the whitelist.
- After the LLM output, compare numbers in the text against the whitelist using regex and a numeric tolerance.
- If they do not match, refuse to publish and fall back to the rule template.
def verify(text: str, facts: dict, tol=1e-6) -> bool:for k, v in facts.items():# Simplified example: real implementation must handle thousands separators, percentages, and roundingif f"{v:.4f}" not in text and abs(float(k) - v) > tol:return Falsereturn True
5. Implementation Recommendations and Boundaries
For implementation, start with a “minimum closed loop”: ingest only one type of data, use two factors, one model, and a fixed-template report, get the six tables and verification working end to end, then expand incrementally. Splits must be strictly time-based; avoid using future data for standardization, and keep cross-validation time-series aware. The LLM should only handle “explanation and summarization,” not “computation and prediction”—this is the key boundary that preserves verifiability.
Overall, the value of this approach is not proving that a particular factor works, but building validation into engineering: reproducible workflows, traceable numbers, verifiable text, and presentable negative results. The conclusions apply only to the current dataset and split; changing the data requires re-validation.
