Implementation:AI4Finance Foundation FinRobot calculate peer statistics
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Finance, Valuation, Deterministic_Compute |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Concrete tool for computing median and mean multiples across a peer set with NM-cap exclusion and sample-size warnings, provided by the FinRobot compute layer.
Description
The calculate_peer_statistics function aggregates multiples across a PeerComps object. It returns a deep copy with statistics set; the input is not mutated. It ignores None values and guards against empty lists before calling statistics.median/mean.
Key features:
- NM cap exclusion: Trailing EV/EBITDA and P/E medians apply NM (not meaningful) caps — real-but-distorting multiples above the cap are excluded from the median without dropping the peer from the competitive landscape display.
- Finiteness guard: NaN multiples (one corrupt peer) are excluded so they do not poison the median.
- Sample-size warnings: Appends a warning to result.warnings for each multiple where peers were excluded due to None or NM, surfacing the effective sample size.
Usage
- Comps_Analysis workflow (Step 2): Called after calculate_multiples has been applied to every peer to compute the peer-set medians/means.
- Equity_Research workflow (Step 3): Called as part of peer analysis to produce the benchmark medians.
- Import this when you need aggregated peer statistics from a PeerComps object.
Code Reference
Source Location
- Repository: FinRobot
- File: finrobot_desktop/finrobot/engine/compute/operators/multiples.py
Signature
def calculate_peer_statistics(comps: PeerComps) -> PeerComps:
"""Compute median and mean multiples across the peer set.
Returns a new copy with statistics set (input is not mutated).
Ignores None values. Guards against empty list before calling
statistics.median/mean.
Appends a sample-size warning to result.warnings for each multiple
where one or more peers were excluded due to None (data-quality drop).
"""
Import
from finrobot.engine.compute.operators.multiples import calculate_peer_statistics
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| comps | PeerComps | Yes | Peer set with target and peers (each having multiples computed via calculate_multiples) |
Outputs
| Name | Type | Description |
|---|---|---|
| result | PeerComps | Deep copy with median_ev_ebitda, mean_ev_ebitda, median_pe, mean_pe, median_ev_revenue, median_forward_pe, median_pb, sample sizes, warnings |
Usage Examples
Aggregate Peer Statistics
from finrobot.engine.compute.operators.multiples import calculate_multiples, calculate_peer_statistics
# Compute multiples for each peer first
comps.peers = [calculate_multiples(p) for p in comps.peers]
comps.target = calculate_multiples(comps.target)
# Then aggregate
comps = calculate_peer_statistics(comps)
print(f"Median EV/EBITDA: {comps.median_ev_ebitda:.1f}x")
print(f"Median P/E: {comps.median_pe:.1f}x")
print(f"Warnings: {comps.warnings}")
Related Pages
Implements Principle
Requires Environment
Uses Heuristics
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment