Building a Personal Trade Blotter Backtesting System with an LLM: A Practical Field Log
This article documents a hands-on project in which an AI coding assistant was used to build a complete backtesting analysis system for personal historical trade records, from data extraction and market data ingestion to database storage. It covers how to decompose a long-chain engineering task into manageable steps, how to design effective prompts (including the exact prompt used for data fetching), and the reusable lessons learned: convert Excel files to Markdown before analysis, require observable progress in prompts, design re-runnable tasks to handle model freezes, and manually verify every result. The piece is aimed at developers and investors interested in using LLMs for data-heavy engineering projects.
1. Background and Motivation
Many individual investors share a similar experience: you’ve placed plenty of trades, but you can’t tell whether your profits come from luck or from a repeatable pattern. There’s an old adage in the trading world: “Review your trade records again and again, and build your own trading style.” But a trade blotter is usually just a messy Excel file, and it’s nearly impossible to draw objective conclusions from it by eye.
So I set myself a small goal: take historical trade records, run them through historical market data in a full backtest, and produce an objective report. This was also a good opportunity to test whether an AI coding assistant can handle a long-chain engineering task end to end. Conveniently, I still had some leftover API credits from a previous top-up, so I used those to power the experiment.
The conclusion first: the project did run through its full pipeline successfully, but along the way it exposed several typical problems of LLMs on long-running tasks—at one point I seriously wondered whether the whole thing was about to collapse. The rest of this article walks through the process and methods in detail.
2. Overall Planning: Nail Down the Workflow Before Letting the Model Work
2.1 Why “Dumping the Whole Requirement at Once” Loses Control
My old habit was to throw the entire requirement at an LLM in one go: “Build me a backtesting system—fetch data, compute indicators, generate a report.” The result was usually code that looked complete on the surface but failed in practice: poorly normalized databases, mismatched field names, cascading errors, and ultimately more rework than it saved.
The empirical lesson: for transactional, multi-step, personalized tasks, figure out the workflow first, then drive the model through it step by step. I split this project into three steps:
- Extract the list of ticker symbols from the trade blotter, and manually verify it.
- Fetch daily and intraday market data via a market data API and store it in a database.
- Run a historical backtest against the trade records and generate an analysis report.
I confirmed the result of each step before moving to the next; the model was only responsible for implementing the current step.
2.2 Key Technology Decisions
- AI coding assistant: an AI-powered IDE with a locally configured LLM for code generation and debugging.
- Data storage: a local relational database, chosen because the data would be read repeatedly and new indicators added over time. The schema had to be normalized and extensible.
- Market data source: I had API documentation and credentials from a data service platform. The prompt explicitly instructed the model to prioritize this interface, and referenced the local documentation path.
3. Step One: Preprocessing the Trade Blotter
3.1 Why Not Feed Excel Directly
Trade blotters exported from brokerage software are Excel files. In earlier experiments, I found that models often failed to read all the data from Excel—I suspect that when the model calls code to parse the files, it handles merged cells and non-standard headers poorly.
This time I followed a practice widely recommended in the community: first convert the spreadsheet to Markdown, then hand it to the model. Existing open-source tools can do this conversion, restoring the sheet into structured text row by row. The model’s comprehension improved noticeably.
I can’t paste my real trade blotter here; suffice it to say the data was painful to look at—which is exactly why the backtest matters.
3.2 The First Task: Extracting the Ticker List
The prompt I gave the model was deliberately minimal: only deduplicate and summarize the tickers appearing in the blotter, and output a clean list. The model finished quickly. After I manually verified the list, we moved to step two. This “small steps, frequent checkpoints” rhythm was the key to keeping the project from spiraling out of control.
4. Step Two: Fetching Market Data and Persisting It
4.1 The Design of the Key Prompt
This was the most valuable prompt-engineering practice of the whole project. My prompt contained five elements:
- Goal statement: this is step one of a stock trading backtest analysis system.
- Input specification: use the ticker list confirmed in the previous step.
- Resource pointer: provide the path to the local API documentation (which contains the credentials) and instruct the model to prioritize that interface.
- Storage requirements: the database must be built properly—normalized and extensible—no improvised shortcuts.
- Observable progress: the fetch process must continuously report progress so I can monitor what it’s doing.
Here’s the prompt:
I'm building a stock trading backtest analysis system. As the first step,fetch the daily and intraday data for all the stocks listed above:use the confirmed ticker list as the target universe, refer to the localAPI documentation, and store the results in a local database (the schemamust be well designed, normalized, and extensible).While fetching, continuously report concrete progress so I can followthe execution status.
4.2 Execution and a Typical Problem
Code generation and initial execution were fairly fast, and the model reported progress as agreed. But there was one clear stability problem: at a certain step the model would freeze, producing no output for a long time. My workaround was to manually pause the current session and re-issue the execution; it usually got past the sticking point quickly.
The general strategies for handling this kind of issue:
- Break long tasks into shorter ones so you can resume from the most recent confirmed checkpoint instead of starting over.
- Require the model to emit intermediate artifacts (such as table-creation scripts) and persist them to files, so a restart only needs to “continue” rather than “redo.”
- Don’t paste documents containing credentials or tokens directly into the conversation; reference them by path. It’s safer and keeps the context from bloating.
5. Reusable Methodology
Looking back at the project, several lessons generalize to any scenario where you build a data-oriented system with an LLM:
- Decomposition before generation. Draw the workflow yourself first, then drive the model one step at a time, confirming each step manually.
- Data preprocessing before analysis. Convert unstructured files into model-friendly formats first; this dramatically reduces data-misreading errors.
- Observable progress is a hard requirement. Forcing the model to report progress in the prompt is both a debugging aid and a quality constraint.
- Accept stability fluctuations as reality. Freezes and interrupted output are common in today’s long-running tasks; design tasks to be re-runnable to absorb them.
- Objectivity is the bottom line for backtesting. Data analysis feeds real investment decisions, so manually verify every result—never blindly trust model output.
Next, I plan to build on the stored data by computing holding-period statistics, win rate, drawdown, and related metrics, and to complete the report-generation module. If this series continues, I’ll share the details of the indicator layer.
6. Final Thoughts
The biggest gain from this experiment wasn’t the backtest report itself—it was validating a working mode: treat the LLM as a highly capable intern who needs to be managed. Give it clear boundaries, explicit checkpoints, and observable processes, and its output quality will far exceed the “dump one big requirement and wait for results” approach. As for how capable the specific model version is, the answer is hidden in the process: it gets the work done, but only if you build the scaffolding for it.
