Evaluating LLM Versions Through a Backtesting Project: An Engineering Practice
This article shows how to compare the high-performance and lightweight versions of a large language model using a personal trade statement backtesting project. It covers data normalization, task routing between the two versions, state-machine workflows, database design, interface adaptation, failure recovery, and verification of generated reports.
1. Problem Definition: Why Use a Backtesting Project to Compare Two Versions
A large language model’s high-performance version should not be judged by whether one chat answer seems smart, or whether one code generation looks impressive. A more reliable method is to place the model in a complete engineering workflow with real data, clear goals, intermediate artifacts, and failure recovery requirements. This article uses a personal trade statement backtesting analysis as the case study. It describes how to use a general method to assess whether each version suits data engineering, code generation, tool calling, and long-running tasks.
The project goal can be summarized in five steps: read personal trading records and clean them into structured data; fetch historical daily and intraday market data for the traded securities; build a local database; generate a backtesting report that identifies metrics such as win rate, profit-loss ratio, holding period, and maximum drawdown; and produce conclusions that can be checked. The task combines spreadsheet parsing, API adaptation, database design, batch processing, exception handling, and report generation. That makes it a useful sample for evaluating LLM engineering capability.
This article discusses a general technical approach and is not investment advice. Evaluation conclusions should not rest on a single run of one model. Instead, build a reproducible task set, a scoring sheet, and a failure log.
2. Converting Trade Statements into Analyzable Text
Trading software usually exports trade statements as spreadsheet files. Passing a spreadsheet directly to a model often causes problems. Multiple sheets may not be read completely, merged cells can shift columns, dates and numbers may be misinterpreted, formulas and formatting may be lost, and long tables may be truncated. A safer approach is to normalize the data first, then convert it into structured text that the model can read and use to generate analysis code.
The normalization steps are:
- Standardize column names, such as trade date, security code, security name, buy/sell direction, quantity, trade price, trade amount, commission, and stamp duty.
- Standardize data types. Convert dates to a standard date format, convert amounts and quantities to numeric values, and map buy/sell direction to enumerated values.
- Keep original validation records, such as the file hash, row count, and total amount, so results can be traced back to the source.
- Convert the data to structured text, such as a Markdown table or one JSON object per row. This keeps field meanings clear and makes the data easy for the model to read.
- Mask sensitive data. Remove or hash account numbers, names, and similar fields before they reach the model.
The value of this step goes beyond making the data readable for the model. It turns an unpredictable file parsing problem into a data cleaning problem that can be tested. Whether the high-performance or lightweight version runs the later steps, stable input quality improves the results.
3. Dividing Work Between the Lightweight and High-Performance Versions
In a real project, the high-performance and lightweight versions do not simply replace one another. A better strategy routes each task by its complexity, batch size, latency requirements, and cost of failure.
The lightweight version suits batch field extraction, format conversion, simple script generation, unit test sample generation, first drafts of interface probing scripts, log classification, and repetitive data validation. These tasks have clear input and output boundaries, are sensitive to cost, and can be retried quickly.
The high-performance version suits overall solution design, complex SQL and backtesting logic review, refactoring across files, root cause analysis of errors, aligning data dictionaries over long contexts, and reviewing report conclusions. These tasks need stronger planning and reasoning. A single failure is expensive, so call this version at key checkpoints.
Engineers can also add manual confirmation points. For example, have the model output only a list of security names or a field mapping first, then have a person confirm it before the next step. The original experience is that listing every requirement in one prompt tends to lose control. A safer approach is to split the work into a state machine: parse the trade statement, confirm the security list, probe the market data interfaces, build the database, fetch data, verify completeness, run the backtest, and generate the report. Each state has defined inputs, outputs, acceptance criteria, and a rollback strategy.
4. Step-by-Step Prompts and State Machines
In long workflows, a model can appear to be running while making no actual progress. Common causes include waiting on tool calls, interrupted streaming output, external API timeouts, context drift in very long tasks, and server-side rate limits. When a manual pause and rerun quickly restores progress, the task state was not saved, so rerunning costs more than it should.
Organize each prompt as role, goal, inputs, constraints, output format, and acceptance criteria. Require the model to output an executable next step. For example:
- Step 1: Extract a deduplicated list of securities from the trade statement. Output a table only, with no code.
- Step 2: Based on the security list and the market data API documentation, generate a script that checks interface availability.
- Step 3: Based on the probe report, design the database tables. Output the table definitions and field descriptions.
- Step 4: Fetch data in batches. For each batch, report the number of successes, failures, and retries.
Also maintain a task status table. Record the task ID, stage, checkpoint, processed securities, failure reasons, and retry count. Use idempotent upserts for all writes so that reruns do not create duplicate data. For external interfaces, set timeouts, exponential backoff retries, and failure isolation. With these controls, the workflow can resume from a checkpoint even if the model or a tool is interrupted.
5. Database and Interface Adaptation: Standardized, Extensible, and Observable
The local database design should focus on extensibility and verifiability. At a minimum, include tables for securities, the trading calendar, daily bars, intraday bars, tasks, interface tests, and data quality. In the daily bar table, use security, trade date, and frequency as the unique key, and store a summary of the raw response along with the ingestion time. Partition intraday data by date or write it in batches. The task table records progress. The interface test table records each interface’s availability, response time, and error codes.
Illustrative table definitions:
CREATE TABLE daily_bar (symbol VARCHAR(32) NOT NULL,trade_date DATE NOT NULL,freq VARCHAR(16) NOT NULL,open_price DECIMAL(18,4),high_price DECIMAL(18,4),low_price DECIMAL(18,4),close_price DECIMAL(18,4),volume DECIMAL(24,4),amount DECIMAL(24,4),ingest_time TIMESTAMP,PRIMARY KEY (symbol, trade_date, freq));CREATE TABLE ingest_task (task_id VARCHAR(64) PRIMARY KEY,stage VARCHAR(32),symbol VARCHAR(32),status VARCHAR(16),retry_count INT,message TEXT,update_time TIMESTAMP);
For market data interfaces, use three parts: a local copy of the interface documentation, a probe report, and an adapter layer. Organize the documentation as local text files. Generate a probe script for each interface, and record the usable interfaces, required parameters, rate limit notes, and sample failures. Business code should depend only on a unified adapter interface, which makes it easier to replace the data source. Progress should be visible. For each security processed, report the number handled, successes, failures, current stage, and estimated remaining work.
6. Exceptions and Apparent Hangs: Timeouts, Retries, and Idempotency
When comparing the two versions, stability matters as much as capability. For each task type, record the first-attempt success rate, average retry count, number of manual interventions, end-to-end duration, and cost per task. When a task appears to hang, do not blame the model by default. Separate the causes: network issues, tool calls, external interfaces, long contexts, and truncated output. Engineering countermeasures include per-step timeouts, retry limits, checkpoint resumption, idempotent writes, a failure queue, manual confirmation points, and log tracing.
7. Backtesting Report and Evaluation Metrics
The backtesting report should include data completeness checks, trading pattern statistics, win rate, profit-loss ratio, average holding period, maximum drawdown, sensitivity to fees and slippage, out-of-sample validation, and a statement of limitations. After the model generates the report, verify the key figures with an independent script. To evaluate models, track metrics such as the code run rate, data validation pass rate, report verification rate, and recovery success rate after exceptions.
8. Conclusion: Routing Between Two Versions Instead of Choosing One
Overall, the high-performance version is better suited to complex planning, code review, and error diagnosis. The lightweight version is better suited to batch extraction, format conversion, and low-cost trial and error. Project success depends less on a single model response than on whether the team breaks work into small tasks, saves state, makes interfaces testable, keeps data verifiable, and recovers from exceptions. A practical approach is to use the lightweight version for batch processing and first-pass screening, and the high-performance version to review key checkpoints. Build a reproducible evaluation set alongside this routing to control costs while keeping engineering quality stable.
