AI Coding Agents for Financial Indicator Reproduction: From Research Reports to Trading Formulas
This article explains how AI coding agents can convert complex research reports into runnable, verifiable, and reusable financial indicator scripts. It covers semantic extraction, document structuring, computation-graph recovery, formula-language conversion, logging, common compatibility issues, and a three-stage validation process. It also clarifies where AI agents help and where researchers must still confirm assumptions, data conventions, and interpretation.
In quantitative research and investment analysis, the hard part is often not writing a few formulas. The real challenge is accurately converting a research document—one with complex structure, inconsistent terminology, and extensive contextual explanation—into an indicator script that can run, be verified, and be reused.
Historically, this work required researchers to read the report, manually organize variable definitions, calculation order, and boundary conditions, and then implement the logic according to the formula syntax of the target analysis software. Whenever an indicator involved multi-layer smoothing, percentiles, extreme-value filtering, rolling windows, or conditional branches, the process was prone to misunderstandings. Today, AI coding agents with document-reading, code-generation, and self-correction capabilities can break this workflow into explicit stages and produce an initial reproduction in a relatively short time.
1. The Real Problem: Semantic Conversion, Not Just Formula Writing
Consider a moving-average timing indicator. A research report may contain all of the following:
- The research background behind the indicator;
- Descriptions of source data and data frequency;
- Mathematical definitions of intermediate variables;
- Parameter values and the rationale for adjusting them;
- Dependencies among multiple calculation steps;
- Special handling used in backtesting;
- Additional constraints found in charts, notes, and footnotes.
This information rarely appears as one complete, continuous piece of pseudocode. A variable may be defined in the main text, a parameter may be described in a table, and the calculation order may be hidden in formula numbering or contextual description. Indicator reproduction is therefore first a problem of recovering a computation graph from natural language and formatted documents.
The problem can be abstracted into four layers:
- Conceptual layer: Understand the market phenomenon the indicator is intended to describe.
- Mathematical layer: Recover variables, operators, windows, and recursive relationships.
- Language layer: Translate mathematical expressions into the target formula language.
- Validation layer: Check whether the result is consistent with the report’s logic and sample behavior.
The real value of an AI coding agent is not replacing any single step. It is connecting all four steps into one continuous workflow.
2. Document Parsing: Build Structure Before Extracting Formulas
Asking a model to “read the report and write the code” directly often produces unstable results. A more reliable method is to require the agent to build a structured document summary before implementation.
The first step should define the input materials, including:
- The original research report;
- Syntax documentation for the formula language;
- Runnable example files;
- The required output file format;
- Logging requirements;
- Whether approximate expressions are permitted.
Example files are especially important. Formula platforms differ in function names, parameter order, comment format, variable naming, and statement terminators. Even if the mathematical expression is correct, the script may fail to execute if its syntax style does not match the target environment.
The agent should then produce an indicator definition table with at least the following fields:
| Field | Description |
|---|---|
| Variable name | Original symbol in the formula or target name |
| Chinese meaning | Economic meaning of the variable in the research |
| Input data | Close, high, low, volume, and other inputs |
| Window parameter | Period or sample length used in the calculation |
| Operation type | Mean, median, difference, smoothing, or conditional test |
| Dependent variables | Upstream calculation results required by this variable |
| Boundary handling | How to handle insufficient data |
| Final use | Plotting, signal detection, or backtest filtering |
This step effectively prevents the common problem of understanding a formula while missing its prerequisite definitions.
3. Recovering the Computation Graph from Mathematical Expressions
A complex indicator should not be treated as one long formula. It should be decomposed into a directed acyclic graph. Each node represents an intermediate variable, and each edge represents a dependency between variables.
For example, an indicator may follow this abstract flow:
Raw price series↓Base price transformation↓Rolling statistic↓Smoothing↓Threshold or range test↓Final indicator line↓Buy/sell or trend signal
Consider a moving-average indicator that uses a median. You cannot simply replace the median with an arithmetic mean. The two can differ significantly when the data distribution is asymmetric or contains abnormal fluctuations. If the target formula environment does not provide a median function directly, you must first determine the statistical object and window length in the original report, then design an equivalent implementation.
Common implementation approaches include:
- Sort the data within the window.
- Determine whether the window length is odd or even.
- For an odd window, take the middle value.
- For an even window, average the two middle values.
- Use the result as input to subsequent smoothing or comparison operations.
In practical formula platforms, however, sorting may not be convenient. Depending on platform capabilities, alternatives may include combining existing statistical functions, using a piecewise approximation, or constructing the result through multiple conditional comparisons. In such cases, the log must clearly state whether the implementation is strictly equivalent or an approximation required by platform limitations.
4. Formula Conversion: Preserve Semantics Before Pursuing Conciseness
When translating mathematical formulas into scripts, follow the principle of “expand layer by layer and name variables step by step” rather than compressing everything into a single expression.
For example, do not directly generate an opaque long formula:
FinalIndicator = ComplexFunction(ComplexFunction(ComplexFunction(PriceSeries)))
Instead, use intermediate variables:
BaseValue = ...RollingStatistic = ...SmoothedResult = ...FilteredResult = ...FinalIndicator = ...
This style has three advantages:
- It is easier to compare each item against the research report.
- Numerical anomalies are easier to locate.
- Later parameter changes are less likely to break the overall structure.
Comments should also avoid useless statements such as “calculate indicator.” Instead, they should explain variable meaning, input source, and calculation purpose. For example:
// Base price series: used to construct the raw observations// Rolling statistic: reflects the central level within the specified window// Smoothed result: reduces short-term noise// Signal condition: used to identify changes in trend direction
If the target platform supports plotting parameters, separate “calculation logic” from “presentation logic.” Colors, line widths, and layer positions belong to the presentation layer and should not be mixed into the core calculation process; otherwise, migration becomes more difficult.
5. Tool Calls and Process Logs: Make Results Auditable
Another important capability of AI coding agents is the ability to make multiple tool calls around documents, code, and test files. To use this capability reliably, a clear execution order must be specified.
The recommended workflow is as follows:
1. Read the document
The agent first extracts the main text, tables, formulas, and footnotes, and marks potentially ambiguous locations. For image-based formulas or scanned pages, it should first perform text recognition, then use the model to correct the result in context.
2. Extract definitions
Produce a variable list, parameter list, calculation order, and open questions. Do not write the final script immediately.
3. Read syntax examples
Identify function naming, comment style, variable declarations, and output rules in the target language.
4. Generate an initial script
Keep intermediate variables explicit and add explanations at each key step.
5. Run static checks
Check for undefined variables, invalid loop windows, mismatched parentheses, incorrect function argument counts, and naming conflicts.
6. Save execution logs
Logs should contain at least:
- Input files;
- Core definitions extracted;
- Assumptions made by the model;
- Generated script versions;
- Execution errors;
- Reasons for modifications;
- Final test results.
The purpose of logging is traceability. When results do not match the report, you can determine whether the cause was a document-understanding error, a formula-translation error, or different behavior in a platform function.
6. Common Problems: Missing Statistical Functions and Syntax Incompatibility
In practical reproduction work, the most common failure is not that the model cannot derive the logic. It is that the target formula environment lacks certain functions.
For example, a research report may use median, percentile, sorting, or a specific smoothing function, while a traditional formula platform provides only basic mean, maximum, minimum, and conditional tests. In this situation, you cannot simply delete the step, nor replace it with an arithmetic mean without explanation.
A more reasonable approach is to:
- Check whether the platform has synonymous functions.
- Check whether the logic can be implemented by combining existing basic functions.
- Determine whether the window length is fixed.
- Evaluate the complexity and runtime cost of an exact implementation.
- If only an approximation is possible, clearly mark the approximation scope.
- Verify the numerical trend of the substitute result with manual samples.
In some cases, the first generated script needs only one targeted correction before it runs. But “runnable” does not mean “logically correct.” Syntax testing is only the first validation layer; numerical and semantic validation are also required.
7. Validation: Complete at Least Three Rounds of Checks
Round 1: Syntax validation
Paste the script into the target environment and check whether it compiles or loads. Focus on function names, argument counts, variable definitions, and comment format.
Round 2: Numerical validation
Construct a set of simple datasets—for example, monotonically increasing, monotonically decreasing, completely identical, and data with a single outlier—and observe whether the indicator behaves as expected.
For moving-average indicators, at least check:
- Whether the indicator remains reasonably upward when the input rises overall;
- Whether the indicator changes accordingly when the input falls overall;
- Whether response speed changes with window length in a way that makes sense;
- Whether median and mean behave differently as expected when extreme values appear;
- Whether results remain stable when data is insufficient for the window length.
Round 3: Semantic validation
Compare the implementation against charts, textual descriptions, and conclusions in the research report item by item. The goal is not to require every numerical value to match exactly, but to confirm that the calculation logic, trend direction, and signal-trigger conditions are consistent.
If the original report provides a sample interval, use the same data frequency, adjustment method, and parameters for comparison. Otherwise, even a correct formula may produce large differences because of different data conventions.
8. Limits of AI Agents: Efficiency Gains Are Not Research Conclusions
AI coding agents can significantly reduce the time cost of document reading and formula implementation, but they cannot automatically solve every research problem.
First, the report itself may be ambiguous. The same symbol may mean different things in different sections, or the main text and footnotes may describe parameters inconsistently. The model can propose interpretations, but it cannot decide which interpretation matches the original author’s intent.
Second, indicator implementation depends on data conventions. Whether to use adjusted data, how to handle missing values, whether to fill suspended trading periods, and how to align trading days across markets can all affect the final result.
Third, formula reproduction is not strategy reproduction. Even if the indicator line is calculated identically, trading signals, holding periods, transaction costs, slippage, and risk controls can still cause backtest performance to differ.
The most appropriate positioning is therefore this: AI agents accelerate the process of understanding, coding, testing, and correction, while researchers remain responsible for confirming assumptions, judging data conventions, and interpreting results.
9. A Work Model for Enterprise R&D
This method applies not only to financial indicators but also to many tasks that require converting specialized documents into executable logic, such as:
- Converting technical specifications into validation scripts;
- Converting API documentation into test cases;
- Converting process policies into rule engines;
- Converting paper algorithms into engineering implementations;
- Converting equipment manuals into monitoring and alert conditions.
To improve team collaboration, establish a unified template that requires every project to submit the following artifacts:
- Original documents and version information;
- Structured requirement summary;
- Variable and parameter dictionary;
- Intermediate formulas or pseudocode;
- Final script;
- Test data and validation results;
- Assumptions, limitations, and open questions;
- Complete execution logs.
This approach turns a one-off model conversation into an engineering asset that can be reviewed, reused, and maintained.
Overall, the core value of AI coding agents in complex indicator reproduction is not merely faster writing. It is their ability to assist with document understanding, dependency mapping, syntax migration, and error correction. When tasks are broken into structured steps and combined with logs, examples, and multiple validation rounds, research engineering work that once required long manual effort can become a more transparent, stable, and reproducible technical process.
