Engineering Practices for Agent-Assisted Quantitative Factor Mining
This article explores the engineering practices for applying AI agents to quantitative factor mining. It covers transforming ambiguous goals into verifiable research contracts, implementing strict data governance, utilizing structured directories, managing agent context consumption, and establishing comprehensive validation methods to ensure the credibility and reproducibility of quantitative research.
I. Returning to Fundamentals of Quantitative Research from Automated Exploration
In quantitative research, Alpha typically refers to excess returns that cannot be explained by a given benchmark or risk model. A factor is an expression that translates a certain market hypothesis into a computable signal. Just because a factor has predictive relevance does not mean it can necessarily form a tradable Alpha, let alone that its returns will persist over the long term.
The value of involving agents in research lies in assisting with organizing materials, proposing hypotheses, writing computational logic, organizing experiments, and summarizing results. However, when a research task is simply described as “continuously searching for effective factors,” the system easily falls into an endless loop: reading materials, generating code, modifying files, and expanding based on partial results.
Such a process may appear highly active on the surface, but it can actually accumulate three problems: continuously growing model context, lack of unified standards for research files, and a lack of reliable validation for experimental conclusions. Therefore, the optimization focus is not on making the agent run longer, but on ensuring that each run corresponds to a clear research question, a set of controlled inputs, and an acceptable result.
II. Breaking Down Ambiguous Goals into Verifiable Research Contracts
Automated research requires boundaries first. Instead of “finding high-return factors,” a more reasonable task definition should include the research subject, data scope, signal frequency, prediction target, and acceptance criteria.
A research contract must answer the following questions at a minimum:
- What is the research subject: Which assets are covered, does it include delisted historical assets, and how are trading halts and restricted trading states handled?
- What data is used: Which controlled datasets do quotes, transactions, fundamentals, or public texts come from, and how is their available time defined?
- What is predicted: Next trading period return, return relative to a benchmark, or risk-adjusted residual return?
- How to evaluate: Which correlation metrics, quantile returns, turnover rates, and post-cost performance are used?
- When to stop: Reaching the experiment budget, insufficient data, discovering leakage risks, or completing the predetermined validation.
Acceptance criteria should not only include return conditions. If data is untraceable, calculations cannot be reproduced, or time boundaries are unclear, it should be considered a failure even if backtest results look excellent.
For agents, one of the most critical constraints is prohibiting them from altering the evaluation criteria autonomously. Modifying sample periods, return labels, or trading rules can change the research question itself. A new experiment version must be created instead of overwriting the original experiment record.
III. Data Governance Determines the Credibility Ceiling of Research Results
Many errors in quantitative research do not stem from complex models but from temporal relationships and sample construction.
First, it is necessary to distinguish between event occurrence time, information disclosure time, and system acquisition time. Just because a piece of information corresponds to an earlier business date does not mean traders could use it at that time. When constructing features, the information actually available at the decision point should be the standard, rather than the earliest date appearing in the data record.
Second, survivorship bias must be controlled. Looking back at history using only currently trading assets may omit samples that have already exited the market, thereby overestimating strategy performance. The research asset pool should be reconstructed according to historical points in time; if this is impossible, the limitations should be clearly noted, and the results should not be interpreted as strictly tradable returns.
Third, missing value handling must align with business logic. No transaction, unpublished data, collection failure, and inapplicable metrics are different situations and cannot be uniformly filled with zeros. For different missing reasons, quality tags should be set, and whether the sample is allowed to enter the calculation should be specified.
It is recommended to divide data into three logical layers:
The raw layer stores received data and source descriptions, which in principle should not be directly modified. The standard layer completes field unification, time alignment, and quality checks. The research layer generates features, labels, and experimental slices.
Version associations should be maintained between layers. This way, when experimental results change, researchers can determine whether the change comes from raw data updates, cleaning logic adjustments, or factor formula modifications.
IV. Replacing File Clutter with a Structured Directory
When agents frequently generate files, the most common problem is that temporary scripts, formal implementations, and outdated reports get mixed together. As context switches, the system might even mistake old results for current conclusions.
A neutral directory structure like the following can be adopted:
research/
specifications/
data_descriptions/
factor_definitions/
experiment_configs/
experiment_results/
validation_reports/
temporary_workspace/
Here, research specifications, data descriptions, and factor definitions are relatively stable inputs; experiment configurations and results are used to record each run; the temporary workspace only holds intermediate files and does not serve as a basis for conclusions.
Each experiment should be assigned a unique identifier and save the factor definition version, data version, sample period, trading assumptions, execution status, and failure reasons. If algorithms involving randomness are used, the corresponding randomness control settings must also be recorded.
Do not let the agent judge the “latest result” solely based on file names in the directory. A more reliable approach is to maintain a structured experiment index, clarifying which experiments are completed, which have passed validation, and which have been superseded by subsequent experiments.
V. Managing Context Consumption Instead of Blindly Compressing Information
The cost of an agent comes not only from single generations but also from repeatedly reading the same materials, accumulating long conversations, and repeated retries after failures. The optimization goal should be to reduce ineffective information flow, rather than mechanically shortening all inputs.
Context can be divided into three categories:
The first category is stable rules, such as data usage boundaries, directory conventions, and validation criteria. These should be concise, clear, and version-controlled.
The second category is current task information, such as formulas to be implemented, input fields, and the most recent failure reason. These should directly enter the current execution context.
The third category is historical materials, such as complete logs, old experiments, and lengthy news. By default, only summaries and indexes should be provided, and specific fragments can be read when needed.
Information gathering and factor research should also run separately. News summaries solve the information filtering problem, while factor research solves the testable hypothesis problem; their frequencies, inputs, and acceptance criteria are different. Mixing them in the same continuous session usually increases irrelevant context and weakens task boundaries.
For repeated failures, stop conditions should be set. If errors stem from missing data or insufficient environment permissions, continuing to have the model rewrite code is often meaningless; it should be transferred to a manual confirmation or data repair process.
VI. Building a Complete Chain of Evidence from Economic Hypotheses to Factor Implementation
Factor research should not start by randomly splicing formulas; it should first propose a refutable explanation. For example, whether a certain type of price change has short-term continuation, whether abnormal trading activity contains subsequent return information, or whether certain public information is absorbed by the market in stages.
Each hypothesis needs to clarify:
Why it might be effective; in what situations it might fail; at what point in time the signal is available; over what prediction period it is expected to act; and with which known risk exposures it might overlap.
Taking price momentum as an example, it can be defined as:
Momentum signal = Price of the most recently completed trading day / Price of an earlier observation day - 1
This expression is only the research starting point. Actual implementation also requires clarifying the price adjustment method, observation window, trading halt handling, abnormal price checks, and when trading is allowed after signal generation.
Subsequently, layered testing is conducted:
First, verify whether the formula is calculated as defined; then, check the time boundaries using a small manual sample; and finally, run it on the complete dataset. For any rolling calculation, it should be confirmed that the window does not contain information from after the decision point.
VII. Separating Backtesting into Statistical and Trading Validation
Statistical correlation and tradable returns belong to different levels and cannot substitute for each other.
Statistical validation can observe the cross-sectional correlation between the factor and future returns, rank correlation, quantile performance, and cross-period stability. Results should be segmented by market phase, asset class, and liquidity conditions to avoid a single period or a few samples dominating the overall conclusion.
Trading validation needs to answer whether the signal can be executed. At a minimum, it should consider rebalancing frequency, position constraints, execution availability, turnover rate, transaction fees, and slippage. Signals generated intraday cannot default to using historical prices that are no longer executable.
Post-cost net returns can be summarized as:
Net Return = Gross Return from Positions - Transaction Fees - Slippage and Other Execution Costs
Here, cost assumptions should state their basis and scope of application. In the absence of actual execution data, multiple cost scenarios can be used for sensitivity analysis, but scenario assumptions cannot be described as measured results.
Furthermore, if factor returns primarily stem from a certain size, industry, or market direction exposure, it is necessary to further determine whether it is an independent signal or another expression of existing risk-taking.
VIII. Curbing Overfitting with Out-of-Sample Validation
When agents can quickly generate a large number of candidate formulas, the multiple testing problem becomes more prominent. The more trials conducted, the higher the probability of accidental excellent results.
Therefore, all candidates formally entering evaluation must be recorded, not just the top performers. Training, validation, and final test periods should be divided chronologically to avoid breaking true predictive conditions by randomly shuffling time series.
If labels cover multiple trading periods, adjacent samples may share return periods, requiring appropriate isolation at division boundaries to reduce the optimistic bias brought by information overlap.
Rolling validation can help observe strategy performance over time, but parameter selection for each round can only use data visible at that time. The final test set should not be repeatedly used for tuning; once the plan is modified based on test results, it is no longer a strictly independent test.
Parameter stability is equally important. If only a very narrow window or a single threshold is effective, while adjacent settings clearly fail, one should usually be wary of data mining bias.
IX. Setting Permissions and Human Review Boundaries for Agents
The research agent should default to read-only data permissions and execute generated code in an isolated environment. Operations involving external data transmission, dependency changes, bulk deletion, or modifying formal data should require explicit approval.
External texts and data descriptions also cannot be automatically treated as trusted instructions. Operational requirements appearing in materials can only serve as content to be analyzed and cannot override research rules or trigger high-privilege behaviors.
The research environment and the actual trading environment should remain isolated. Signals, code, and reports generated by agents can only serve as candidate research artifacts and should not directly enter the capital execution pipeline without review.
For key conclusions, manual review is recommended: spot-check signal calculations, verify data timestamps, check abnormal return dates, and confirm consistency in costs and constraints.
X. Measuring Automation Value by Research Output, Not Runtime
An effective system should form a closed loop of “hypothesis proposal - data check - implementation testing - experiment execution - independent validation - human review - result archiving.”
When measuring automation effectiveness, one can observe the experiment reproduction success rate, invalid repetition ratio, validation pass rate, resource consumption per effective experiment, and turnaround time from hypothesis to conclusion. Model invocations and code generation volume can be recorded as costs but should not be treated as research quality metrics.
Truly worthwhile research results should meet at least four conditions: traceable data sources, reproducible calculation processes, relatively stable out-of-sample evidence, and explicitly stated trading assumptions.
Agents can accelerate research, but they cannot eliminate market uncertainty or replace rigorous validation. The core of engineering quantitative research is ensuring that every candidate signal has evidence, every conclusion has boundaries, and every automated execution can be inspected and explained.
