LLM Agents for Quantitative Analysis and Financial Research Report Generation
This article examines how large language model agents can move beyond chat-style answers to support end-to-end quantitative analysis and financial research report generation. It covers task decomposition, tool use, code-based data processing, chart generation from real data, PDF report assembly, common sources of result variance, key limitations, and engineering practices such as data validation, audit trails, number consistency checks, separation of facts and opinions, and human review. The goal is to show a reliable division of labor: the model plans and explains, programs calculate, visualization tools present data, and human review ensures final quality.
1. From Chat-Style Answers to Executable Analysis
The value of large language models in finance and quantitative analysis is no longer limited to explaining concepts, generating text, or completing code. A more practical direction is to let models participate in complete tasks as agents: understanding goals, breaking down steps, reading data, writing programs, calling tools, validating results, and finally producing structured reports.
For example, a user may ask:
Read the specified spreadsheet, calculate the quantiles of inventory and basis, analyze the reasons for recent changes using recent market materials, generate trend charts, and compile the text and charts into a PDF research report.
If the model is relied on to answer directly, several problems can arise. First, numbers in the spreadsheet may be misunderstood. Second, complex calculations may be approximated. Third, chart data and textual conclusions may be inconsistent. Fourth, the model may present uncertain information as established fact.
The core improvement of the agent pattern is to turn the model from an “answer generator” into a “task execution coordinator.” The model understands requirements and writes execution logic; actual calculations are handled by programs; external materials are obtained through retrieval tools; and final results are checked and summarized.
2. Typical Workflow: Task Decomposition, Tool Calls, and Result Aggregation
A relatively complete intelligent analysis workflow usually includes the following stages.
2.1 Define Inputs, Outputs, and Constraints
At the start of a task, data sources, field meanings, calculation definitions, time ranges, output formats, and precision requirements should be specified as clearly as possible. For example:
- The input file contains fields such as date, inventory, price, and basis;
- Quantiles are calculated over a specified historical interval;
- Missing values must not be treated directly as zero;
- Results retain a specified number of decimal places;
- Charts must use actual calculation results;
- The report must include data descriptions, conclusions, risk notes, and a methodology appendix.
The clearer the constraints, the less likely the agent is to produce ambiguity.
2.2 Automatically Build a Task List
Agents typically break complex requirements into multiple subtasks, such as:
- Check whether the file exists and read the spreadsheet;
- Identify field names and data types;
- Clean missing values, duplicate values, and abnormal dates;
- Calculate statistical indicators for inventory and basis;
- Generate trend charts, quantile charts, or comparison charts;
- Retrieve public information related to data changes;
- Write analytical conclusions;
- Merge text, charts, and data descriptions into a PDF;
- Perform a consistency check on the final document.
This task list has two benefits. First, it helps users understand what the model is doing. Second, if a step fails, the problem can be located instead of restarting the entire workflow.
2.3 Process Structured Data Through Code
For spreadsheets, time series, and statistical indicators, it is not advisable to let the model perform “mental arithmetic” directly from context. A more reliable approach is to have the agent generate and execute a Python script.
Example code:
import pandas as pddf = pd.read_excel("market_data.xlsx")df["date"] = pd.to_datetime(df["date"], errors="coerce")df = (df.dropna(subset=["date", "inventory", "basis"]).drop_duplicates(subset=["date"]).sort_values("date"))inventory_quantile = df["inventory"].rank(pct=True).iloc[-1] * 100basis_quantile = df["basis"].rank(pct=True).iloc[-1] * 100print(f"Inventory quantile: {inventory_quantile:.2f}%")print(f"Basis quantile: {basis_quantile:.2f}%")
The key point is not how complex the code is, but that the calculation process is reproducible and auditable. With the same file and the same calculation definitions, the program should produce consistent results. Users can also inspect the code to confirm whether the quantile method, missing-value handling, and time range meet business requirements.
3. Why Programmatic Calculation Is More Reliable Than Directly Generated Numbers
When large models output numbers, they may be influenced by context, training samples, and language expression habits. For simple arithmetic, this problem may not be obvious. But with multiple columns, long time series, or multi-step statistical tasks, the model may introduce the following deviations:
- Confusing adjacent fields;
- Ignoring some data rows;
- Misunderstanding percentiles versus percentages;
- Including missing values in calculations;
- Retaining only approximate values;
- Producing inconsistent numbers across paragraphs;
- Mismatching calculation results and chart data.
Therefore, a more reasonable division of labor is:
- The large model understands natural-language requirements;
- Programs read data and perform precise calculations;
- Visualization libraries draw charts based on real data;
- Retrieval modules obtain external materials;
- The large model explains results and organizes them into a report.
This architecture does not eliminate all errors, but it significantly reduces the risk of “guessing numbers from memory.”
4. Chart Generation: Real Data and Visual Expression Must Be Separated
In financial research reports, charts are not decoration; they are important evidence for conclusions. Agents can call Python visualization libraries to generate line charts, bar charts, scatter plots, and distribution charts based on data.
Example code:
import matplotlib.pyplot as pltplt.figure(figsize=(10, 5))plt.plot(df["date"], df["inventory"], label="Inventory")plt.plot(df["date"], df["basis"], label="Basis")plt.title("Market Indicators")plt.xlabel("Date")plt.ylabel("Value")plt.legend()plt.grid(alpha=0.3)plt.tight_layout()plt.savefig("indicator_trend.png", dpi=160)
Programmatic charting is fundamentally different from image generation models. Every point in a programmatic chart comes from explicit data and coordinate mapping, so it is suitable for statistical analysis, trend assessment, and research reports. Image generation models are better at visual expression, but they are not suitable for precise numerical presentation, especially as replacements for serious statistical charts.
In practical applications, the following details also need attention:
- Chart titles should state the indicator and time range;
- Axes should be labeled with units;
- Multiple curves need clear legends;
- When indicators have very different scales, use dual axes or separate panels;
- When there are too many data points, avoid overlapping labels;
- After generating images, check for garbled text, truncation, or distorted proportions.
5. From Data Analysis to Automatically Generated PDF Research Reports
After data calculation and chart generation are complete, the agent can further generate daily reports, weekly reports, or thematic research reports. A complete report usually includes:
5.1 Summary
Use a short section to describe the current indicator status, main changes, and potential impacts, so readers can quickly understand the conclusions.
5.2 Data Overview
Explain data sources, time intervals, field definitions, missing-value handling, and calculation methods. For professional reports, this section cannot be omitted; otherwise, readers cannot judge whether the conclusions are reproducible.
5.3 Indicator Analysis
Present changes in indicators such as inventory, basis, price, and trading volume separately, and explain them using quantiles, period-over-period changes, year-over-year changes, and historical ranges.
5.4 Charts and Key Observations
Each chart should be accompanied by a brief explanation of trends, turning points, and abnormal intervals, rather than simply stacking images in the document.
5.5 External Information and Risk Notes
If online retrieval or a local knowledge base is used, facts, inferences, and opinions should be distinguished. Information with uncertain sources must not be written directly as a definitive conclusion.
5.6 Methodology Appendix
Retain calculation definitions, core code, field mappings, and exception-handling rules for later review.
During document generation, the agent can first generate Markdown or HTML and then convert it to PDF. Whichever method is used, the exported document should be checked again for page layout, fonts, chart clarity, page numbers, and table overflow.
6. Common Result Differences in Practical Testing
On the same dataset, different agents may produce slightly different results. Such differences do not necessarily mean that one model is “completely wrong”; they may come from the following causes:
- Different definitions of the quantile algorithm;
- Whether the current data point is included;
- Different historical windows;
- Different handling of missing values and outliers;
- Deviations in understanding field meanings;
- Different decimal-place and rounding rules.
Therefore, when comparing agents, it is not enough to look only at the final percentage. Comparisons should also consider:
- Whether all data was read correctly;
- Whether the calculation formula was shown;
- Whether the statistical interval was specified;
- Whether executable code was retained;
- Whether the same result can be reproduced;
- Whether the report distinguishes raw data from inferred conclusions.
Only when calculation definitions are fully consistent does result comparison become meaningful.
7. Major Limitations of Agents in Financial Scenarios
Although agents can automate many tasks, they are still not researchers who require no supervision.
First, the model may misunderstand business fields. For example, “inventory” may refer to spot inventory, deliverable inventory, or inventory in a specific region. The same field name does not necessarily mean the same thing.
Second, the timeliness and authenticity of external materials require human confirmation. Retrieved content may be duplicated, outdated, or missing context. The agent cannot automatically guarantee that every piece of information is suitable for inclusion in a research report.
Third, the model may over-interpret data in order to make the article fluent. Statistical correlation is not causation, and short-term price changes cannot simply be attributed to a single factor.
Finally, PDF generation does not mean the report quality is complete. Layout, citations, number consistency, and risk statements still require human review.
8. Recommended Engineering Practices
To make agents more suitable for production environments, the following mechanisms can be established.
8.1 Data Validation
Add field checks, type checks, date continuity checks, and outlier alerts to scripts. When key fields are missing, the workflow should stop rather than continue generating conclusions.
8.2 Result Traceability
Save original files, cleaned data, intermediate calculation results, execution logs, and final reports to form a complete audit trail.
8.3 Number Consistency Checks
Automatically extract key numbers from the report and compare them with program outputs. When inconsistencies are found, require the model to revise the report.
8.4 Separation of Facts and Opinions
Clearly label “data facts,” “model inferences,” and “analytical opinions” in the report to prevent readers from mistaking predictive content for objective facts.
8.5 Human Approval Points
For reports involving trading decisions, risk judgments, or external publication, human review should be required. The agent is responsible only for improving efficiency, not for replacing the final responsible person.
Conclusion
The real value of a new generation of large model agents is not simply generating a paragraph that looks professional. It is connecting natural-language requirements, code execution, data analysis, visualization, and document production. For quantitative research and financial reporting scenarios, the most reliable approach is not to let the model guess results directly, but to let the model plan and explain, let programs calculate, let charting tools present, and then ensure final quality through validation and human review.
In cloud environments such as Baidu AI Cloud, such workflows can be further combined with general capabilities such as object storage, container platforms, logging services, task scheduling, and monitoring and alerting to form a data analysis system that can run repeatedly, be traced, and scale. Regardless of where it is deployed, accurate data definitions, transparent calculation processes, and strict result review remain the foundation for putting intelligent analysis into practice.
