Abstract
Building high-performing models for financial markets is a complex task that requires balancing predictive accuracy with domain-specific intuition and regulatory auditability. Traditional Automated Machine Learning (AutoML) tools often function as "black boxes," while standard Large Language Model (LLM) agents frequently produce unreliable code or lack financial precision. This paper introduces TS-Agent, a modular framework designed to automate the financial time-series modeling pipeline. By utilizing structured knowledge banks and an iterative "reflective feedback" loop, TS-Agent produces models that outperform state-of-the-art AutoML tools while maintaining a fully transparent and auditable development process.
Introduction
Financial time-series modeling is notoriously difficult due to the low signal-to-noise ratio and non-stationary nature of market data. While AutoML has streamlined hyperparameter tuning, it lacks the ability to incorporate qualitative financial heuristics. Conversely, while LLMs show promise in code generation, they are prone to "hallucinations" and often fail to adhere to the rigorous requirements of financial data processing. In high-stakes financial environments, practitioners require more than just a performant model; they need a system that can explain the rationale behind specific architectural choices and refinements.
Methodology: The TS-Agent Framework
TS-Agent formalizes the modeling pipeline into a structured, two-stage decision process that mimics the workflow of a human quantitative researcher.
Stage 1: Model Pre-selection
The framework employs Case-Based Reasoning (CBR) to initiate the modeling process. The agent queries a Case Bank containing successful historical tasks to identify the most relevant model architectures—such as Autoformer or PatchTST—from a curated Code Base. This prevents the agent from starting from scratch, thereby reducing the likelihood of structural errors.
Stage 2: Iterative Code Refinement and Reflective Feedback
Once a base model is selected, the agent enters a "reflective" optimization loop. This stage is governed by a Chain-of-Code Edits approach:
- Edit: The agent modifies the code using a Refinement Knowledge Bank, which contains expert-level strategies for data scaling, learning rate scheduling, and early stopping.
- Execute: The system executes the code, capturing comprehensive logs and performance metrics.
- Reflect: The agent analyzes the execution results. If the loss decreases or performance improves, the change is committed; otherwise, the agent reverts the change and explores an alternative strategy based on the failure logs.
This structured approach ensures that every modification is grounded in empirical evidence and expert knowledge.
Experimental Setup
The TS-Agent framework was evaluated across three distinct financial domains to test its versatility:
- Crypto: Hourly closing prices for 20 cryptocurrency pairs against USDT (2024).
- Exchange: Daily foreign exchange rates for eight major currency pairs (1990–2010).
- Stock: Daily closing prices for 10 major U.S. stocks (2020–2024).
Beyond forecasting, the system was also tested on Time-Series Generation tasks, where the goal was to create synthetic data that preserves the statistical properties of real-world financial markets.
Key Results and Insights
Superior Predictive Performance
TS-Agent consistently outperformed traditional AutoML benchmarks like AutoGluon and other agentic frameworks such as DS-Agent. Notably, it achieved a reduction in Root Mean Squared Error (RMSE) of over 20% on the Exchange dataset and 8% on the Crypto dataset compared to AutoGluon.
Reliability and Success Rates
While many LLM-based agents struggle with code execution consistency, TS-Agent achieved a 100% success rate in producing executable code across various LLM backbones, including GPT-4o and Claude. This reliability is attributed to the framework's use of modular code templates rather than open-ended generation.
Financial Fidelity and Auditability
In backtesting and trading simulations, TS-Agent’s forecasts resulted in risk metrics (such as Sharpe Ratio and Value at Risk) that closely aligned with ground-truth data. Furthermore, the system provides a complete audit trail of its decision-making process, logging the specific rationale for every code adjustment (e.g., "Adjusting weight decay to mitigate observed overfitting in validation logs").
Conclusion and Future Work
TS-Agent demonstrates that structured, agentic workflows can overcome the limitations of both black-box AutoML and unconstrained LLM agents in the financial domain. By constraining the agent with domain-specific knowledge and a reflective feedback loop, the framework achieves high accuracy and total transparency.
Future research will focus on expanding TS-Agent to address tasks such as fraud detection and the integration of multimodal data, enabling the agent to synthesize numerical trends with textual insights from financial news and earnings reports. Additionally, the authors aim to automate the growth of the framework's knowledge banks by allowing the agent to ingest and implement techniques directly from new academic literature.
Summary updated