LLM-Driven Quantitative Factor Mining: An Evolutionary Search Approach

    This article explains how large language models can automate the hypothesis generation and code drafting stages of quantitative factor research. It presents an evolutionary trajectory search framework, a seven-stage multi-role pipeline, a composite fitness function, and strict overfitting controls, along with practical guidance on cloud architecture and common pitfalls.

    1. Why Traditional Factor Mining Needs a New Paradigm

    The most time-consuming part of quantitative research is often not writing backtest code, but coming up with factors. Researchers propose hypotheses based on market experience, implement them in code, run backtests, and switch directions when results disappoint. This workflow depends heavily on individual experience, limits output speed, and tends to concentrate on a few logics that are already fully priced in, which leads to factor homogenization.

    What large language models change is the “propose a hypothesis” step: it shifts from being labor-intensive to being generated in batches and screened automatically. It is worth stressing that LLMs do not replace backtesting or risk control; what they replace is the enumeration of hypotheses and the production of code drafts. Any factor that has not been validated out of sample has no value in live trading.

    The complete process of a factor, from hypothesis to evaluation, can be treated as a single trajectory. The framework maintains a population of trajectories, ranks them by fitness after evaluation, keeps high-performing trajectories to participate in “crossover,” and eliminates low-performing ones, thereby improving overall quality across multiple rounds of iteration.

    This design has three advantages. First, exploration and exploitation can be balanced, preserving diversity while reinforcing strong directions. Second, the process is traceable: every factor can be traced back to the source of its hypothesis and its modification history. Third, it is naturally parallel, since trajectories are independent of one another and therefore suitable for large-scale concurrent execution.

    3. Core Pipeline: Seven Model Calls with Division of Labor Across Roles

    The key engineering decision is not to have the model output the final factor code in one shot, but to split the work into stages with clear responsibilities, where each stage solves only one problem.

    1. Direction decomposition. Given a broad topic (such as the price-volume relationship), the model acts as a senior researcher and splits it into sub-directions that are as orthogonal as possible, for example volume-price correlation, volume anomalies, intraday volatility structure, turnover momentum, and volume distribution patterns. Orthogonality reduces semantic overlap and improves the diversity of the final factor pool.
    2. Hypothesis generation. Under each sub-direction, produce testable hypotheses in batches, each required to include an economic rationale, an expected direction, and failure conditions.
    3. Factor formalization. Convert natural-language hypotheses into explicit mathematical definitions, specifying fields, windows, and normalization methods.
    4. Code implementation. Generate executable computation logic with a unified input/output contract to make batch scheduling easy.
    5. Static review. Check for data leakage, look-ahead functions, division by zero, and missing-value handling.
    6. Backtesting and diagnostics. Compute returns, volatility, drawdown, turnover, decay curves, and stability by year.
    7. Review and mutation. Rewrite hypotheses or parameters based on the diagnostic results to form the next generation of trajectories.

    An illustrative interface contract (pseudocode):

    1. def evaluate(trajectory, data) -> dict:
    2. factor = implement(trajectory) # generate the factor computation logic
    3. values = factor(data) # unified as a [time, instrument] panel
    4. metrics = backtest(values, data) # returns, drawdown, turnover, IC
    5. return {"fitness": score(metrics), "metrics": metrics}

    4. The Fitness Function: What Determines the Direction of Evolution

    If annualized return is used as the fitness measure alone, the model will quickly converge on fragile factors with high turnover and high volatility. A more robust approach is a composite score:

    • Out-of-sample performance carries more weight than in-sample performance;
    • Penalties are applied for drawdown and volatility;
    • Penalties are applied for turnover and transaction costs;
    • A penalty is applied for correlation with existing factors, to encourage incremental information;
    • Rewards are given for stability across years and across market environments.

    The scoring function should be public, fixed, and reproducible; otherwise the iteration process degenerates into a search for loopholes in the score.

    5. Overfitting Prevention and Validation Discipline

    The fast generation speed of large models amplifies overfitting risk at the same time. Hard rules must be established: split the time series strictly, and use the test set only once at the final stage; set a minimum sample length and a minimum number of instruments; run perturbation tests on parameter sensitivity, and keep only factors whose performance is smooth in the neighborhood; adopt rolling-window validation and observe how fast performance decays. Results such as nearly 28% annualized return with a maximum drawdown under 8% can only be regarded as research-stage metrics when there are no transaction costs, impact costs, or capacity constraints.

    6. Engineering Implementation and Cloud Architecture

    Productionization requires four general capabilities working together: object storage to hold market data and factor panels; a message queue to distribute trajectory tasks; a container platform to carry concurrent backtests; and logging services with monitoring and alerting to track task failure rates and resource utilization. Baidu AI Cloud offers corresponding product categories for all four of these general capabilities, which can be used to build an elastically scaling factor factory.

    On cost control, it is advisable to run batch coarse screening with a smaller model and call a stronger model only for candidates that pass the initial screen; cache the implementation results of identical hypotheses; and cap the maximum number of iterations per trajectory to avoid wasted consumption.

    7. Common Pitfalls

    One is treating model output as a conclusion and skipping independent recomputation. A second is non-orthogonal direction decomposition, which leads to highly collinear factors. A third is scoring on returns only while ignoring capacity. A fourth is the lack of factor library governance, which causes repeated mining. A fifth is ignoring data timestamp alignment and thereby introducing implicit future information.

    8. Summary

    The sensible role of large models in quantitative research is that of a “hypothesis generator and coding assistant”: evolutionary search handles screening, and strict backtesting handles the final judgment. Separating these three layers of responsibility clearly, together with thorough validation discipline and a cloud engineering architecture, is what turns factor mining from a practice driven by individual experience into a scalable and reproducible system capability.