Engineering LLMs for Production: A Trading Data Backtesting Project to Evaluate Model Capabilities

    This article walks through a hands-on engineering experiment that uses trading data backtesting to test what a newly released large language model can actually do. It presents a reusable workflow covering input normalization, task decomposition, API-first data ingestion with credential security, layered storage design, observability, and quantitative model evaluation. Readers will find practical engineering advice, sample Python and SQL snippets, and four reusable dimensions for objectively assessing a new model's instruction following, long-chain stability, correctability, and output verifiability.

    1. Background: A Real Engineering Experiment Driven by Leftover Trial Credits

    Many developers have had a similar experience: a small trial balance sits in an account, and when a new model is released, it becomes a convenient way to build a small but end-to-end project to test “what it can actually do.” The value of such an experiment is not a surprising conclusion, but the fact that it covers every stage of real engineering work: input cleaning, task decomposition, external data ingestion, persistence, progress observability, and result review.

    This article abstracts that kind of experiment into a general pattern: use real business data as input, build a reproducible backtesting and analysis system, and observe the model’s capability boundaries along the way. To avoid tying the discussion to any specific product, the text uses neutral terms such as “a certain large model,” “an AI coding tool,” and “a market data API.”

    2. Input Layer: Turning Human-Readable Material into Model-Parseable Format

    Raw material usually comes from exported files produced by trading software, mostly in spreadsheet format. When a model reads spreadsheet files directly, common problems include misaligned rows and columns, lost merged cells, and numeric values recognized as text, which eventually leads to “reading part of it and missing part of it.”

    A more reliable approach is to run a format normalization step first, converting the spreadsheet into a clearly structured, plain-text-based markup format. This brings three benefits:

    1. Reduced parsing ambiguity: plain-text structures are friendlier to models, with clear field boundaries.
    2. Easier manual spot checks: after conversion, you can quickly browse the first several rows to confirm headers and data types.
    3. Version control friendly: text formats are easy to put under version management, making it possible to trace “which input was used for which analysis.”

    Example flow:

    1. exported spreadsheet -> format normalization tool -> structured text -> manual header check -> analysis pipeline

    Engineering advice: after normalization, add a “field dictionary” step that defines the meaning, unit, time granularity, and missing-value handling for each column. Without this step, every later statistical conclusion rests on implicit assumptions.

    3. Task Decomposition: Why a “One-Sentence Requirement” Easily Gets Out of Control

    A recurring lesson in practice is that handing a complete requirement to the model all at once often produces uncontrollable output, especially for personalized, strongly constrained tasks. A more reliable way is to think the workflow through yourself first, then dispatch it step by step, with a verifiable acceptance point at each step.

    Recommended decomposition order:

    • Step 1: Entity extraction. Extract the list of instrument names from the input material, and have a human confirm it before moving on.
    • Step 2: Data ingestion. Pull the required historical data at the needed granularity for each instrument.
    • Step 3: Storage setup. Establish a well-structured, extensible local data layout.
    • Step 4: Metric calculation and backtesting. Compute on controlled data, avoiding fetching and calculating at the same time.
    • Step 5: Report generation and review. Output conclusions and keep intermediate artifacts for traceability.

    This “small steps, fast iteration, with human checkpoints” mode essentially converts uncontrollable free generation into a controllable engineering pipeline.

    4. Data Ingestion Layer: API First and Credential Security

    For data acquisition, preferring a mature market data API over web scraping is a general best practice. APIs are more explicit about field definitions, rate limits, and error codes, which makes retries and throttling easier to implement.

    Credential security deserves special emphasis: API documentation often contains access tokens. Such files should not be pasted wholesale into a prompt, nor committed together with the code. A better approach is to inject them via environment variables or a local configuration file, and keep only field descriptions in the documentation.

    1. import os
    2. TOKEN = os.environ["DATA_API_TOKEN"] # Credential injected from the environment, never hard-coded
    3. BATCH = 50 # Fetch in batches to control per-request load

    At the same time, three basic capabilities should be implemented: retry on failure (exponential backoff), incremental updates (continue pulling by time range), and fetch logs (recording instrument, range, status, and elapsed time).

    5. Storage Layer: Prioritize Structure and Extensibility

    Behind the sentence “store the data in a local database” lie many design trade-offs. A practical principle is: separate the raw layer from the processed layer.

    • Raw layer: saved by data source and fetch batch, with no cleaning, so it can be recomputed.
    • Standard layer: unified field naming, unified time and time zone, and unified adjustment convention.
    • Feature layer: stores metrics and intermediate backtesting results, which can be rebuilt at any time.

    Example table structure:

    1. CREATE TABLE daily_bar (
    2. symbol TEXT NOT NULL,
    3. trade_date DATE NOT NULL,
    4. open NUMERIC,
    5. high NUMERIC,
    6. low NUMERIC,
    7. close NUMERIC,
    8. volume NUMERIC,
    9. adjust_type TEXT NOT NULL,
    10. PRIMARY KEY (symbol, trade_date, adjust_type)
    11. );

    A composite primary key and an explicit adjustment identifier prevent subtle errors later, such as “two prices for the same date.”

    6. Observability: Making the Process Visible

    The requirement “I want to see the actual progress” is in fact a dividing line for engineering maturity. Observability includes at least three layers: task-level progress (completed instruments / total instruments), data-level checks (row counts, null rate, time coverage), and exception-level alerts (consecutive failures, missing fields).

    A lightweight implementation is structured logging plus a progress callback:

    1. def on_progress(done, total, symbol, rows):
    2. print(f"[{done}/{total}] {symbol} rows={rows}", flush=True)

    With these three layers of information, when something goes wrong you can quickly tell whether it is API throttling, a field change, or a local write failure, instead of a vague “it just won’t run.”

    7. Capability Evaluation: How to Objectively View a New Model

    Back to the original question: how do you evaluate a newly released large model? Based on this practice, here are four reusable evaluation dimensions.

    1. Instruction following: whether it strictly follows the given path, the given API, and the given storage scheme, rather than improvising.
    2. Long-chain stability: whether it experiences long periods of unresponsiveness, a kind of “fake hang,” in multi-step tasks that requires manual interruption and retry. This is more common right after a model is released and server load is high. It is an important indicator of engineering usability and should be evaluated separately from “generation quality.”
    3. Correctability: whether it can return to the right track after an error based on brief feedback.
    4. Output verifiability: whether it proactively produces intermediate results that can be spot-checked, rather than only giving a conclusion.

    It is worth noting that a single experience is not enough to support a conclusion. A reasonable approach is to prepare a fixed task set, record success rate, average elapsed time, and number of manual interventions, and form a comparable baseline.

    8. Conclusion and Extensions

    The most valuable output of this experiment is not a particular conclusion, but a transferable way of working: normalize the input first, then decompose the task, prefer APIs for data acquisition, store data in layers, keep the whole process observable, and finally use a fixed task set for quantitative evaluation.

    To productize this workflow, you can further introduce containerized execution, a task queue for concurrent fetching, object storage to archive raw files, and logging services with monitoring and alerting for anomaly detection. The tech stack can be replaced, but the methodology stays the same: constrain the model’s free generation capability within the deterministic boundaries of engineering. That is the real path for large models to enter production environments.