From Research Reports to Indicator Formulas: A Reliable Reproduction Method for AI-Assisted Programming

    Reproducing quantitative indicators from research reports with AI-assisted programming is less about generating code and more about preserving semantic consistency across statistical definitions, time-series computation, and the target formula environment. This article presents a structured workflow: break the task into verifiable deliverables (definition extraction, environment-agnostic specifications, implementation, and validation records), resolve evidence issues in document parsing, handle missing native functions such as rolling medians with semantically equivalent alternatives, replace "looks correct" with a three-layer test loop, interleave planning with tool execution, and keep reproducible logs. It also explains how to evaluate the real value of AI-assisted coding for this kind of work.

    1. The Core of Indicator Reproduction Is Semantic Consistency, Not Code

    In quantitative research and financial data analysis, research reports typically combine textual descriptions, mathematical formulas, parameter tables, and backtest charts. Developers must convert this content into indicator expressions that the target analysis environment can execute before moving on to visualization, historical validation, and strategy research.

    AI-assisted programming can accelerate this process, but the real difficulty is not generating a few lines of formulas. It is ensuring consistency across three levels:

    First, what statistical method does the report describe; second, how does the mathematical definition map to discrete time-series computation; third, does the target formula environment support the required data structures, window operations, and function semantics.

    If any of these three levels deviates, you get the classic problem of “the formula runs, but the result is not the original indicator.” For example, the report asks for the median over the most recent N valid trading days, but the generated formula uses a calendar-day window; the report requires excluding missing observations, but the implementation treats missing values as zero. Both can produce smooth, plausible-looking curves while silently changing the indicator’s definition.

    A more reliable technical approach is therefore:

    Build a verifiable indicator specification before generating formulas; validate numbers before judging charts; clarify compatibility boundaries before discussing automation efficiency.

    2. Break the Task into Verifiable Deliverables

    Asking an AI coding system to simply “read the report and reproduce the indicator” leaves too much room for interpretation. The system may fill in parameters on its own or substitute a common algorithm for the report’s actual definition.

    A better approach is to decompose the task into four types of deliverables.

    2.1 Definition Extraction Checklist

    The extraction should include at least:

    • The indicator’s chapter, page, or paragraph location;
    • The meaning of input series, such as closing prices, returns, or other observations;
    • The mathematical expression and the definition of each symbol;
    • Window length, weights, and other parameters;
    • Handling rules when the initial sample is insufficient;
    • Treatment of missing values, outliers, and trading suspensions;
    • Ambiguities that still require human confirmation.

    The most important distinction here is between “explicitly specified in the source text” and “engineering conventions adopted during implementation.” The former must be preserved faithfully; the latter should be recorded separately and must not be written up as conclusions from the report.

    If the source material does not specify a key parameter, mark it as “not specified” rather than picking a common default and claiming the reproduction is complete.

    2.2 Intermediate Specification

    Before generating the target formula, produce an environment-agnostic specification. For example:

    The input is a price series sorted in ascending time order; at each time point, only current and historical data are read; the specified statistic is computed over a complete window of length N; no output is produced when fewer than N valid samples are available.

    This kind of description helps researchers and developers jointly confirm the logic, and it also makes later migration to other computing environments easier.

    2.3 Target Environment Implementation

    The implementation should list the functions and capabilities it depends on, not just deliver a final formula. At minimum, it should state:

    • Whether rolling windows are supported;
    • Whether sorting or quantile computation is supported;
    • Whether custom functions are allowed;
    • Whether loops, arrays, or recursive state are supported;
    • Whether missing results can be represented;
    • Whether intermediate computation series can be output separately.

    These capabilities determine whether a mathematical definition can be expressed directly, and how complex a workaround implementation would be.

    2.4 Validation and Execution Records

    The final deliverable should include test inputs, expected outputs, actual outputs, error explanations, and the correction process. This way, even if the formula later behaves differently due to an environment upgrade, the problem can be located quickly without re-interpreting the entire report.

    3. Document Parsing Must Resolve the Evidence Problem First

    Formulas in research reports are not always stored as copyable text. Some are images, some are rendered through complex layout, and some documents suffer from blurry scans, misaligned subscripts and superscripts, or tables split across pages.

    Therefore, document extraction cannot rely on a single text pass.

    For pages containing mathematical definitions, cross-check the body text, the formula regions, and adjacent charts. Pay special attention to content that is easily misread:

    • Upper and lower bounds of summation symbols;
    • The sample count in denominators;
    • Subscripts for current versus historical time points;
    • Absolute values, parentheses, and negative signs;
    • How weighted terms are normalized;
    • Strict versus non-strict inequalities;
    • Parameters that are defined elsewhere in the body text.

    For example, a single subscript offset can turn “the window up to the current time point” into “the window up to the previous time point”; dropping a weight normalization term can change the indicator’s entire scale.

    A reliable extraction result should be traceable back to its location in the source text. For formulas recognized with uncertainty, keep a pending-confirmation status and have a human verify them before they enter the implementation stage. A fluent explanation from an AI system cannot replace original evidence.

    4. Handling Missing Functions: The Rolling Median Example

    A common obstacle in indicator reproduction is that the target environment does not provide a native function required by the mathematical definition. The median is a typical case.

    Note that the following content is only used to illustrate compatibility handling methods and does not represent the complete definition of any indicator from a specific report. Whether a given indicator uses a median and how it combines other statistics should always follow the original report.

    For a window containing N valid observations, sort the data in ascending order:

    x(1) ≤ x(2) ≤ … ≤ x(N)

    When N is odd, the median is the (N+1)/2-th value; when N is even, the median is typically the average of the N/2-th and (N/2+1)-th values. If the report adopts a different convention, follow the report’s definition.

    The pseudocode below illustrates the algorithm logic; it is not a directly runnable interface for any target environment:

    1. // Example: rolling median over a complete window
    2. // Preconditions: window length N is a positive integer; data is sorted in ascending time order
    3. For each time point t:
    4. If the historical data up to t has fewer than N observations:
    5. Output a missing result
    6. Continue to the next time point
    7. Window = the N observations from t-N+1 to t
    8. If the window contains missing values:
    9. Apply the pre-confirmed missing-value rule
    10. If the valid-sample requirement is not met:
    11. Output a missing result
    12. Continue to the next time point
    13. Sorted window = sort the window in ascending order
    14. Valid count = number of elements in the sorted window
    15. If the valid count is odd:
    16. Output the middle element
    17. Else:
    18. Output the average of the two middle elements

    This example reveals an important principle: you must not replace the median with the arithmetic mean just because the target environment lacks a median function. The two differ in sensitivity to extreme values, and after substitution it is no longer the same statistical method.

    4.1 Prefer Semantically Equivalent Capabilities

    If the target environment provides order statistics or quantile capabilities, investigate whether they can express the median. But verify the exact definition, especially the interpolation rule for even-sized samples, missing-value handling, and window boundaries.

    Similar function names do not imply identical behavior.

    4.2 Alternatives in Restricted Environments

    If the environment supports neither sorting, arrays, nor custom functions, consider:

    • Using explicit comparison-and-selection logic for fixed, short windows;
    • Computing the indicator externally and importing it into the target analysis environment;
    • Using an approximation method validated for error, clearly labeled as approximate;
    • Adjusting the deployment so that complex computation is separated from chart display.

    Each option has prerequisites. Comparison logic for fixed windows can be hard to maintain; external computation requires the target environment to support the corresponding data input method; approximation algorithms must come with error bounds and cannot be delivered as exact reproductions.

    If the target environment genuinely cannot express the original algorithm, clearly stating the limitation is more professional than outputting a superficially similar formula.

    5. Replace “Looks Correct” with a Test Loop

    A formula passing syntax checks only proves the expression can be parsed. A chart roughly resembling the curve in the report does not prove numerical correctness.

    Validation should have at least three layers.

    5.1 Statistical Function-Level Validation

    Validate the underlying operations before the full indicator. Taking the median as an example, construct:

    • Odd-sized window: 1, 4, 9, expected result 4;
    • Even-sized window: 1, 3, 7, 9, expected result 5;
    • Repeated values: 2, 2, 2, 8, 10, expected result 2;
    • Extreme value: 1, 2, 3, 4, 1000, expected result 3.

    These small samples quickly reveal errors in sorting, indexing, and even-sized window handling.

    5.2 Time Series-Level Validation

    Compare the full series point by point, focusing on:

    • At which time point the first valid output appears;
    • Whether the current observation enters the window;
    • Whether the window changes in sync when parameters change;
    • Whether missing observations cause unintended sample compression;
    • Whether appending historical data abnormally rewrites existing results.

    Error evaluation can use absolute error with a tolerance set relative to the data scale. When relative error is involved, avoid distortion caused by reference values close to zero. If the data contains missing results, also compare whether the missing positions match.

    5.3 Strategy-Level Validation

    If the indicator is used for timing or signal generation, the trading logic also needs validation:

    • Is the signal formed after the close or intraday;
    • After the signal forms, when is the earliest it can be executed;
    • Does it use data that was not yet available at the time;
    • Are transaction costs, slippage, and unfilled orders considered;
    • Were parameters determined only on the training interval;
    • Do the conclusions still hold on out-of-sample intervals.

    Correct indicator values do not automatically imply an effective strategy. And no single historical backtest can be extrapolated into a promise of future returns.

    6. Why AI-Assisted Programming Needs Planning Interleaved with Tool Use

    Complex reproduction tasks are rarely one-shot code generation. They are loops of “read — judge — implement — run — fix,” where the system adjusts subsequent actions based on real results returned by tools.

    An effective workflow looks like this:

    1. Parse the document and build an evidence list;
    2. Extract definitions and flag uncertain items;
    3. Check the target environment’s functions and syntax constraints;
    4. Generate a minimal verifiable implementation;
    5. Execute tests and read error messages;
    6. Fix the specific issues causing failures;
    7. Run regression tests;
    8. Output the final formula, assumptions, and validation report.

    The value of interleaving planning with execution is that every step is constrained by external evidence. Compared with outputting a long piece of code in one go, this approach makes errors easier to locate and modifications easier to scope.

    But a more complete process does not guarantee a correct result. If document parsing is wrong, test samples are insufficient, or environment information is incomplete, the system can still reach wrong conclusions. Human review should focus on key positions — indicator definitions, environment constraints, and acceptance criteria — rather than merely checking whether the final code looks tidy.

    7. What Logs Should Record to Truly Support Reproduction

    The purpose of keeping execution logs is not to display a lengthy generation process, but to preserve the facts and decisions that affect the result.

    Recommended log contents include:

    • Input document version and file checksum information;
    • Extracted formulas, parameters, and their sources;
    • Human-confirmed ambiguities and final handling decisions;
    • Target environment version and capability constraints;
    • Each submitted formula version;
    • Test data and its sources;
    • Error messages and numerical discrepancies;
    • Reasons and scope of each modification;
    • Test items that ultimately passed;
    • Limitations that remain unresolved.

    When sensitive reports or internal data are involved, follow the authorized scope, control file access permissions, and avoid writing complete data into unnecessary logs.

    Logs suitable for reproduction should be concise, searchable, and comparable. They do not need to record the system’s internal reasoning; they should record observable steps, inputs, outputs, and the basis for decisions.

    8. How to Evaluate the Real Value of AI-Assisted Programming

    Evaluating this kind of capability should not rest solely on whether the first generation succeeds, nor should a few cases be used to declare one system comprehensively superior.

    More meaningful evaluation dimensions include:

    • Whether definition extraction is faithful;
    • Whether uncertain information is explicitly flagged;
    • Whether tool calls complete the necessary checks;
    • Whether the formula is compatible with the target environment;
    • Whether errors are caught by tests;
    • Whether modifications pass regression validation;
    • Where human intervention is concentrated;
    • Whether total delivery time includes reading, debugging, and review;
    • Whether the final result can be independently verified by others.

    The main benefit of AI-assisted programming is reducing repetitive document organization, formula translation, and test construction, so developers can focus their effort on definition confirmation and result judgment. It does not remove the need for knowledge of financial mathematics, time series, and the target runtime environment.

    9. Conclusion: Reliable Reproduction Depends on a Complete Evidence Chain

    From a research report to a runnable indicator, what really needs to be delivered is not a piece of formula but a complete evidence chain:

    Original definitions have traceable sources, engineering assumptions are recorded, implementation logic is explainable, numerical results are verifiable, and the modification process is trackable.

    Once this chain is established, AI-assisted programming can shift from “rapidly generating content” to “reliably assisting engineering.” Even if a human ultimately has to supply a compatibility implementation, it will be clear where the problem lies, what was changed, and why the result is trustworthy.