A New Paradigm for LLM Evaluation: Backtesting with Brokerage Trade Records
This article presents an engineering approach to evaluating large language models by having them analyze exported brokerage trade records. It covers converting spreadsheet exports into structured text, validating data integrity, breaking complex instructions into verifiable steps, handling API rate limits, designing storage schemas, managing long-running task stalls, and producing reproducible backtest reports. Readers will learn how to treat the workflow as a staged data pipeline rather than an end-to-end model task, and why backtesting should be viewed as hypothesis testing rather than return prediction.
1. The Starting Point: Why Reviewing Trade Records Needs Engineering
Many individual investors share a familiar experience: their accounts swing unpredictably, losses outweigh gains, and post-trade reviews rely on gut feeling, often producing contradictory conclusions. A common piece of industry advice is to repeatedly review your own execution records and extract stable trading patterns from them. But manually scanning hundreds of trade details is slow and prone to selective memory. Treating this as a small data engineering project is what makes the conclusions reproducible.
The workflow has four stages: raw data acquisition, format normalization, data storage, and metric calculation with report generation. Each stage can introduce errors, so each one needs to be validated individually rather than handing the entire requirement to a model for end-to-end completion.
2. Data Preparation: Why Tables Must Be Converted to Structured Text
Trading software typically exports spreadsheet files. Passing a binary spreadsheet directly to a model commonly causes row and column misalignment, loss of numeric precision, or partial data reads, which shifts all downstream statistics.
A more reliable approach is to first convert the file into a structured plain-text format (for example, converting each spreadsheet row into a Markdown table or CSV text) and then pass it to the model. After conversion, check at least three things:
- Whether the row count matches the original export, to avoid truncated trailing records;
- Whether amount, quantity, and fee fields remain numeric types rather than strings with thousands separators or currency symbols;
- Whether date-time values are normalized to a single format, confirming the year is not omitted for cross-year data.
Illustrative validation logic:
import pandas as pddf = pd.read_csv("trades.csv", dtype={"code": str})assert df["date"].nunique() > 0df["amount"] = pd.to_numeric(df["amount"], errors="coerce")assert df["amount"].isna().sum() == 0, "Unparseable amounts found"df["date"] = pd.to_datetime(df["date"]).dt.normalize()
3. Instruction Design: Breaking Long Requirements into Verifiable Steps
Describing all requirements at once often produces code that deviates from expectations, especially for personalized, heavily constrained tasks. A more reliable method is to think the workflow through yourself first, then issue instructions step by step, with a human confirmation point at each step.
The first step does entity extraction only: pull the list of instrument codes involved from the trade records and verify it manually. This step costs very little yet prevents every downstream stage from being built on a wrong instrument pool.
The second step issues the data retrieval task with constraints spelled out: data source priority, the target instrument list, the period granularity to fetch, storage requirements, and a requirement to output progress information. The more specific the constraints, the less rework.
Only the third step moves to metric calculation and report generation. By then the data is already stored and can be re-run at any time, without depending on the model’s memory of prior context.
4. Data Acquisition and Storage: Prioritize a Clean, Extensible Structure
Market data can be obtained through publicly available financial data APIs. Most APIs control call frequency with credit-based quotas, so rate limiting must be handled explicitly: control concurrency, add retries with backoff, mark successfully retrieved records as complete, and support resuming from breakpoints.
For the storage layer, define the schema before writing code, distinguishing at least three tables: an instrument dimension table, a daily bar table, and an intraday bar table, with unified primary keys and indexes.
CREATE TABLE daily_bar (code VARCHAR(16) NOT NULL,trade_date DATE NOT NULL,open DECIMAL(18,4),high DECIMAL(18,4),low DECIMAL(18,4),close DECIMAL(18,4),volume BIGINT,PRIMARY KEY (code, trade_date));
Progress observability matters just as much. Having each step print the current instrument, the number completed, and the failure reason makes it possible to judge the direction in real time and to pinpoint afterward which data segment is missing.
5. Interaction Stability: Handling Stalls and Retries
In practice, models exhibit long stretches of no output during long tasks, a kind of apparent hang; manually aborting and re-running usually restores output immediately. There are three engineering responses: first, shorten the granularity of each task so every run finishes within an acceptable duration; second, convert long tasks into scripted execution, where the model only generates and modifies scripts while the actual retrieval is done by a local program; third, keep complete logs and resume from the logs after an interruption rather than from the context.
6. Metrics and Reports: Making Conclusions Testable
A backtest report should include at least: number of trades and win rate, profit/loss ratio, average holding period, return distribution by instrument and by month, maximum drawdown, and the impact of commissions and stamp duty on net returns. Every metric needs a documented calculation definition, otherwise results cannot be compared across implementations.
It is important to stress that historical backtesting can only verify how a fixed rule set performed in the past and cannot guarantee future effectiveness; with a small sample size, any conclusion may be noise. Treating backtesting as a hypothesis testing tool rather than a return prediction tool is the most important premise of this practice.
