LLM Agents for Quantitative Analysis and Research Report Generation: A Practical Guide

    This article explains how to build and evaluate LLM-agent workflows for quantitative analysis and financial research reporting. Instead of judging models only by answer quality, it focuses on task delivery: data validation, deterministic computation, code interpretation, reproducible percentile calculations, data-driven charts, constrained report writing, final acceptance checks, and security controls. It also outlines how to assess such systems with fixed datasets, independent recomputation, and traceable evidence.

    1. Evaluate LLM Capability by Task Delivery, Not Answer Quality Alone

    In quantitative analysis and financial research, users usually do not need a polished explanation. They need an analysis output that can be checked, recomputed, and traced. For example, an agent may need to read inventory and basis data, explain the calculation logic in factor code, determine where the current indicator sits within its historical range, and then integrate charts and analytical conclusions into a readable report.

    Such tasks involve multiple interdependent steps: reading files, identifying fields, cleaning data, running calculations, retrieving materials, drawing charts, and formatting the output. An error in any step can make the final report misleading.

    The value of the agent pattern is that it moves an LLM from simply generating text to planning tasks and calling controlled tools to execute operations. However, the ability to automate a workflow should not be treated as proof that the analytical result is correct.

    At minimum, evaluation should distinguish three layers:

    • Workflow completion: whether the agreed steps were completed and whether an openable deliverable file was generated.
    • Computational correctness: whether explicit definitions were used and whether the results can be independently recomputed.
    • Conclusion credibility: whether the text is supported by data and whether facts, inferences, and uncertainties are distinguished.

    A polished report may contain calculation errors. A report with correct numbers may still draw unreliable conclusions because of an inappropriate time range or business interpretation. Technical implementation must cover all three layers.

    2. Clear Division of Labor: Models Understand, Computation Programs Handle Numbers

    Language models are good at understanding natural-language requirements, explaining code, decomposing tasks, and organizing text. They should not be used directly as precise calculators. Especially with long tables, complex filters, missing values, and multiple statistical definitions, generating answers from context alone can easily omit records or confuse rules.

    A safer approach is to let the model translate analytical intent into executable calculation steps, and then let deterministic computation programs process the data.

    For example, if a user asks, “Analyze whether current inventory is at a historical high,” the agent should clarify:

    1. Which inventory metric is used, and what is its unit?
    2. Which date does the current value correspond to, and is it the last valid observation?
    3. How long is the historical comparison window, and does it include the current value?
    4. Is there seasonality, and should the comparison use the same season or the full history?
    5. How should percentiles handle duplicate values and missing values?

    Only after these questions are resolved should calculation begin.

    A common misconception should be corrected: program execution does not change arithmetic rules because of uncertainty in language generation, but a program can still execute the wrong formula, read the wrong field, or use the wrong data. Deterministic execution solves the problem of “calculating according to given rules”; it does not automatically prove that “the rules themselves are correct.”

    Therefore, reliability requires three conditions to hold together: trusted data, clear definitions, and correct implementation.

    3. Start with Quantitative Code Understanding and Build a Complete Analysis Chain

    3.1 Define Input and Delivery Boundaries

    Before a task starts, establish an input checklist, including data files, field descriptions, factor source code, report date, research subject, and the scope of external materials allowed.

    Field descriptions are especially important. A field named “inventory” may refer to warehouse inventory, social inventory, or deliverable inventory. A field named “basis” may also use different price sources and contract selection rules. A model cannot reliably infer the business definition from the field name alone.

    Delivery requirements should also be specific, for example:

    • Output cleaned data and a list of anomalous records.
    • Retain the metric calculation logic and execution records.
    • Generate charts with units, time ranges, and source notes.
    • Output the main text, charts, and final report file.
    • Explicitly mark data or opinions that cannot be confirmed.

    3.2 Interpret Source Code, Not Just Summarize Function Names

    When analyzing factor code, focus on data dependencies, calculation formulas, time alignment, and exception handling, rather than only explaining that “this code calculates a certain indicator.”

    For code involving historical backtesting, also check for look-ahead bias. For example, using subsequently revised data for historical decisions, or using next-period prices for current-period signals, will distort the analysis.

    In addition, the explanation should cover whether rolling windows require sufficient samples, whether missing values are implicitly filled, and how data at different frequencies is aligned. Code that runs only shows that the syntax and execution path can pass; it does not mean the economic meaning is consistent with the research objective.

    3.3 Break the Workflow into Acceptance Stages

    The following task chain is recommended:

    Input validation → data cleaning → metric calculation → result validation → chart generation → text writing → file layout → final acceptance

    Each stage should produce an intermediate output. In this way, if the final result is abnormal, you can locate whether the issue comes from data, definitions, calculation, or textual explanation without rerunning the entire task.

    4. Why Percentiles Often Produce Different Results

    Percentiles are common in quantitative analysis and prone to definition differences. When discussing “what historical percentile the current value is in,” the task is usually to calculate the historical percentile rank of the current value, not directly to find the quantile point corresponding to a probability. The two are related but not the same.

    Let the number of valid historical samples be n and the current value be x. Several definitions can be used:

    • Strictly less than: the number of samples less than x divided by n.
    • Less than or equal to: the number of samples less than or equal to x divided by n.
    • Midrank: samples equal to x are counted as half in the ranking.

    An illustrative calculation logic is as follows:

    1. valid_samples = historical data after removing missing values
    2. count_less = number of valid samples strictly less than the current value
    3. count_equal = number of valid samples equal to the current value
    4. strict_percentile = count_less / number of valid samples
    5. inclusive_percentile = (count_less + count_equal) / number of valid samples
    6. midrank_percentile = (count_less + 0.5 * count_equal) / number of valid samples

    Suppose there are 10 valid samples, of which 4 are less than the current value and 2 are equal to the current value. The three definitions then produce 40%, 60%, and 50%, respectively. These are illustrative calculations and do not represent any actual business data, but they are enough to show that different results may come from different definitions rather than from a model calculation error.

    Additional factors that affect the result include:

    • Whether the historical window uses all data or only the most recent periods.
    • Whether the current value is included in the comparison sample.
    • Whether the data has been revised, deduplicated, or processed for outliers.
    • Whether the comparison uses the same season or the same trading session.
    • Whether date sorting and data frequency are consistent.

    Therefore, different numbers from multiple systems cannot by themselves be used to determine which one is more accurate. Data and algorithms must first be aligned, and then an independent implementation should be used for recomputation.

    For seasonal indicators such as inventory, full-year historical ranking and same-season historical ranking may also express different meanings. The report should state the comparison object rather than only giving a percentage.

    5. Professional Charts Must Be Data-Driven

    Charts in quantitative research reports should be generated by data visualization programs so that every point, bar, and curve corresponds to explicit data or calculation results.

    Visually generated images can be used for covers and conceptual explanations, but they should not be responsible for precisely expressing prices, yields, inventory, or percentiles. Looking like a statistical chart does not mean its axes, values, and proportions can be verified.

    A qualified research chart should include at least:

    • Metric name, time range, and unit of measurement.
    • Data source and update date.
    • Legend and necessary definition notes.
    • Indications of missing intervals or anomalous points.
    • Numerical expressions consistent with the main text.

    Also avoid using truncated axes to exaggerate changes, or using unexplained dual-axis relationships to imply correlation. If price and inventory are shown together, clarify their units and, when necessary, split them into vertically stacked charts.

    After automatic generation, the actual rendering must be checked. Missing glyphs, label occlusion, legend overlap, and insufficient export resolution are all problems that can still occur after a program has executed successfully.

    6. From Calculation Results to Research Reports: Constrain Text Generation

    The main text of a research report should not rely directly on model memory to generate market judgments. Instead, content should be organized based on confirmed data and evidence.

    Conclusions should be divided into three layers:

    The first layer is facts. For example, how much inventory increased compared with the previous period, and what its historical rank is. These should correspond directly to calculation outputs.

    The second layer is interpretation. For example, an inventory increase may be related to higher arrivals or changes in demand. Such explanations need supporting materials; statistical changes should not be written directly as certain causality.

    The third layer is scenario judgment. For example, if inventory continues to increase and demand does not improve, prices may face pressure. Such judgments should retain conditions and uncertainty and should not be packaged as certain forecasts.

    Web or knowledge base retrieval also needs to record publication time, source, and scope of application. Outdated information, duplicate reposts, and unconfirmed rumors should not be placed at the same evidence level as verified data.

    For financial analysis, especially avoid jumping from a single indicator to a trading conclusion. A high inventory rank does not automatically mean prices must fall. Basis changes also need to be interpreted together with term structure, delivery conditions, and market supply and demand.

    7. Automated Layout Is Not the Last Step; Acceptance Is

    Merging text and charts into a PDF file completes the delivery action, but it does not complete quality inspection.

    Final acceptance should include four types of checks:

    Numerical Consistency

    Whether the main text, tables, and charts use the same calculation results. Values should be read from a unified structured result rather than repeatedly entered or recalculated at multiple stages, which helps avoid inconsistency between charts and text.

    Content Completeness

    Whether the data cutoff date, historical interval, units, calculation definitions, and limitations are complete. Without this information, even correct numbers are difficult for others to reuse.

    File Readability

    Check pagination, fonts, table truncation, image proportions, and page numbers. It is best to also retain an editable source document for revision and review.

    Evidence Traceability

    Whether key conclusions can be traced to input data, calculation scripts, or cited materials. If a certain step fails, it should be clearly reported rather than concealed by fluent text.

    8. Enterprise Deployment Also Requires Permission and Security Controls

    Financial data may contain account information, trading records, or internal research materials. When an agent can read files, execute programs, and access the network, permission boundaries must be part of the design.

    It is recommended to use an isolated execution environment, expose only necessary directories, restrict unrelated network access by default, and require approval for high-risk operations such as modifying files or sending data. Instructions in input materials should also be treated as untrusted content. They should not be allowed to change task rules or obtain additional permissions simply because they appear in a document.

    Each run should also retain the association between input versions, calculation definitions, execution records, and output files. For important reports, human review should be introduced, focusing on outliers, key conclusions, and externally disclosed content.

    Resource control is equally important. Long tasks need execution time limits, failure retries, and staged checkpoints to avoid losing completed work when interrupted. Calculation results and the report outline can be confirmed before full layout to reduce ineffective repetition.

    9. How to Form an Objective Evaluation of Usage

    Evaluating the agent experience should be based on fixed datasets and clear acceptance criteria, not only on whether a single output reads fluently.

    Key observations include: whether the system correctly identifies table structures, proactively detects missing and duplicate data, explains formulas and retains calculation records, whether charts faithfully represent data, whether execution failures are reported honestly, and whether numerical consistency is maintained during revisions.

    A more effective testing method is to gradually add missing values, duplicate dates, unit changes, and anomalous records to the same task, and observe whether the system identifies the problems and requests confirmation. For items that can be precisely calculated, independent recomputation should be used as the benchmark. For textual analysis, check evidence sufficiency, logical completeness, and expression of uncertainty.

    The real value of LLM agents in quantitative analysis is not to replace all judgment, but to organize repetitive data processing and document production into a traceable workflow. Only when calculations are reproducible, charts are verifiable, conclusions are evidence-based, and operations are constrained can automatically generated research reports move from “looking professional” to “being usable in professional work.”