Reliable Reproduction of Research-Report Indicator Formulas
Complex indicator formulas from research reports often fail at the last step because of mismatches across definitions, chart conventions, formula languages, and market data. This article describes a contract-driven workflow—extracting computable semantics, listing platform capabilities, implementing in short cycles with logs, and verifying in the terminal—so you get an explainable, regressable implementation instead of a one-shot “perfect” formula.
Why Complex Formula Reproduction Fails at the Last Step
Turning a quantitative or technical-analysis research report into a runnable indicator looks like “read the document and write the formula.” In practice it is a translation across representations: natural-language definitions, implicit chart conventions, the function set of a formula language, and price adjustment and bar period of market data. If any of these disagree, the curve diverges from the original.
AI coding tools can shorten a first draft, but complex work still fails in three typical ways: unstable extraction from long documents, constraints dropped mid-tool-call, and outputs that lack intermediate artifacts you can review.
The goal should not be “generate a perfect formula in one shot.” It should be “within a limited number of rounds, produce an implementation that is explainable, regressable, and can be pasted back into a terminal for human verification.” Reliability comes from process, not from a confident single answer.
Split the Task into an Acceptable Contract
Before coding, freeze the boundaries on one page so the model does not invent freely on open questions.
- Input scope: Use only the specified report sections and formula examples the user provides. Do not fill definitions with “industry common sense” from outside the document.
- Output shape: Comments, variable names, assignment order, and period-function style must match the examples. Keep comments separate from formulas so they are easy to paste.
- Success criteria: Explain the economic meaning of each intermediate; if a function is missing, give an equivalent implementation instead of pretending it exists; keep a log of the whole process.
- Explicit non-goals: Do not change trading rules, optimize parameters on your own, or treat backtest conclusions in the report as verified facts.
Shorter contracts work better. Timing indicators often mix trend filters, volatility regimes, and signal confirmation. Asking to “read the full paper and reproduce the whole strategy” at once fills context with irrelevant chapters and dilutes the definition sentences.
Extract Definitions with Computational Semantics
When reading the report, extract computable objects rather than a summary. Structure notes with fields such as:
- Names and aliases: whether the indicator means the same thing in body, charts, and appendix.
- Input series: price, volume, or existing moving averages; whether adjusted prices are required; whether the default period is daily or parameterized.
- Windows and aggregation: simple average, weighted, median, quantile, or extrema; fixed-length windows versus state-dependent ones.
- State switches: when to use a fast line, a slow line, or hold the previous value.
- Signal rules: crosses, thresholds, N-bar confirmation, and whether the signal may use future data.
- Unspecified items: list them side by side; do not fill gaps by guessing.
“Moving average” in different texts may mean an arithmetic mean or a composite curve with state switching. Quote key definitions at sentence level and mark page location or section title for lookup. If a definition lives only in a figure note or formula image, transcribe the symbol table to text before coding. Generating from the figure alone often misses initialization and edge bars.
Inventory Formula-Language Capabilities First
Terminal formula languages are not general-purpose programming languages. Common gaps include no median or quantile, restrictions on recursive variables, limited nesting of logical expressions, and inconsistent null handling in series functions. List what the language actually provides, then write the formula.
For median: if the runtime has no median, do not call a nonexistent identifier. When the definition allows it, express the median with explicit element selection or odd/even-length branches. If the language cannot even sort, state clearly that the document definition cannot be implemented equivalently, and give the closest alternative with the deviation labeled—do not silently switch to a mean. After a failure, change only the statements related to the gap so a full rewrite does not introduce new errors.
Illustrative structure (organization only, not a vendor dialect):
// Input: CLOSE, window N, state threshold as defined in the report// Constraint: do not use an unavailable median; express median via explicit selection// Intermediates: ma_fast, ma_slow, vol_state, icu// Output: icu, signal
Putting constraints in comments is less likely to be lost in later edits than repeating them in chat.
Interleave Reasoning to Bound Errors
For multi-step work, effective reasoning is not a long plan followed by all the code at once. Alternate in short cycles: read one definition, land one intermediate, self-check with assertions, then proceed. Errors stay confined to a single series.
A practical cadence:
- Plan: sketch a variable dependency graph; mark quantities that depend on future bars versus those that must recurse on prior values.
- Implement: add one intermediate series at a time, plus one line stating the relation it should satisfy on sample points.
- Self-check: division by zero, insufficient window, null propagation, and whether the signal uses data from a bar that has not closed.
- Converge: tick each definition clause; leave uncovered items as unconfirmed rather than pretending they are done.
Longer context is not always better. Huge history mixes early wrong formula versions with correct constraints, and models more easily “fix” a draft already rejected. Keep stable constraints at the top of the task brief; compress failed attempts to “cause of error + correct fragment to keep.” Stability also depends on granularity: extract definitions first, generate formulas after confirmation, and rewrite for missing functions last.
Log Tool Calls; Do Not Only Look at the Final Answer
If an agent reads documents, edits files, and runs checks, every step should leave a log: which section was read, extracted definition quotes, formula version, human-reported errors, diffs, and reasons for change. Logs enable regression: the same checklist can be reused on the next report instead of relying on one lucky conversation.
Suggested checklist:
- Definition coverage: every output variable traces to a report sentence.
- Legal functions: every call is in the target language’s function table.
- Legal time: no future data in signals; recursion has initial values.
- Numerical robustness: short samples, halted trading, and zero volume do not divide by zero or infect the whole series with nulls.
- Complete comments: parameter meaning, units, and default period so someone else can take over.
- Deviation notes: if a non-equivalent substitute was used, list the bias separately; do not bury it in main formula comments.
Pasting the formula back into the terminal for comparison remains necessary. Generation only shows that the code looks right, not that it matches the report’s curve. Hold adjustment method, symbol, and interval fixed; inspect intermediates before the final signal. If intermediates already diverge, do not tune signal thresholds first.
When a “Preliminary Reproduction” Is Actually Done
Shorter elapsed time is not completion. A preliminary reproduction should jointly satisfy: definition clauses ticked, formula loads in the target environment, missing capabilities handled explicitly, and a log that a third person can replay. Parameter search, out-of-sample tests, commissions, and slippage are not this stage; stuffing them into generation only enlarges hallucination.
More useful developer metrics are process metrics, not slogans of “stronger models”: missed clauses in first-round extraction, edits from missing-function to a runnable version, pass rate of similar tasks under a fixed checklist, and volume of human revision. These do not depend on model rankings and support team review.
How People and Tools Should Collaborate
People own semantics and acceptance; tools expand and rewrite. Ambiguous sentences, unlabeled initial values in figures, and whether approximation is allowed in the business must be decided by a person. Tools fit mechanical work: layout to the example, expanding branches from confirmed definitions, recording diffs in the log. Limit “thinking” to confirmed facts and crash rates drop. Letting the model invent rules the report never wrote makes errors look fluent and harder to catch.
With contract, extraction, capability inventory, stepwise implementation, and log replay, “read a report and write an indicator” becomes an engineering task of one extraction pass plus limited corrections, not an unbounded chat. That is what AI coding tools should deliver here: a traceable implementation, not an unverifiable one-shot success.
