Evaluating LLMs for Quantitative Strategy Development: A Practical Guide to Model Selection and Testing

    Large language models can help write quantitative strategy code, but the right model depends on the task. This article outlines a reusable evaluation framework covering six task types, five scoring dimensions, execution practices such as repeated sampling and automated validation, and recommendations for human-in-the-loop adoption.

    Evaluating LLMs for Quantitative Strategy Development: A Practical Guide to Model Selection and Testing

    Recently, many quantitative developers have begun using LLMs to assist with strategy code. A common question is: “With so many models, which one is better for quantitative strategies?” Rather than give a subjective answer, it is more useful to break the question down: How can we scientifically evaluate an LLM’s real capabilities in quantitative scenarios? This article shares a reusable methodology across three levels: evaluation framework, key capability dimensions, and engineering adoption.

    1. Why You Should Not Rely Only on “Someone Else’s Recommendation”

    Before selecting a model, recognize one fact: LLM performance in quantitative strategy development depends heavily on the specific task. Some models are good at generating clear strategy skeletons; others are more reliable in mathematical reasoning and factor logic; still others perform better in long-context understanding, such as reading large historical backtest logs.

    Therefore, “which model is better” is not a rigorous question. The correct question is: On your typical task set, which model produces higher overall output quality? This also means any horizontal comparison detached from specific tasks has limited reference value. Developers should build a small evaluation set of their own instead of directly trusting one-off experience reports online.

    2. Designing a Reusable Quantitative Evaluation Set

    Scientific evaluation requires a fixed task set. I recommend extracting six task types from a typical quantitative development workflow:

    1. Strategy skeleton generation: Given a natural-language description (e.g., “buy on a double moving-average golden cross, sell on a death cross, add an ATR stop-loss”), ask the model to generate runnable strategy code.
    2. Indicator and factor implementation: Ask the model to implement common technical indicators (e.g., RSI, MACD, Bollinger Bands, volatility factors) and check the correctness of mathematical formulas.
    3. Data processing code: Cover candlestick data cleaning, adjustment for splits and dividends, missing-value filling, rolling-window calculations, and similar tasks; check the model’s understanding of time-series boundaries.
    4. Backtest framework construction: Check whether the model can generate simple backtest logic that accounts for commissions, slippage, and execution constraints, rather than an idealized version with look-ahead bias.
    5. Error diagnosis: Provide buggy strategy code and an error message, and ask the model to locate and fix the issue.
    6. Strategy explanation and improvement suggestions: Ask the model to analyze logical flaws in a strategy, testing its financial common sense and critical thinking.

    For each task, use a fixed prompt, a fixed scoring rubric, and multiple samples averaged together. This reduces the interference caused by model output randomness.

    3. Key Capability Dimensions: How to Score

    I recommend scoring quantitative code generation across five dimensions, each on a 1-5 scale.

    1. Mathematical and Logical Correctness

    This is the most important must-pass criterion. Check whether the model’s indicator formulas are correct. For example, when implementing RSI, common errors include using a simple average instead of a smoothed average, misclassifying gains and losses, and failing to handle division by zero. An effective check is to compare model output with a manually calculated reference:

    1. import numpy as np
    2. def rsi_reference(close, period=14):
    3. """Reference implementation: Wilder-smoothed RSI for validating model-generated code"""
    4. delta = np.diff(close)
    5. gain = np.where(delta > 0, delta, 0.0)
    6. loss = np.where(delta < 0, -delta, 0.0)
    7. # Wilder smoothing: first value uses the mean, later values use recursive smoothing
    8. avg_gain = np.zeros_like(gain)
    9. avg_loss = np.zeros_like(loss)
    10. avg_gain[period - 1] = gain[:period].mean()
    11. avg_loss[period - 1] = loss[:period].mean()
    12. for i in range(period, len(gain)):
    13. avg_gain[i] = (avg_gain[i-1] * (period - 1) + gain[i]) / period
    14. avg_loss[i] = (avg_loss[i-1] * (period - 1) + loss[i]) / period
    15. rs = np.divide(avg_gain, avg_loss,
    16. out=np.full_like(avg_gain, np.inf), where=avg_loss != 0)
    17. return 100 - 100 / (1 + rs)

    Any model that gets core formulas wrong should be down-weighted for quantitative use, no matter how fluent its writing is.

    2. Look-Ahead Bias and Data Leakage Detection

    This is a particularly common failure mode in quantitative scenarios. Model-generated code often “unintentionally” uses future data, for example:

    • Normalizing with the mean of the entire dataset instead of a rolling window;
    • Generating a signal from the current day’s close and then executing at that same close;
    • Misaligning indices during factor calculation, causing signals to take effect one candlestick early.

    Evaluation should deliberately include such traps and observe whether the model avoids them proactively. A qualified prompt can explicitly require “do not use any future data,” and you can check whether the model still falls into the trap.

    3. Backtest Rigor

    When asking a model to generate backtest logic, focus on whether it considers:

    • Commissions and slippage;
    • Minimum trading units and capital constraints;
    • The timing between signal generation and execution (T-day signal, T+1 open execution);
    • Warnings about survivorship bias and overfitting risk.

    An illustrative rigorous backtest framework should include the following structure:

    1. def backtest(prices, signals, fee_rate=0.0003, slippage=0.0002):
    2. """
    3. prices: close price series
    4. signals: target position series (generated at T-day close, effective on T+1)
    5. """
    6. positions = np.roll(signals, 1) # Delay signals by one candlestick to avoid look-ahead bias
    7. positions[0] = 0
    8. returns = np.diff(prices) / prices[:-1]
    9. positions = positions[:-1]
    10. turnover = np.abs(np.diff(positions, prepend=0))
    11. cost = turnover * (fee_rate + slippage)
    12. net_returns = positions * returns - cost
    13. equity = np.cumprod(1 + net_returns)
    14. return equity

    If a model-generated backtest lacks these elements, it shows that the model’s understanding of quantitative engineering remains superficial.

    4. Code Engineering Quality

    This includes naming conventions, modularity, exception handling, type annotations, and ease of unit testing. Strategy code eventually enters production, so one-off script-style output has limited value.

    5. Hallucination and Defensive Behavior

    Deliberately ask the model about a nonexistent technical concept (for example, a fictitious indicator name) and observe whether it admits not knowing or confidently fabricates a formula. In quantitative work, a plausible-sounding hallucination is far more dangerous than an error message.

    4. Practical Points for Running Evaluations

    Fix randomness and sample count. LLM outputs are stochastic. Sample each task at least 3-5 times and measure success rate rather than single-run performance.

    Use a unified prompt template. Different models have different prompt sensitivity. Start with a neutral, information-rich prompt as a baseline evaluation, then fine-tune prompts for each model and record upper-bound performance. This separates “model capability” from “prompt engineering capability.”

    Prefer automated validation over manual reading. For strategy code, the best scoring method is to run unit tests and small-sample backtests against reference results. Manual code review can be misled by fluent comments.

    Maintain a failure-case library. Collect typical errors from each model (formula errors, look-ahead bias, hallucinations) into a case library. During later model version upgrades, run regression tests to see whether they improve.

    5. From Evaluation to Adoption: A Reasonable Human-Machine Collaboration Model

    The ultimate purpose of evaluation is to guide usage. Based on extensive practice, I offer several adoption recommendations:

    1. Treat the model as a “junior researcher,” not a “strategy author.” Let it generate drafts, add unit tests, and explain indicator principles, but humans must review the core logic.
    2. Enforce code review and backtest validation. Any model-generated strategy code must pass out-of-sample validation and stress tests against historical extreme market conditions before it can be considered for deployment.
    3. Retest regularly with a private evaluation set. Model versions iterate quickly, and conclusions from three months ago may not apply today. Rerun the evaluation set quarterly.
    4. Pay attention to data compliance and cost. Strategy code and market data often involve sensitive assets. When calling cloud model services, assess data egress risk and use general cloud capabilities such as object storage, logging, and monitoring/alerting for call auditing and usage control.

    6. Conclusion

    There is no standard answer to “which model is better for quantitative strategies,” but there is a standard method for “how to evaluate.” Build a fixed task set, score across multiple dimensions, automate validation, and run regular regressions. This four-step evaluation loop is more valuable than any single horizontal comparison. Model capability boundaries keep changing, and a rigorous evaluation methodology lets developers keep control of model selection.

    I hope this framework helps you upgrade from blind testing—“I’ll try whatever others recommend”—to data-driven, scientific model selection.