Reproducing Research Report Indicators and Strategy Formulas with AI Coding: A Reliability-First Workflow

    AI coding tools can generate formulas from research documents, but runnable code is not the same as correct code. This article presents an engineering workflow for reliably reproducing indicators and strategy formulas from research reports: extract documented evidence first, build a testable algorithm specification, adapt to the target formula environment, verify with layered tests covering syntax, numerics, edge cases, and look-ahead bias, and keep auditable logs. It helps developers turn occasional AI coding success into a repeatable, verifiable delivery process.

    1. From “Generating Code” to “Completing the Task”

    Evaluating AI coding capability cannot be based solely on whether the code looks complete or whether a single demo runs smoothly. Real development tasks involve multiple interconnected stages: understanding requirements, reading source material, extracting constraints, choosing algorithms, adapting to the runtime environment, executing tests, and fixing errors.

    Reproducing an indicator from a research report is a typical example. A user provides a research document and asks the system to extract the definition of a moving-average-style indicator and convert it into a formula executable in market analysis software. On the surface, this is a “document-to-code” task. In practice, it spans document parsing, mathematical understanding, time-series processing, and adaptation to a specialized formula language.

    A failure at any stage can produce a dangerous outcome: the code runs, the chart looks plausible, but the computed results do not match the research document.

    So the more valuable question is not “did the model write the code,” but:

    • Does the indicator definition have a clear basis in the document?
    • Does the formula conversion preserve the mathematical meaning?
    • Does the target environment support the functions being used?
    • Does the calculation remain correct on boundary data?
    • Can the reproduction process be traced and repeated?

    Building a workflow around these questions is what turns AI coding from a writing aid into a reliable development collaborator.

    2. Extract the Evidence Before Choosing the Algorithm

    2.1 The Indicator Definition Is Rarely a Single Formula

    A research document may scatter key information across body text, figure captions, tables, footnotes, and appendices. For example, the body explains the computation idea, a figure caption specifies the window length, an appendix describes outlier handling, and the backtest section adds the timing of trade signal execution.

    If you extract only the paragraph containing the indicator’s name, you can easily miss conditions that affect the result.

    Start by building an “indicator definition checklist”:

    Item What to confirm
    Input series Close price, returns, or other processed data
    Time window Fixed or dynamic window; whether the current bar is included
    Core computation Mean, median, weighted statistics, or other transforms
    Parameter settings Values, rationale, and whether they change across samples
    Initialization rules Behavior when data is insufficient: missing value, partial-window result, or other
    Exception handling How missing data, suspensions, zeros, and extreme values are treated
    Signal definition Whether the indicator itself and buy/sell conditions are defined separately
    Time constraints Whether each result uses only data available at that time

    Every item should be annotated with the page number, section, or location in the source document. Anything without documented support should be marked as “to be confirmed” rather than silently filled in by the model based on common practice.

    2.2 Separate Confirmed Facts, Interpretations, and Assumptions

    Classify extracted information into three levels:

    Confirmed facts: formulas, parameters, and processing rules stated directly in the document.

    Interpretive derivations: equivalent expansions or variable renames made to aid understanding.

    Assumptions to verify: information missing from the document, plus temporary conventions adopted so development can proceed.

    For example, “the window includes the current bar” versus “the window ends at the previous bar” differ by a single index, yet this changes when signals are generated. Such choices must not be treated as arbitrary implementation details.

    For scanned documents, also check OCR results carefully for subscripts, minus signs, fraction bars, and summation bounds. Formula symbol recognition errors are harder to spot than ordinary typos, and downstream code tends to amplify them.

    3. Convert the Documented Definition into a Testable Intermediate Specification

    Before generating the target formula, build an algorithm description that is independent of any specific software. This substantially reduces debugging difficulty.

    A qualified intermediate specification includes at least:

    1. Input variables and their units.
    2. Output variables and their meaning.
    3. Window and indexing conventions.
    4. The order of every computation step.
    5. Missing-value and initialization rules.
    6. Small, hand-computable samples with expected results.

    For example, a rolling-median smoothing process—used here purely to illustrate the engineering method—can be written as:

    1. Inputs:
    2. Series X
    3. Window length N
    4. For each time step t:
    5. If fewer than N valid historical data points are available:
    6. Output a missing value
    7. Else:
    8. Take X[t-N+1] through X[t]
    9. Sort them in ascending order
    10. If N is odd:
    11. Output the middle value of the sorted list
    12. If N is even:
    13. Output the average of the two middle values

    This pseudocode only demonstrates how to define a computation process; it does not represent any specific research indicator. In an actual reproduction, you must use the algorithm confirmed against the document—not adopt an example simply because it looks reasonable.

    This intermediate layer has another important role: it separates “the model misunderstood the algorithm” from “the target language does not support it.” If the independent computation is correct but the target formula is wrong, focus debugging on syntax and function semantics. If both deviate from the hand-computed result, go back to the algorithm definition.

    4. Formula Adaptation Is About Semantics, Not Just Syntax

    4.1 Build a Capability Checklist for the Target Environment

    Formula engines differ widely in capability. Some support rolling statistics but not array sorting; some allow conditional expressions but not loops or user-defined functions.

    Before conversion, confirm:

    • How historical references are written and in which direction.
    • The start and end range of rolling windows.
    • Whether median, sorting, and quantile operations are supported.
    • Whether recursive state is supported.
    • How conditional branches and missing values are handled.
    • The formats for comments, variable assignment, and output statements.
    • Whether any function may reference future data.

    Ideally, provide a minimal formula that has already run successfully in the target environment as a syntax sample. The sample’s purpose is to constrain assignment symbols, comment style, and output form—not to let the model copy its computation logic.

    4.2 A Missing Function Does Not Mean Any Substitution Is Acceptable

    If the target environment has no median function, you cannot simply replace it with an arithmetic mean. The two differ in sensitivity to outliers, and substituting one for the other changes the indicator’s definition.

    Possible paths include:

    Exact implementation: For short, fixed-length windows, implement the equivalent operation with comparison and selection logic. The expression may become long and harder to maintain.

    External precomputation: If the environment supports a verified data-import workflow, compute the indicator externally and import the results. Time indexing, data alignment, and update rules must be specified explicitly.

    Approximate implementation: Only acceptable when the task permits approximation, with the error, applicable conditions, and strategy impact documented separately.

    Confirm it cannot be implemented: When the language cannot express the original algorithm, report the limitation clearly instead of generating a substitute formula that looks complete but is materially wrong.

    A reliable development assistant should be able to recognize “cannot be implemented equivalently,” not just keep producing new code.

    5. Verification Must Cover Compilation, Numerics, and Temporal Causality

    5.1 Passing Compilation Is Only the Minimum Bar

    The target software accepting the formula only proves the syntax and some interface usage are valid. It proves nothing about algorithmic correctness.

    Complete verification should include at least four layers:

    • Syntax verification: can the formula load and execute?
    • Numerical verification: does the output match the reference computation?
    • Boundary verification: do special inputs follow the established rules?
    • Temporal causality verification: do historical results depend on future data?

    5.2 Use Small Samples to Find Big Problems

    Design inputs that can be hand-computed first, rather than observing complex market curves directly.

    For the rolling-median example above, test:

    • A series where all elements are identical, to check the output stays constant.
    • A strictly increasing series, to check window positioning.
    • A series with a single extreme value, to check median semantics are preserved.
    • A series with duplicate values, to check sorting and position selection.
    • A series shorter than one window, to check initialization rules.
    • A series containing missing values, to check the pre-confirmed convention.

    Different algorithms need different tests. If the indicator involves recursive smoothing, add tests for initial state and sustained-running results; if it involves division, check behavior when the denominator is zero or near zero.

    5.3 Compare Point by Point, Not Just by Eyeballing the Curve

    Save the point-by-point outputs of both the reference implementation and the target formula, and compute:

    1. Absolute error = |target output - reference output|
    2. When the reference output is clearly not near zero:
    3. Relative error = absolute error / |reference output|

    Error tolerance should be set according to data precision and the computation process; do not apply a single arbitrary threshold everywhere. When the reference value is close to zero, relative error is easily inflated, so supplement it with absolute error or another pre-defined scale.

    When a discrepancy appears, locate “the first time step that disagrees.” The first deviation is usually more diagnostically valuable than the many that follow, and it helps identify window misalignment, initialization inconsistency, and recursion errors.

    5.4 Check for Future Information Leakage

    Run a truncation test on the time series: first compute using data up to a given date, then add later data and recompute. If previously output historical values change, check for future references, backfilling, or repainting behavior.

    Note, however, that historical data revisions or changes in price-adjustment methods can also alter historical results. Fix the data snapshot during testing to avoid misinterpreting data changes as an algorithm problem.

    For trading strategies, also distinguish between when the indicator value is produced and when the order executes. A signal computed from the current day’s close cannot, without justification, be assumed to execute at that same closing price.

    6. Let the AI Work in Stages, Not All at Once

    Complex tasks are better handled through staged collaboration:

    Stage 1: Requirements and evidence confirmation.
    Read the document, organize definitions and open questions. Do not generate a complete formula yet.

    Stage 2: Independent reference implementation.
    Produce verifiable computation logic and test samples to confirm the mathematical meaning.

    Stage 3: Target-environment conversion.
    Adapt the syntax based on the capability checklist, and explicitly report unsupported features.

    Stage 4: Execution and repair.
    Read real error messages, make minimal-scope changes, and run the existing tests.

    Stage 5: Delivery and review.
    Output the formula, parameter documentation, evidence locations, test results, and known limitations.

    This approach controls risk far better than “do everything in one pass.” Each stage has a concrete artifact, which also prevents the model from expanding an early misunderstanding into large amounts of wrong code.

    Tool-call permissions should be minimized per task. Reading a research document should not by default grant write access to the entire working directory; when executing generated code, prefer isolated environments, resource limits, and controlled output directories.

    7. Logs Should Record Engineering Evidence, Not Just Chat History

    Effective logs should support reproduction and audit. Recommended contents:

    • Input document version and data version.
    • Evidence locations in the document and the definition checklist.
    • Open questions and the conventions finally adopted.
    • The version of each generated artifact.
    • Operations actually executed and their returned results.
    • Error messages and the corresponding fixes.
    • Test inputs, expected values, and actual values.
    • Unresolved limitations and risks.

    There is no need to require the system to expose its internal reasoning. What matters is auditable evidence, decision summaries, and execution results.

    In particular, distinguish “about to execute,” “already executed,” and “executed successfully.” Only genuine returned results can prove that a file was written, a formula ran, or a test passed; a natural-language claim of success cannot substitute for verification evidence.

    8. Evaluate Value by Total Cost and Stability

    The cost of AI coding is not just the subscription price. For individual developers, manual review, error repair, and repeated debugging may consume more time; for enterprises, security review, integration maintenance, and failure risk must also be considered.

    Use the following framework to estimate value:

    Total cost = usage fees + integration and maintenance cost + human review cost + error repair cost + risk cost

    For evaluation, run the same representative task set repeatedly under similar inputs, permissions, and test conditions, and record:

    • Full-task pass rate.
    • First-generation pass rate.
    • Average number of repair rounds.
    • Human intervention time.
    • Total completion time.
    • Failure-reason distribution.
    • Whether results are reproducible.

    A single successful demo shows that one path is feasible; it does not prove general reliability on complex tasks. Likewise, context window size, reasoning settings, or tool count alone cannot represent engineering effectiveness. Whether the material is well organized, whether feedback is genuine, and whether testing is adequate often matter just as much.

    9. Conclusion: Reliable Reproduction Comes from a Closed Loop, Not Fluent Output

    The practical value of AI coding lies in shortening the distance between understanding, implementation, and debugging. But to reliably convert a research document into an executable formula, clear engineering boundaries are still required.

    A workflow worth adopting is:

    Document evidence extraction → algorithm specification confirmation → independent reference computation → target semantic adaptation → layered test verification → logging and human review.

    Following this path, developers can catch definition ambiguities, function incompatibilities, and time-indexing errors earlier, and turn one-off successes into a repeatable delivery process.

    One final clarification: a correctly reproduced indicator does not imply an effective strategy. Strategy evaluation still requires independently checking out-of-sample performance, transaction costs, data bias, and execution conditions. AI coding can improve research efficiency, but it cannot replace evidence—and it cannot replace verification.