Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI4Finance Foundation FinRobot execute peer analysis

From Leeroopedia
Knowledge Sources
Domains Finance, Valuation, Pipeline_Step
Last Updated 2026-10-18 00:00 GMT

Overview

Concrete pipeline step for selecting peers, fetching their financials, FX-normalizing, computing multiples, and aggregating statistics deterministically, provided by the FinRobot shared helpers layer.

Description

The execute_peer_analysis function is a shared pipeline step executor used by both the equity_research and standalone comps pipelines. It selects peer tickers (deterministic candidate screen, sticky artifact selection, or caller-supplied via peers kwarg), then fetches + FX-normalizes + computes multiples for each peer in parallel, and aggregates peer statistics.

Peer selection precedence:

  1. Caller-supplied peers override (e.g. `finrobot comps --peers AAPL,MSFT`)
  2. Sticky selection (from a prior artifact)
  3. Deterministic candidate screen (cyclical-peer screening)

The target company is never its own comp — it is dropped if listed. Peer drops (e.g. a foreign comp lost to an FX rate-limit) are keyed by ticker so the artifact warning names them instead of silently vanishing.

Usage

  • Comps_Analysis workflow (Step 2): The primary step for statistical benchmark computation.
  • Equity_Research workflow (Step 3): Produces the PeerComps for the equity research report.
  • Import this when you need a complete peer analysis step in a pipeline. Pass peers=['T1','T2',...] to override auto-selection.

Code Reference

Source Location

  • Repository: FinRobot
  • File: finrobot_desktop/finrobot/engine/pipelines/_helpers.py

Signature

async def execute_peer_analysis(
    agent: Agent[Any, Any],
    deps: FinRobotDeps,
    prompt: str,
    structured_context: dict[str, object],
    ticker: str,
    **kwargs: object,
) -> StepOutput:
    """Select peer tickers, then fetch + compute multiples deterministically.

    Peers come from the deterministic candidate screen UNLESS the caller
    passes peers=[...] (e.g. finrobot comps --peers AAPL,MSFT), in which
    case auto-selection is skipped and the user's set is used verbatim.

    Shared by equity_research and the standalone comps pipeline so BOTH
    emit deterministic, traceable multiples instead of LLM free text.
    """

Import

from finrobot.engine.pipelines._helpers import execute_peer_analysis

I/O Contract

Inputs

Name Type Required Description
agent Agent Yes PydanticAI agent for narrative
deps FinRobotDeps Yes Settings, data_layer, artifact_store
prompt str Yes Prompt for the agent
structured_context dict Yes Mutable context dict (carries FinancialData from prior step)
ticker str Yes Target company symbol
peers list[str] No Caller-supplied peer override (via kwargs)

Outputs

Name Type Description
StepOutput StepOutput PeerComps: target, peers, peer_justification, median_ev_ebitda, median_pe, median_pb, warnings

Usage Examples

Standard Peer Analysis (Auto-Selection)

from finrobot.engine.pipelines._helpers import execute_peer_analysis

result = await execute_peer_analysis(
    agent=agent,
    deps=deps,
    prompt="Analyze peer comparable companies",
    structured_context=ctx,
    ticker="AAPL",
)
peer_comps = result.structured_data
print(f"Peers: {[p.ticker for p in peer_comps.peers]}")
print(f"Median EV/EBITDA: {peer_comps.median_ev_ebitda:.1f}x")

With Caller-Supplied Peers

result = await execute_peer_analysis(
    agent=agent,
    deps=deps,
    prompt="Analyze peers",
    structured_context=ctx,
    ticker="AAPL",
    peers=["MSFT", "GOOGL", "AMZN", "META"],  # Override auto-selection
)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment