Build Financial Analysis Agents with Claude and Python
A detailed walkthrough from MarkTechPost last week shows how to build skill-driven financial analysis agents using Claude, Python, and the Model Context Protocol. The approach is worth studying not just for finance people — the architecture generalizes to any domain where you want an agent to combine reasoning, computation, and structured output.
The system automates discounted cash flow models, comparable company analysis, sensitivity heatmaps, and investment memo generation. It uses Claude for reasoning, Python for computation, and MCP connectors to pull data from external sources. The result is a reusable agent template that produces analyst-grade deliverables without the analyst sitting at the keyboard for every step.
The architecture
The agent is built around a skill-discovery pattern. Instead of hardcoding which tools the agent can use, the system dynamically discovers available skills — each one a self-contained Python module with a defined interface — and builds a system prompt that includes descriptions of every available capability.
Here is the flow in practice.
The agent starts with a task: “Analyze Company X. Produce a DCF, comps table, sensitivity heatmap, and investment memo.” It scans the skills directory, finds modules for DCF modeling, comps analysis, sensitivity analysis, and memo generation. It builds a system prompt that tells Claude what each skill does, what inputs it needs, and what outputs it produces.
Claude then reasons about which skills to invoke and in what order. It calls the DCF module first to establish intrinsic value, then the comps module to cross-reference against market multiples, then the sensitivity module to stress-test assumptions, and finally the memo module to synthesize everything into a structured report.
Each skill call triggers a Python execution that returns structured data back to Claude. Claude interprets the results and decides the next step. This is not a fixed pipeline — the agent can reorder steps, skip irrelevant analyses, or drill deeper into unexpected results.
The code in practice
The skill-discovery layer is the clever part. Each financial skill is a Python file with a standard interface:
# dcf_model.py
SKILL_NAME = "dcf_model"
SKILL_DESCRIPTION = "Build a discounted cash flow model. Requires: revenue projections, WACC, terminal growth rate."
def run(ticker: str, years: int = 5, wacc: float = None, terminal_growth: float = 0.025):
# Fetch financial data
# Project free cash flows
# Calculate terminal value
# Discount to present value
return {
"intrinsic_value": ...,
"upside_pct": ...,
"key_assumptions": {...},
"sensitivity_table": [...]
}
The agent builder scans the skills directory, imports each module, and extracts SKILL_NAME, SKILL_DESCRIPTION, and the function signature. These get formatted into a system prompt:
You have access to the following skills:
1. dcf_model — Build a discounted cash flow model. Requires: revenue projections, WACC, terminal growth rate.
2. comps_analysis — Run comparable company analysis. Requires: ticker, peer group.
3. sensitivity_heatmap — Generate sensitivity heatmap. Requires: base assumptions, variable ranges.
4. memo_generator — Generate investment memo. Requires: analysis results, template selection.
To use a skill, call: skill_run(name="dcf_model", params={...})
Claude decides which skills to use and in what order. The Python host executes the actual computation. Claude interprets the output and decides what to do next.
This separation — reasoning in the model, computation in the host — is the key insight. Claude is bad at math but good at reasoning about what math to do. Python is good at math but cannot reason about which analyses matter. Combining them gives you the best of both.
MCP connectors for real data
The financial domain is useless without real data. The agent uses MCP connectors to pull live financial data instead of relying on the model’s training data, which would be stale and potentially hallucinated.
The connectors handle authentication, rate limiting, and data normalization. When Claude decides it needs revenue projections for a DCF, it does not guess — it calls the connector, which hits the financial data API, validates the response, and returns structured data that the Python modules can consume directly.
This is the same pattern that makes coding agents work: the model does not memorize documentation, it queries it at runtime. The financial agent does not memorize P/E ratios, it fetches them when needed.
The MCP layer also handles error recovery. If the API is down or returns malformed data, the connector surfaces a structured error that Claude can reason about — “the revenue data for this ticker is unavailable, should I proceed with estimated values or skip the DCF?” The agent does not crash; it adapts.
Automated deliverables
The memo generator is the payoff. After all the analyses run, Claude synthesizes the results into a structured investment memo with sections for:
- Executive summary (thesis in 3 sentences)
- Business overview
- DCF valuation with key assumptions
- Comps analysis with peer benchmarking
- Sensitivity analysis (what happens if growth is 2% vs 5%)
- Risk factors
- Recommendation (buy/hold/sell with price target)
The memo is not a template with blanks filled in. Claude writes each section based on the actual analysis results, adapting the tone and emphasis to what the numbers say. A DCF that shows 40% upside gets a different narrative than one that shows 5%.
The output can be formatted as Markdown, PDF via LaTeX, or injected into a Google Doc template. The deliverable pipeline is configurable — if your firm uses a specific memo format, you template it once and the agent fills it every time.
Why this matters beyond finance
The architecture is domain-agnostic. Swap the financial skills for legal research skills, and you get a due diligence agent. Swap them for clinical trial analysis, and you get a biomedical research agent. Swap them for infrastructure monitoring, and you get an SRE agent.
The pattern is the same everywhere: a language model that reasons about what to do, a set of domain-specific Python modules that do the actual computation, and MCP connectors that feed real data into the loop. The skill-discovery mechanism means adding a new capability is as simple as dropping a new Python file into the skills directory — no prompt engineering required.
This is the direction agent frameworks are heading. Manual tool definitions with JSON schemas and carefully written descriptions are being replaced by self-describing modules that the model can discover and understand at runtime. The financial analysis agent is a clean reference implementation of this pattern.
Getting started
The full code is available on GitHub under the Claude Skills repository. You need:
- An Anthropic API key (Claude Opus or Sonnet for the reasoning layer)
- Python 3.11+ with the Anthropic SDK
- A financial data API key (the reference uses Yahoo Finance for free data, but you will want a paid source for production)
- Optional: MCP server for your financial data source
The setup takes about 30 minutes end to end. Run the skill scanner, point it at your data source, and give Claude a ticker. The first run will fetch data, build models, and produce a memo in about 2-3 minutes depending on API latency.
For teams, the real value is standardization. Every analyst produces memos in the same format, using the same models, with the same assumptions documented. You can diff two memos on the same company a month apart and see exactly which assumptions changed and why — traceability that is hard to maintain when humans write each memo from scratch.
Limitations to know about
The model does not replace a senior analyst — it automates the mechanical parts of analysis so the analyst can focus on judgment. The DCF is only as good as the assumptions, and the assumptions still need human review. Claude will happily project 8% revenue growth for a declining business if the historical data happens to look favorable.
The MCP connectors add latency and points of failure. If your financial data provider changes its API schema or rate limits, the agent breaks. You need monitoring around the data pipeline, not just the agent logic.
The memo quality varies with model quality. Claude Opus produces significantly better analysis and narrative than Claude Sonnet, and both produce better output than GPT-4o. The gap between models matters more here than in simpler agent tasks because financial writing requires nuance — distinguishing between “slightly overvalued” and “run away” is the difference between a useful memo and a misleading one.
Finally, compliance. If you are at a regulated financial institution, every piece of analysis that goes to clients needs review. An AI-generated memo with a hallucinated growth rate or an incorrect peer comparison is a liability. The agent reduces the time to first draft, but it does not eliminate the review step — and in regulated environments, it probably cannot.
How this compares to other agent frameworks
If you have built agents with LangChain or CrewAI, the skill-discovery pattern will look familiar but sharper.
LangChain agents define tools with JSON schemas. You write a description string, specify input parameters, and the agent decides which tool to call based on the description. It works, but the tool descriptions get stale. You add a parameter to a Python function and forget to update the JSON schema, and now the agent calls the function with wrong arguments.
CrewAI takes a role-based approach: define agents with roles, assign tools, and orchestrate them with tasks. The abstraction is higher but the coupling is tighter — changing a role’s toolset requires editing the orchestration code.
The skill-discovery pattern sidesteps both problems. The Python function is the source of truth. The function signature, docstring, and module-level constants define the skill interface. No separate JSON schema to maintain. No orchestration code to update when you add a skill. Drop a new Python file into the skills directory, and the agent discovers it on the next run.
This is the Unix philosophy applied to agents: each skill does one thing well, and the model composes them. It reduces the maintenance burden that makes agent systems fragile over time.
Where this approach breaks
Skill discovery fails when skills have overlapping capabilities. If you have two modules that both claim to do “valuation” — one using DCF, one using residual income — Claude may pick the wrong one or call both redundantly. The system needs clear skill descriptions and, ideally, a way for Claude to ask clarifying questions before invoking.
The approach also assumes skills are stateless and independent. If skill B depends on the output of skill A, but skill A fails silently, skill B produces garbage. The agent needs validation layers between skill calls — check that the DCF produced sensible numbers before feeding them into the memo generator. The reference implementation handles this with return-value validation, but it is worth building explicit checks for production.
Cost scales with model quality. Running Claude Opus for a full financial analysis — multiple skill calls, each requiring detailed reasoning — can cost $0.50 to $2.00 per analysis depending on complexity. That is cheap compared to an analyst’s hourly rate, but it adds up if you are running hundreds of analyses per day. Batching and caching intermediate results helps, as does downgrading to Sonnet for simpler steps like data fetching and keeping Opus for the reasoning-heavy steps like memo generation.
Sources: MarkTechPost, Q2B Studio, Claude Skills GitHub repository, Anthropic Cookbook.