LLM-Assisted Reproduction of Quantitative Trading Indicators: A Practical Workflow
This article walks through a real, end-to-end workflow for using large language models and coding agents to reproduce quantitative trading indicators from research reports. It breaks the task into four stages, demonstrates a hands-on example of turning a PDF report into a trading software's formula language—including a workaround for a platform that lacks a median function—explains the technical capabilities behind agentic coding, and lays out a reusable six-step methodology. It closes with a realistic look at human-AI collaboration, risk control, and how to measure the payoff of these tools.
Introduction: From “weeks for a quant PhD” to “a one-hour draft from an agent”
The first step in the lifecycle of a quantitative strategy is usually reproduction: turning the indicators, factors, and timing rules described in research reports, papers, or internal documents into runnable code. This stage looks like mere “translation,” but it demands deep domain knowledge from the researcher.
Take a typical moving-average timing study as an example. A complete research report usually involves three layers:
- Price series preprocessing: adjustment for splits and dividends, outlier handling, and alignment to the trading calendar;
- Window statistics: mean, median, standard deviation, and quantiles;
- Timing signals: moving-average bullish/bearish alignment, breakouts, and divergences, plus parameter optimization and robustness checks.
The person reproducing it must understand the underlying statistics, be familiar with the programming paradigm and function library of the target trading software (or another backtesting framework), and iterate through debugging until the results match the report’s charts. Traditionally, this kind of task took a researcher with both a financial-engineering background and strong programming skills several days to weeks.
Continued advances in LLMs’ coding ability are reshaping this division of labor. Using a real task—extracting an indicator definition from a research report and reproducing it in a trading software’s formula language—this article breaks down the full workflow of LLM-assisted reproduction and offers practical best practices.
Note: The indicator names, prompts, and code in this article are technical illustrations only. They do not constitute investment advice and do not represent the behavior or performance of any specific product.
1. Breaking down the task: four stages of reproducing a report’s indicators
The difficulty of reproduction tasks lies in crossing several “semantic gaps”: natural language in the document, values in charts, and symbols in mathematical formulas must all ultimately map to definite program logic. This can be broken into four stages.
1.1 Document parsing and information extraction
Research reports are mostly published as PDFs containing body text, formulas, tables, and charts. Information extraction must handle at least three kinds of problems:
- Distinguishing body text, footnotes, and chart captions;
- Recognizing typesetting details in formulas, such as subscripts and summation limits;
- Locating the original source of indicator definitions, parameter settings, and signal rules.
Any omission here can later turn into a hard-to-detect error.
1.2 Domain translation and assumption completion
A report cannot spell out every detail, so the reproducer must explicitly fill in assumptions, for example:
- Whether to use the closing price or the adjusted price;
- Whether the window includes the current day;
- How to handle missing or suspended-trading data.
Recording these assumptions in a log makes them easy to review and helps later iteration.
1.3 Code implementation
The target platform usually provides a dedicated formula language or scripting interface. The syntax is relatively simple, but the function set is limited. The implementation challenges concentrate on:
- Whether window functions exist (moving average, moving standard deviation, count-based conditional statistics, and so on);
- Whether it supports nesting, backward references, and multi-period calls;
- Whether comment conventions and output formats meet the team’s requirements.
1.4 Validation and iteration
Once the code is written, you must confirm that it runs and produces correct results. This includes:
- Comparing against the report’s charts;
- Running unit checks on boundary samples;
- Doing sensitivity analysis on key parameters.
Only when this step is done is the reproduction truly closed-loop.
2. Hands-on: from report to formula, then a single correction
2.1 Task setup
The test task is a typical “document-driven formula reproduction” scenario:
- Input a PDF of a moving-average research report and a sample file of formula-writing conventions;
- Use an agentic coding tool’s document-handling ability to locate and extract the target indicator’s definition and calculation steps from the PDF;
- Implement it in the target trading software’s formula language, following the syntax and comment conventions in the sample file;
- Save the process as a log for traceability;
- A human pastes the generated formula into the trading software to test it.
2.2 Prompt design
Prompts for this kind of task can be abstracted into the following general template:
[Input]- Reference document: <path to the report PDF>- Format specification: <path to the sample file>[Task]1. Extract the full definition of "<target indicator>" from the reference document, including:calculation steps, parameters and their values, data conventions and special handling;2. Reproduce the indicator using the trading software's formula language;3. Comment style, parameter naming, etc., must match the format specification sample.[Constraints]1. Definitions must stay faithful to the source; do not invent or add/remove parameters;2. For built-in functions the formula language does not support, explain whyand give an equivalent alternative;3. File reading, formula generation, and correction must be logged step by step.[Output]1. Indicator definition summary (with the corresponding document section or page);2. Complete formula code;3. Execution log.
This template looks simple, yet it embodies four key design choices:
- Context completeness: providing both the “knowledge source” (the report) and the “format constraint” (the sample file) keeps the model from guessing indicator definitions from memory;
- Task decomposability: extraction, implementation, and logging have clear boundaries, so the model can proceed step by step;
- Explicit constraints: inventing parameters is prohibited, and citing the source is required;
- Process traceability: keeping an execution log gives humans something concrete to review against.
2.3 Execution result
After reading the document and locating the relevant section, the agent wrote the indicator formula according to the specification, and the execution log was written to disk at the same time. The real test of the model came in the validation stage: when the formula ran in the target software, the platform threw an error—it did not support the required median function.
This is a very common “platform difference” problem in reproduction: for the same statistical concept, different trading software offers very different built-in function sets. For example, a “window median” has a ready-made function on some platforms and must be implemented manually on others.
The developer fed the error message back to the model. After checking the platform’s function library, the model gave an alternative implementation based on a “rank counting” idea:
// Scenario: the platform provides no median function, so a window median must be implemented manually// Idea: the median is the sample in the middle position after sorting;// for each historical position, count how many closes in the window are smaller than it;// that count is its rank (starting from 0);// when the rank equals the middle position, that price is the median.// Note: illustrative code; parameter names and syntax follow the target platform's documentation.N:=MID_LENGTH; // window length (an odd value here, to keep it simple)MID_POS:=INT((N-1)/2); // middle position (starting from 0)// Enumerate the price at each historical position in the windowLOWER_CNT_0:=COUNTIF(CLOSE<REF(CLOSE,0),N);LOWER_CNT_1:=COUNTIF(CLOSE<REF(CLOSE,1),N);LOWER_CNT_2:=COUNTIF(CLOSE<REF(CLOSE,2),N);// ...... and so on, up to N-1// The close at the middle position is the window medianMED:=IF(LOWER_CNT_0=MID_POS,REF(CLOSE,0),IF(LOWER_CNT_1=MID_POS,REF(CLOSE,1),IF(LOWER_CNT_2=MID_POS,REF(CLOSE,2),/* ...... remaining branches omitted ...... */ 0)));
For this odd-length window, the idea can be understood through the lens of playing cards:
- Lay out the N samples in the window one by one;
- Flip over one card and count how many cards before it are smaller;
- When a position’s count equals MID_POS, that card is the median.
If no such position exists, there are duplicate values. In that case, you should specify how to handle duplicates—for example, take the first matching position—and note it in the comments.
If the window length is even, the median is the average of the two middle samples, so you need to find both the MID_POS and MID_POS+1 positions and average them. If the platform supports loops, you can also use a loop to enumerate instead of nesting branches, which reduces code duplication.
This correction took only one round, and the formula then passed the test.
2.4 The difficulty is in “looking things up,” not “writing code”
This case is a reminder that the real value of coding assistance may not lie in whether the model can write a piece of complex code, but in whether it can quickly narrow down the search. When humans hit a similar error, they usually need to:
- Consult the function manual;
- Search community resources;
- Iterate through trial and error.
An agent, by contrast, can close the loop in a single session: read the function library → locate what is missing → design an alternative → generate code.
Of course, the correctness of the alternative still needs human confirmation, including three points:
- Whether it covers boundary cases like even windows and duplicate values;
- How to handle the case when there are fewer than N periods of historical data;
- Whether it matches the original definition’s conventions.
In fact, the logical complexity of an indicator sets the upper bound on reproduction difficulty:
- Ordinary moving-average indicators (simple moving average, exponential moving average, multi-MA combinations, and so on) are relatively straightforward to reproduce and make good entry-level scenarios for an agent-assisted workflow;
- Indicators involving quantiles, rolling regression, event statistics, state-machine-style signals, and similar logic demand far more in terms of document comprehension, syntax mastery, and boundary-condition handling.
3. Where the capability gains come from: three technical dimensions
Behind the experience above are several common technical advances in LLMs for the coding-agent scenario. These advances are not exclusive to any single model but are directions the industry broadly explores.
3.1 From “single-turn answers” to an “agentic closed loop”
Early conversational coding usually followed an “ask—answer—paste” pattern: the model only generated code snippets, and debugging and validation depended entirely on the developer.
Agentic coding tools embed the LLM in a loopable execution framework:
- The model reads files, parses documents, and calls the command line to run scripts;
- The execution result (success or error) is fed back to the model;
- The model revises the code based on that feedback and runs it again.
Throughout, the model and the developer share the same working directory and execution log. The median correction above is a typical example of this loop: the model did not “guess” an alternative but made a targeted correction based on the platform’s feedback.
3.2 Active thinking and interleaved reasoning
In complex coding tasks, if a model generates code directly, it often lacks global planning and tends to hit two problems:
- Missing boundary conditions;
- Multiple edits conflicting with each other.
So some LLMs now enable a “thinking mode” by default, having the model analyze requirements, break down steps, and anticipate risks before answering. Going further, “interleaved thinking” means that after calling a tool for external information, the model does not mechanically splice the result into the answer but continues reasoning between tool calls and then decides the next action.
The effect can be understood as “think while you do,” rather than “finish thinking, then do” or “guess while you do.” It is closer to how a human researcher works—look things up, make a judgment, look things up again—and it effectively reduces the tendency to “go down a single path to the end” after a tool call fails.
3.3 Output stability and context management
A coding agent can be seen as a sense-and-act loop: special markers in the model’s output decide whether it “speaks” or “calls a tool,” and even a slight parsing deviation can break the loop. Structured output formats and high output stability are therefore prerequisites for a coding agent to run reliably. The former is constrained through conventions and post-processing; the latter depends on the model’s own generation quality.
The context window matters just as much. A long context can hold a whole research report and several specification files, but it also brings problems: irrelevant content crowds out attention and can trigger a “lost in the middle” effect, driving up costs. A newer line of thinking seeks a balance between “enough” and “focused,” rather than pursuing ever-longer contexts.
4. Methodology: a reusable “six-step workflow”
Drawing on the case above, LLM-assisted indicator reproduction can be abstracted into a general process.
Step 1: Grade the task
Not all tasks suit the same treatment. Tasks can be graded by “logical complexity × code volume” into three levels:
- Lightweight: single-file edits, writing functions from comments, explaining errors—handled directly in conversation;
- Medium: cross-file changes, extracting definitions from documents and generating code to spec—suited to agentic mode;
- Heavy: reproducing an entire research-report strategy from scratch (data processing, factor calculation, and performance evaluation)—needing a multi-round “decompose—implement by module—integrate and validate” cycle.
Choosing the right tool and level of scrutiny by task grade improves efficiency and controls risk.
Step 2: Write structured prompts
A high-quality prompt should contain six elements:
- Role and goal;
- Input files and their purpose;
- Specific tasks and steps;
- Constraints (no invention, cite sources);
- Output format (code, comments, log);
- Acceptance criteria.
Also, prefer having the model read real files rather than pasting large blocks into the prompt. This reduces truncation and omission from copy-paste and keeps the model’s attention on the task itself.
Step 3: Set up a project-level rules file
Maintain a rules file in the project root (for example, a conventions file) containing:
- The target platform’s formula syntax and comment conventions;
- Common parameter-naming habits;
- A list of the platform’s function library, plus known missing functions and their alternatives;
- The record format for reproduction results.
The coding agent reads this file as project context. When formatting requirements change, you only update the file rather than repeating instructions each time.
Step 4: Use a “capability list” to handle missing functions
For platform differences, keep a capability list for each target platform, including:
- Supported built-in functions and their syntax;
- Known unsupported functions and verified equivalent alternatives;
- The scope and boundary conditions of each alternative.
With this list, both humans and models can quickly locate a suitable implementation when hitting a similar problem. The “rank counting” median implementation above is exactly the kind of entry that can be added to the list.
Step 5: Run an independent validation loop
Always remember: model-generated code is only a draft, and the validation responsibility stays with the developer. Three checks are recommended:
- Syntax check: compile or dry-run on the target platform to ensure the formula parses;
- Unit validation: hand-build small samples (for example, the five numbers 1 through 5) and compare outputs with theoretical values, focusing on even windows and duplicate values;
- Result validation: replay the indicator on historical data, compare against the report’s charts, and run parameter sensitivity tests where needed.
Only after all three pass do you move to the next research step.
Step 6: Keep logs and manage versions
Both execution logs and code should be under version control:
- Record the reason for each change;
- Record the assumptions and sources the model gave;
- Keep rollback-able historical versions.
This is the basis for teamwork and the evidence for later review and audit.
5. Human-AI collaboration: boundaries, risks, and benefits
5.1 View capability boundaries objectively
LLMs’ coding ability has improved markedly but still lags the world’s top level:
- For highly complex, very long-context engineering tasks, the one-shot success rate still has room to grow;
- Understanding of multimodal material like report charts and scanned documents is limited;
- “Correct” generated code does not equal an “effective” strategy.
So a reasonable expectation is: the agent handles heavy information retrieval, code generation, and first-round debugging, while humans own problem definition, key decisions, and final acceptance.
5.2 Risk control
- Hallucination and fabrication: require the model to cite sources, and do not accept content without them;
- Code defects: scenarios like parameter boundaries and insufficient historical data must be handled explicitly;
- Data compliance: when handling copyrighted material such as research reports, comply with relevant laws, regulations, and usage licenses;
- Sensitive information: do not upload code or data containing personal privacy or institutional secrets to external services.
5.3 Measuring the payoff: back to the “meta-task”
To evaluate the value of these tools, you should not look only at the time to write a single formula but return to the “meta-task” level—the total time a piece of work takes from start to finish. A complete indicator reproduction usually includes reading the report, consulting the platform manual, writing the formula, debugging, validating, and writing documentation. The debugging step is often the hardest to estimate and the part where agent assistance pays off most clearly.
In many teams, what is truly scarce is not coding ability but the composite talent who understands both research-report logic and platform syntax. Coding-assistance tools can significantly lower the staffing bar for such tasks.
As for which usage mode to adopt, there are two common choices:
- Subscription coding plans: suited to developers who use them long-term and frequently, with relatively predictable costs;
- Pay-as-you-go API calls: suited to occasional tasks or embedding into your own systems, with more flexible elasticity.
For enterprises whose core is LLM capability, cloud platforms such as Baidu AI Cloud offer model services that let you flexibly combine model capabilities and compute resources on demand. Paired with the platform’s data-processing, storage, and monitoring and operations capabilities, you can bring applications online and keep them running stably faster. Whichever mode you choose, cost evaluation should be tested on real business tasks.
6. Conclusion
From “one or two weeks of manual work” to “a first reproduction in an hour,” what changed is not just the model’s parameters and benchmark scores but the restructuring of how humans and AI collaborate. Document parsing, domain translation, code generation, and log-keeping are connected within the agentic loop, freeing researchers to focus their energy where judgment really matters.
For developers, the next step is not to wait for a “stronger model” but to accumulate the prompt templates, project rules files, platform capability lists, and validation process as team assets. Models will keep iterating, but this methodology is the “compound interest” that can be reused over the long term.
