Manuscript Offprint

arXiv:2610.03128

Trading Strategy Optimization via Textual Gradient

Chaoqun Yang, Qian Wang, Fengbin Zhu, Xinyu Lin, Bingsheng He, Roger Zimmermann, Tat-Seng Chua

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Quantitative trading strategy design aims to discover trading programs from historical data that remain effective in future markets, which can be viewed as a black-box program optimization problem. LLM-based textual gradients offer a promising approach by providing explicit optimization directions for iterative strategy refinement. However, directly applying textual gradients faces two challenges: (1) optimization is myopic, underutilizing experience from previous evaluations; and (2) aggregate backtest feedback overlooks temporal robustness, potentially favoring strategies that perform well only in specific market periods. To address these challenges, we propose TradeGrad, an experience-guided textual-gradient framework for robust trading strategy optimization. TradeGrad leverages accumulated optimization experience to estimate textual gradients and employs multi-scale revisions for both strategy exploration and refinement. It further introduces the Cross-Period Robust Objective (CPRO), which emphasizes performance in unfavorable historical periods to promote temporal robustness. Experiments on cross-sectional and time-series strategy design in Chinese A-share and U.S. equity markets show that TradeGrad achieves the best in-sample and out-of-sample performance across all four settings. Notably, its Chinese cross-sectional strategy achieves 27.99% annualized return, 12.19% maximum drawdown, and a Sharpe ratio of 1.63, approximately 68% higher than the CSI 300 benchmark. Further analyses validate the proposed components and show consistent improvements in both in-sample and out-of-sample performance throughout optimization. The code is available at https://github.com/transcend-0/TradeGrad.

1 INTRODUCTION

Quantitative trading strategies are systematic decision rules that map market observations into trading decisions and play an important role in modern investment (Guo et al., 2024). In practice, a strategy is implemented as an executable program that integrates signal construction, entry and exit rules, position management, and risk control (Figure 1(a)). Trading strategy design can therefore be viewed as searching over a vast space of programs (Allen & Karjalainen, 1999). However, unlike conventional program search under a fixed evaluation setting, trading strategy design uses historical market data to discover programs for deployment in future markets, where conditions may differ substantially. The objective is thus to identify strategies whose effectiveness extends beyond historical backtests to unseen future market conditions (Bailey & López de Prado, 2014) (Figure 1(b)).

Traditionally, trading strategies were designed by quantitative researchers through a combination of financial expertise, domain intuition, and extensive empirical experimentation. The substantial expertise and effort required have motivated research into automated strategy design (Allen & Karjalainen, 1999; Lo et al., 2000). Recent advances in Large Language Models (LLMs) offer new opportunities to automate this process by combining code generation with evolutionary search (Novikov et al., 2025; Lange et al., 2026; Yun et al., 2025). Leveraging their prior knowledge of programming and finance, LLMs can generate various strategy code and thereby facilitate the

∗^{*}Corresponding author

(a) Trading Strategy as a Program

(b) Optimization for Generalizable Trading Strategy

Figure

Figure

Figure 1: (a) Trading Strategy as a Program. (b) Optimization for Generalizable Trading Strategy.

exploration of the strategy space. Nevertheless, existing methods rely largely on stochastic mutations, providing limited guidance on how a strategy should be improved and thus requiring extensive search to discover effective refinements.

Textual gradient optimization (Yuksekgonul et al., 2025) offers a more direct paradigm for iterative program refinement. Analogous to numerical gradients, it is defined as a natural-language optimization signal that diagnoses weaknesses in the current program and suggests actionable directions for revision. For example, if a momentum strategy performs well in trending markets but suffers large drawdowns during volatile reversals, a textual gradient may suggest normalizing momentum by recent volatility or requiring stronger trend consistency before entering a position. The LLM can then translate this semantic optimization direction into concrete modifications of the strategy program.

However, directly applying textual gradients to trading strategy optimization is unsatisfactory due to two key limitations. (1) Textual-gradient optimization is myopic. A gradient inferred from the current strategy captures only a narrow view of the strategy space. Earlier successes and failures are easily forgotten, causing redundant exploration and unstable optimization. Moreover, a fixed scale of revision cannot meet the varying needs of the search process: exploring alternative trading hypotheses requires structural changes, whereas refining promising strategies calls for localized edits. (2) Aggregate backtest feedback overlooks temporal robustness. Financial markets are non-stationary, and strategy performance can vary substantially across historical periods (Bailey & López de Prado, 2014; Bailey et al., 2017; Arian et al., 2024). An aggregate backtest score can be dominated by strong performance in favorable periods, even when the strategy performs poorly in others. Textual gradients derived from such feedback therefore direct optimization toward period-specific improvements that fail to generalize across market regimes. Effective optimization requires feedback that explicitly accounts for performance across different historical periods.

To address the above limitations, we propose TradeGrad, an experience-guided textual-gradient framework for robust trading strategy optimization, built around two central ideas. (1) Experience-guided textual-gradient estimation accumulates and reuses knowledge across strategy revisions. TradeGrad maintains a global optimization memory that distills successful and failure patterns from evaluated strategies. To estimate textual gradients, it samples archived strategies with their code and backtest results, providing comparative evidence for effective modifications. TradeGrad further employs multi-scale revisions: structural revisions explore alternative trading hypotheses, while localized code edits refine promising strategies. (2) Cross-Period Robust Objective (CPRO) promotes temporal robustness by evaluating strategies across calendar-year windows. Within each window, CPRO computes a composite score that integrates annualized return, maximum drawdown, and a one-sided penalty for insufficient trading activity. Inspired by Conditional Value-at-Risk (CVaR) (Rockafellar & Uryasev, 2002), CPRO aggregates the lower tail of these window-level scores, emphasizing unfavorable periods rather than allowing a few favorable periods to dominate.

We evaluate TradeGrad on cross-sectional and time-series strategy design in both Chinese A-share and U.S. equity markets. Extensive experimental results demonstrate that TradeGrad not only consistently achieves the highest in-sample (IS) and out-of-sample (OOS) scores among the evaluated strategy-design methods across all four settings but also maintains favorable risk-return trade-offs. Notably, in the Chinese market, its cross-sectional strategy achieves an annualized return of 27.99% with a maximum drawdown of only 12.19% and a Sharpe ratio of 1.63, outperforming the CSI 300 index by about 68% in Sharpe ratio. Ablation studies confirm that all proposed components are essential to TradeGrad's optimization performance. Optimization trajectory analysis shows that Trade-

Grad consistently improves both IS and OOS performance throughout the optimization, whereas compared methods tend to plateau or deteriorate.

The key contributions of this work are summarized as follows:

• We formulate trading strategy design as a black-box program optimization problem, and identify two limitations of applying textual-gradient optimization in this setting: myopic optimization that makes insufficient use of accumulated search experience, and aggregate backtest feedback that overlooks temporal robustness.

• We propose TradeGrad, an experience-guided textual-gradient framework for robust trading strategy optimization. By combining global optimization memory, sampling-based gradient estimation, and multi-scale strategy revisions, TradeGrad enables more efficient strategy optimization.

• TradeGrad introduces the Cross-Period Robust Objective that evaluates strategies across multiple calendar-year windows and emphasizes lower-tail performance, thereby promoting improvements that remain effective across market periods and generalize to unseen markets.

• Extensive experiments on cross-sectional and time-series strategy design in Chinese A-share and U.S. equity markets demonstrate that TradeGrad achieves the best IS and OOS performance among all evaluated methods and maintains favorable risk-return trade-offs. Ablation studies, hyperparameter analyses, and optimization trajectory analysis provide further insights into TradeGrad's effectiveness.

References (36)

  • Reflective prompt evolution can outperform reinforcement learning
  • Using genetic algorithms to find technical trading rules
  • The cross-section of volatility and expected returns
  • Backtest overfitting in the machine learning era: A comparison of out-of-sample testing methods in a synthetic controlled environment
  • The probability of backtest overfitting
  • The deflated Sharpe ratio: Correcting for selection bias, backtest overfitting and non-normality
  • Robust technical trading strategies using GP for algorithmic portfolio selection
  • Simple technical trading rules and the stochastic properties of stock returns
  • Does the stock market overreact? The Journal of Finance, 40(3):793–805, 1985
  • Scaling textual gradients via sampling-based momentum
  • A genetic programming model to generate risk-adjusted technical trading rules in stock markets
  • The high-volume return premium
  • Quant 4.0: Engineering quantitative investment with automated, explainable, and knowledge-driven artificial intelligence
  • Application of evolutionary computation for rule discovery in stock algorithmic trading: A literature review
  • A prompt optimization system based on center-aware textual gradients
  • Returns to buying winners and selling losers: Implications for stock market efficiency
  • ShinkaEvolve: Towards open-ended and sample-efficient program evolution
  • Evolution of heuristics: Towards efficient automatic algorithm design using large language model
  • Foundations of technical analysis: Computational algorithms, statistical inference, and empirical implementation
  • Human-level reward design via coding large language models
  • Technical trading rules in the European monetary system
  • AlphaEvolve: A coding agent for scientific and algorithmic discovery
  • DLPO: Towards a robust, efficient, and generalizable prompt optimization framework from a deep-learning perspective
  • Generating trading rules on the stock markets with genetic programming
  • gradient descent
  • Conditional value-at-risk for general loss distributions
  • Nature, 625(7995):468–475, 2024
  • Grid trading system robot (GTSbot): A novel mathematical algorithm for trading FX market
  • ProFiT: Program search for financial trading
  • Unleashing the potential of large language models as prompt optimizers: Analogical analysis with gradient-based model optimizers
  • LlaMEA: A large language model evolutionary algorithm for automatically generating metaheuristics
  • Large language models as optimizers
  • ReEvo: Large language models as hyper-heuristics with reflective evolution
  • Optimizing generative AI by backpropagating language model feedback
  • QuantEvolve: Automating quantitative strategy discovery through multi-agent evolutionary framework (opens arXiv in a new tab)
  • LLM-guided evolutionary strategy generation for quantitative trading