Implementation:AI4Finance Foundation FinRobot calculate earnings surprises
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Finance, Earnings_Analysis, Deterministic_Compute |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Concrete tool for classifying quarterly earnings as beat/miss/inline and aggregating surprise statistics, provided by the FinRobot compute layer.
Description
The calculate_earnings_surprises function computes per-quarter EPS and revenue surprise percentages, classifies each as beat/miss/inline (±2% threshold per Livnat & Mendenhall 2006), and aggregates into EarningsResult statistics: beat rate, average surprise, and consecutive beats.
Key design decisions:
- None ≠ 0: A missing actual/estimate stays None so the surprise is "n/a" rather than fabricated as a $0 value. Quarters with undefined surprises are excluded from rates and averages.
- Consecutive beats: Counts the current streak of beats (most recent first).
- All calculations are deterministic; no LLM involvement.
Usage
- Earnings_Analysis workflow (Step 1): Called after earnings data is fetched to compute the surprise statistics for the report.
- Import this when you need deterministic beat/miss classification and aggregate earnings statistics.
Code Reference
Source Location
- Repository: FinRobot
- File: finrobot_desktop/finrobot/engine/compute/operators/earnings.py
Signature
def calculate_earnings_surprises(
ticker: str,
earnings_history: list[dict[str, float | str]],
) -> EarningsResult:
"""Compute beat/miss/inline classification for each quarter.
Args:
ticker: Company ticker symbol.
earnings_history: List of dicts (most recent first) with keys:
date, eps_actual, eps_estimated, revenue_actual, revenue_estimated.
Returns:
EarningsResult with per-quarter surprises and aggregate statistics.
"""
Import
from finrobot.engine.compute.operators.earnings import calculate_earnings_surprises
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| ticker | str | Yes | Company ticker symbol |
| earnings_history | list[dict] | Yes | Quarterly records (most recent first): date, eps_actual, eps_estimated, revenue_actual, revenue_estimated |
Outputs
| Name | Type | Description |
|---|---|---|
| EarningsResult | EarningsResult | ticker, surprises (per-quarter), beat_rate, avg_eps_surprise_pct, avg_revenue_surprise_pct, consecutive_beats |
Usage Examples
Compute Earnings Surprises
from finrobot.engine.compute.operators.earnings import calculate_earnings_surprises
# earnings_history from the EARNINGS data type via data_layer.fetch
result = calculate_earnings_surprises("AAPL", earnings_history)
print(f"Beat rate: {result.beat_rate:.1%}")
print(f"Avg EPS surprise: {result.avg_eps_surprise_pct:.1f}%")
print(f"Consecutive beats: {result.consecutive_beats}")
for s in result.surprises:
print(f"{s.date}: EPS {s.eps_direction} ({s.eps_surprise_pct:+.1f}%)")
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment