From Code Generation to Technical Indicator Reproduction: A Practical Workflow for AI Coding Models

    AI coding models are increasingly expected to do more than complete code and explain errors. They must understand complex documents, decompose tasks, use tools, generate executable outputs, and revise their work based on feedback. This article uses the reproduction of technical indicators from financial research documents as a representative case. It examines where the real difficulty lies, then presents a staged workflow covering requirement definition, algorithm specification, function mapping, handling missing functions such as median, interleaved reasoning, and layered validation. It also discusses logging, human review, and practical criteria for evaluating model performance. The central point is that reliable results depend on explainable task decomposition, reproducible verification, and human audit—not one-shot generation.

    In recent years, the capabilities of AI coding models have expanded from code completion and error explanation toward understanding complex materials, decomposing tasks, invoking tools, generating runnable results, and self-correcting based on feedback. For developers, the significance is not merely writing fewer lines of code. These models are beginning to participate in the complete problem-solving process.

    A representative scenario is reproducing technical indicators from financial research documents. In the past, this work usually required researchers to read dozens or even hundreds of pages, extract a complete algorithm from formulas, variable definitions, boundary conditions, and parameter descriptions, and then reimplement it in the formula language of a specific trading platform. A misunderstanding at any point could cause the result to differ from the original document.

    Today, models with document parsing, code generation, and tool-use capabilities make it possible to split the process into a relatively clear automated workflow.

    1. The Hard Part of Complex Tasks Is Not “Writing the Formula”

    On the surface, reproducing an indicator seems to be nothing more than translating a mathematical expression into code. The real difficulties are usually concentrated in the following areas.

    1.1 Locating Useful Information in Unstructured Documents

    Professional research materials often contain research background, sample scope, experimental results, parameter settings, formula derivations, and strategy descriptions. A model should not simply pass the entire document to a code generator. It should first identify:

    • the formal definition of the indicator;
    • the meaning of each variable;
    • the default values and adjustable ranges of parameters;
    • the initialization method;
    • the rolling window length;
    • how missing data or insufficient historical data should be handled;
    • whether the final output is a single curve, multiple intermediate variables, or buy and sell signals.

    If the model captures only the formula and ignores the explanatory text, it is very easy to produce a result that “looks mathematically correct” but does not run consistently with the source. For example, the document may use a median, a quantile, smoothing, or a specific initial value, while the target formula language may not directly provide a corresponding function.

    1.2 Mathematical Expressions and the Target Language Are Not Fully Equivalent

    Formulas in research documents are usually expressed with mathematical notation, while the target platform has its own function names, argument order, and syntax restrictions. Common differences include:

    • sequential operations in mathematics may need to be implemented through historical references in a formula language;
    • some statistical functions exist in high-level languages but have no direct counterpart in traditional indicator editors;
    • null values, zero values, and invalid intervals may follow different handling rules;
    • variable assignment may differ from ordinary programming languages;
    • comment symbols, line breaks, and output formats may have explicit requirements.

    Therefore, the model must do more than translate. It must perform semantic adaptation: determine what the target environment supports, identify what is missing, and find an equivalent implementation.

    To reduce the error rate, complex formula reproduction should not rely on a single prompt that asks for the final answer. A staged process is more appropriate.

    Step 1: Define Inputs, Outputs, and Constraints

    Before starting the task, provide the model with the complete objective, including:

    1. the documents to read;
    2. the name of the indicator to extract;
    3. the target formula language;
    4. the functions that may and may not be used;
    5. the comment format;
    6. whether intermediate variables should be retained;
    7. whether an execution log must be generated;
    8. how the final result will be accepted.

    The clearer the constraints, the easier it is for the model to form a stable execution plan. In particular, explicitly require it to “analyze first, generate second, and check third” so that it does not jump directly to code.

    Step 2: Produce an Algorithm Specification Before Generating Code

    A better approach is to ask the model to first output a structured analysis containing at least:

    • the original indicator’s definition in natural language;
    • all variables in the formula;
    • the calculation order of each variable;
    • the amount of historical data required;
    • the smoothing or statistical methods used;
    • boundary conditions;
    • alternative implementation approaches in the target language.

    The goal at this stage is not runnability. It is to check whether the model has genuinely understood the research material. Reviewing definitions and variable relationships is usually more efficient than reviewing a large block of code directly.

    Step 3: Build a Function Mapping Table

    Before generating target code, ask the model to list the mapping from each original mathematical operation to its implementation in the target language. For example:

    Mathematical operation Handling in the target environment
    Historical value reference Use the platform’s series-reference syntax
    Moving average Call the moving-average function for the corresponding period
    Median Use a built-in function, or approximate it through sorting logic
    Conditional logic Convert to a conditional expression supported by the platform
    Null handling Use initial values or conditional functions supported by the target environment

    The purpose of this table is to expose compatibility risks. If the model cannot find a clear implementation for a mathematical operation, it should not proceed directly to the final code stage.

    3. Handling a Missing Median Function

    In practical reproduction work, one of the most common problems is that the target formula environment is old and lacks statistical functions commonly found in modern analysis languages. Consider the median as an example. Its definition is to sort the data within a window and take the value in the middle. If the sample size is odd, take the middle element directly. If the sample size is even, usually take the average of the two middle elements.

    When the target environment has no median function, three approaches can be considered.

    Option 1: Use an Existing Equivalent Function on the Platform

    Some environments do not provide a function named “median,” but they may offer sorting, percentile, or statistical ranking capabilities. If these functions have definitions consistent with the research document, prefer the built-in implementation. The code will be simpler and easier to maintain.

    Option 2: Expand the Calculation for a Fixed Window

    If the window length is small and fixed, the data within the window can be expanded item by item, and the middle value can then be calculated through conditional comparisons and sorting logic. This approach is relatively portable, but the code length grows quickly and boundary errors are easy to introduce.

    Option 3: Use an Approximation

    In some scenarios, researchers may accept another robust statistic as an approximate replacement for the median, such as the average of a middle interval after sorting. This is not equivalent to the original definition. It must be clearly labeled, and backtesting or point-by-point comparison must confirm whether the error is acceptable.

    Whichever approach is used, the model should not make the substitution on its own. The correct process is to report the missing function, list the alternatives, and let the user decide whether to accept them.

    4. Why “Interleaved Thinking” Helps Engineering Tasks

    Complex programming tasks are usually not linear. A model needs to switch repeatedly among reading, reasoning, execution, observation, and correction. So-called interleaved thinking essentially breaks the task into multiple verifiable stages instead of generating a long block of code all at once.

    A relatively complete execution process might look like this:

    1. Read the document and locate the indicator definition.
    2. Extract the formula and parameters.
    3. Check which functions the target language supports.
    4. Generate an initial implementation.
    5. Validate it with a syntax checker or runtime environment.
    6. Record error messages.
    7. Determine whether the issue is syntax, function compatibility, or mathematical logic.
    8. Modify only the necessary parts.
    9. Validate again.
    10. Output the final formula and a change log.

    The value of this approach is that each step leaves an intermediate result behind. When the final result is incorrect, users can determine whether the error occurred during document understanding, formula conversion, or platform compatibility, rather than facing an unexplained full block of code.

    5. A Successful First Run Does Not Mean the Result Is Correct

    The fact that a formula is accepted by the target software only shows that the syntax layer has basically passed. It does not prove that the mathematical logic is completely correct. Acceptance should include at least the following levels.

    5.1 Syntax Validation

    Confirm that variable names, parentheses, separators, comments, and function calls meet the platform’s requirements.

    5.2 Boundary Validation

    Focus on behavior when historical data is insufficient. For example, when the window length is 20, should the first 19 data points be empty, should they use partial data for calculation, or should they use an initialized value?

    5.3 Numerical Validation

    Select a set of manually constructed data, calculate it separately with an independent script and the target formula, and compare the outputs point by point. Test data should cover:

    • a monotonically rising sequence;
    • a monotonically falling sequence;
    • a sequence containing sudden outliers;
    • a sequence with many repeated values;
    • a sequence whose length is insufficient.

    5.4 Business Validation

    If the indicator is used for market timing or trading, also check whether the signals match the description in the research document. This includes the timing of signal triggers, whether future data is used, whether duplicate triggers occur, and whether results are stable across different time frames.

    6. Logs and Human Review Are Essential

    Saving the execution process as a log is an important way to improve auditability. The log should not record only the final code. It should also include:

    • which input materials were used;
    • which formulas the model extracted;
    • which functions had compatibility issues;
    • which alternative approaches were adopted;
    • the differences before and after modification;
    • the result of each validation;
    • unresolved assumptions and limitations.

    In high-risk fields such as finance, healthcare, and law, human review remains irreplaceable. AI models can improve the efficiency of material organization and code generation, but they cannot automatically confer business validity on a result. Particular attention should be paid to the following risks:

    • the model misreads a condition in the formula;
    • example parameters are mistaken for official parameters;
    • data frequency and adjustment methods are ignored;
    • future information is mixed into historical calculations;
    • unconfirmed approximations are substituted when functions are missing.

    7. How to Evaluate the Real Capability of AI Coding Models

    A model should not be evaluated only by whether it can write code. The following criteria should also be observed:

    1. Is the task plan complete?
    2. Can it accurately cite the original materials?
    3. Does it proactively check the limitations of the target environment?
    4. Can it make local repairs after discovering an error?
    5. Does it retain clear intermediate results?
    6. Is the output stable and reproducible?
    7. Can it explain its assumptions?
    8. Does it proactively flag uncertain content?

    Current models have clearly improved in complex reasoning, tool use, and code generation. However, compared with truly mature engineering experts, they may still fall short in long-chain tasks, implicit constraints, domain common sense, and final responsibility judgments. The most reasonable role for them is not to “fully replace developers,” but to serve as high-efficiency research assistants, code drafters, and verification collaborators.

    Conclusion

    Reproducing technical indicators from professional documents exemplifies the real value of AI coding tools. They can connect reading, extraction, conversion, debugging, and documentation, significantly shortening the distance from a research conclusion to an executable implementation.

    However, high-quality results depend not only on model capability but also on clear task decomposition, strict function mapping, layered validation, and human audit. For enterprises and individual developers, the best practice is not to pursue one-shot generation blindly, but to establish an explainable, reproducible, and rollback-capable collaboration workflow. Only in this way can the efficiency gains brought by AI models be translated into reliable engineering output.