FMP

FMP

Anomaly Detection For Professional Markets With FMP APIs

-

twitterlinkedinfacebook
blog post cover photo

Image credit: Financial Modeling Prep (FMP)

Anomaly detection in financial data is the process of spotting unusual patterns—such as revenue spikes, EPS drops, or margin shifts—that deviate significantly from historical norms or industry benchmarks. In professional markets, this means using statistical methods and automated systems to flag data anomalies, investigate the cause, and act before competitors.

Using Financial Modeling Prep (FMP) APIs, developers and analysts can automate anomaly detection by pulling structured financial data, applying techniques like Z-Score, percentile thresholds, and rolling average deviation, and generating alerts when anomalous data is found.

This systematic approach turns raw financial data into actionable insights that help identify emerging risks and opportunities.

What is Anomaly Detection in Financial Data?

Anomaly detection is the process of identifying data points that significantly deviate from historical patterns or expected norms. In finance, it means spotting unusual performance—such as revenue surges, EPS drops, or margin shifts—that exceed normal variance when compared with a company's own history or peer benchmarks.

For example, a quarter's EPS might leap far beyond its historical range after adjusting for industry cycles, clearly signaling a deviation that statistical or algorithmic methods can measure, reproduce, and confirm as significant in the market context.

Types of Anomalies

  • Point anomalies: Single data points that significantly differ from the rest of the dataset, such as one quarter with an unexpected revenue spike.
  • Contextual anomalies: Data points that are only unusual in a specific context, such as seasonal fluctuations outside normal seasonal ranges.
  • Collective anomalies: Patterns of data that, when considered together, deviate from expected trends, like a multi-quarter decline in EPS despite rising revenue.

Anomaly Detection Methodologies

Detecting anomalies requires selecting the right analytical approach for the dataset and objective. These methodologies work together to reveal different anomaly types:

  • Z-Score: Flags extreme point anomalies.
  • Percentile thresholds: Captures context-specific outliers.
  • Rolling average deviation: Highlights sustained shifts.

Z-Score Method

The Z-score measures how far a data point is from the mean in terms of standard deviations.

Z equals the difference between the current value and the mean of historical values, divided by the standard deviation of those historical values.

Formula: Z = (X − μ) / σ

  • X = current value (e.g., current revenue)
  • μ = mean of historical values (e.g., average revenue)
  • σ = standard deviation of historical values

A higher absolute Z-score means the value is farther from the mean. Typically, a Z-score > 2 or < -2 indicates an anomaly.

Python Code Example:

import numpy as np


historical_revenue = [100000, 120000, 130000, 110000, 115000]

mean_revenue = np.mean(historical_revenue)

std_dev_revenue = np.std(historical_revenue)

current_revenue = 140000

z_score = (current_revenue - mean_revenue) / std_dev_revenue

print("Z-Score:", z_score)

Percentile Thresholds

This method compares current performance to historical percentiles.

Formula Concept: A value is considered anomalous if it lies above the chosen upper percentile or below the chosen lower percentile.

For example, if current revenue growth is greater than the 95th percentile of historical growth, it's likely an anomaly.

Python Code Example:

import numpy as np


growth_rates = [0.05, 0.07, 0.03, 0.04, 0.06]

percentile_threshold = np.percentile(growth_rates, 95)

current_growth = 0.10

if current_growth > percentile_threshold:

print("Anomalous growth detected")

Rolling Average Deviation

The Rolling Average Deviation method measures how much a current value deviates from the moving average over a chosen time window. This helps capture sustained trends or shifts that might not register as point anomalies but still indicate important changes in performance.

Formula: Deviation = (Absolute Value of (Current Value − Rolling Average)) ÷ Rolling Average

By tracking deviations from a rolling average, you can detect gradual accelerations or declines in metrics like revenue or EPS. This method is especially useful for spotting trend changes masked by seasonality.

Python Code Example:

import numpy as np


historical_values = [100, 105, 102, 110, 108, 115, 120]

window = 3

rolling_avg = np.mean(historical_values[-window:])

current_value = 125

deviation = abs(current_value - rolling_avg) / rolling_avg

print("Rolling Average Deviation:", deviation)

Detect Growth Anomalies with FMP Data and APIs

Data anomaly detection in financial performance starts with high-quality, structured inputs and a consistent comparison process. Financial Modeling Prep's (FMP) APIs deliver machine-readable fundamentals—ideal for building an anomaly detection system that reliably flags unusual trends in revenue, earnings per share (EPS), and other metrics.

Step 1: Retrieve the Data

Use FMP endpoints to gather both historical and current financial figures:

Append your API key to each call. Example:

https://financialmodelingprep.com/api/v3/income-statement/AAPL?period=quarter&limit=20&apikey=YOUR_API_KEY

Adjust the ticker, period (quarter or annual), and limit based on the scope of your analysis.

Step 2: Prepare the Data

Clean and standardize the dataset to ensure accurate comparisons:

  • Align reporting periods so each value corresponds to the same fiscal quarter or year.
  • Adjust for stock splits or share count changes that affect per-share metrics.
  • Normalize currency values if comparing companies across markets.
  • Convert to consistent units (thousands, millions) to avoid scaling errors.

Step 3: Apply Detection Logic

Run statistical checks to uncover anomalous data:

  • Z-Score - Flags extreme point anomalies.
  • Percentile Thresholds - Identifies context-specific outliers.
  • Rolling Average Deviation - Reveals sustained trend shifts.

If a value crosses your threshold (e.g., Z-score > 2), mark it for review. This combination of methods improves your automatic anomaly detection by catching both sharp spikes and gradual, sustained changes.

Investigate the Anomaly

Once your anomaly detection system flags a value, the next step is anomaly analysis—determining if the anomaly is meaningful or just noise.

  1. Validate the data - Confirm it's not a reporting or input error.
  2. Check external factors - Company announcements, earnings calls, regulatory filings, or macroeconomic news.
  3. Compare against peers - See if it's company-specific or a sector-wide event.
    Segment the data - Use APIs like the Revenue Product Segmentation API to pinpoint the source (region, product, customer segment).

Pro Tip: Investigating anomalies in databases tied to product or geographic segments often reveals the underlying cause faster than reviewing aggregated figures.

Anomaly Detection Example

Scenario: Detecting unusual revenue growth in a fictional tech company.

  1. Call the API to retrieve five years of quarterly revenue:

https://financialmodelingprep.com/api/v3/income-statement/FAKE?apikey=YOUR_API_KEY

  1. Prepare the dataset by:

    • Filling missing values.
    • Aligning quarters in chronological order.
    • Adjusting for stock splits or currency shifts.

  2. Apply Z-Score to the latest quarter's revenue vs. historical values.
  3. Flag anomalies where Z > 2.
  4. Investigate by calling /revenue-product-segmentation and reviewing market news—discover a spike tied to a major product launch in Asia.
  5. Strategic Action: Recommend expanding marketing in Asia and set up monitoring scripts for sustained growth tracking.

This anomalous example demonstrates the full loop from raw data to strategic decision-making.

Creating an Anomaly Detection System

Transforming these steps into an anomaly-based detection system ensures anomalies are spotted and analyzed consistently.

System Workflow:

  • Data Ingestion Layer - Automate API calls (/income-statement, /ratios, /growth-metrics) with cron jobs, cloud functions, or workflow tools.
  • Data Preparation Layer - Standardize periods, normalize currencies, and clean anomalies in database records caused by reporting errors.
  • Detection Layer - Apply Z-Score, percentile thresholds, and rolling average deviation to detect point, contextual, and collective anomalies.
  • Analysis Layer - Perform anomaly analysis using segment data, competitive benchmarks, and market context.
  • Output & Alert Layer - Send email, Slack, or dashboard alerts with anomalous examples and likely causes.

Why It Matters: This approach takes you from raw inputs to anomaly detection for professional markets that drives real, timely business decisions.

Best Use Cases of FMP's Financial APIs for Anomaly Detection

FMP's APIs provide structured, machine‑readable fundamentals that support anomaly detection and quantitative analysis. Below are the key API Statements categories, along with examples of the types of anomalies to look for and why they matter:

  • Income Statement - Spot sudden revenue or EPS spikes/drops that deviate from seasonal or historical norms, which may signal product launches, market shifts, or accounting changes.
  • Balance Sheet Statement - Identify unusual jumps in debt or assets that could indicate acquisitions, asset write‑downs, or liquidity concerns.
  • Cash Flow Statement - Detect abrupt changes in operating or free cash flow, possibly tied to operational disruptions or one‑time events.
  • Latest Financial Statements - Compare the most recent filings to previous periods to flag sharp deviations in key metrics.
  • TTM (Trailing Twelve Months) Data - Monitor rolling performance to uncover sustained upward or downward trends masked in quarterly results.

Ratios API:

  • Key Metrics - Look for abnormal swings in metrics like ROE, ROA, or profit margins that could signal efficiency changes or operational risk.
  • Financial Ratios - Detect outliers in liquidity, leverage, or valuation ratios relative to peers or industry benchmarks.
  • Key Metrics TTM - Track smoothed metrics to identify gradual but significant shifts in profitability or asset use.

Analysis API:

  • Financial Scores - Spot major changes in composite health scores, which could indicate a sudden change in market perception or fundamentals.
  • Owner Earnings - Detect unusual increases or decreases suggesting altered capital allocation strategies.
  • Enterprise Values - Monitor sharp changes versus market cap for potential mispricing or market sentiment shifts.
  • Growth Metrics - Flag companies with growth rates far outside normal ranges, whether positive or negative.
  • Income Statement Growth / Balance Sheet Growth / Cash Flow Growth - Pinpoint anomalies in growth patterns over time to uncover emerging risks or opportunities.

By combining these datasets, you can tailor anomaly detection to the type of signal you're targeting, from single‑period outliers to multi‑period structural changes.

From Outliers to Opportunities

Anomaly detection becomes far more actionable when robust statistical methods are paired with comprehensive, high-quality data. Leveraging Z-Score, percentile thresholds, and other techniques alongside FMP's financial data APIs enables developers and analysts not only to identify irregularities, but also to contextualize and validate them. This combination provides a repeatable framework for uncovering potential risks, spotting emerging opportunities, and informing strategic decisions with greater confidence.

Frequently Asked Questions

What is anomaly detection in financial data?

It's the process of finding data points or patterns—like unexpected revenue spikes or profit margin drops—that deviate significantly from historical trends or industry norms.

What is an anomaly-based detection system?

It's a framework that continuously compares new data to historical baselines, statistical thresholds, or peer benchmarks to flag unusual patterns in real time.

When is anomaly detection most useful in finance?

It's especially valuable during earnings season, market volatility, or when tracking company and sector metrics for early signs of change.

How do you detect anomalies in financial data?

By applying statistical methods such as Z-score analysis, percentile thresholds, or rolling average deviation to compare current results with historical performance.

What is the main purpose of anomaly detection?

To quickly identify unexpected shifts that may signal risks, opportunities, or data errors—allowing for faster, evidence-based decisions.

How do I start using FMP APIs for anomaly detection?

Begin by pulling historical and current data from endpoints like /income-statement, /income-statement-growth, and /ratios. Standardize the data, apply detection methods, and validate anomalies with additional datasets or market news.

What advantages does anomaly detection offer to professional markets?

It uncovers hidden trends, spots risks early, validates data integrity, and identifies growth opportunities ahead of the broader market.

How much historical data should I use?

The ideal baseline is several years of historical data for more reliable detection, but even 8-12 quarters can provide solid results for many metrics.

Is setting up an anomaly detection system complicated?

With structured data from APIs like FMP and proven statistical techniques, creating a functional detection workflow is straightforward, though fine-tuning for accuracy takes ongoing adjustment.

Other Blogs

blog post title

Walk Me Through a DCF: A Simple Guide to Discounted Cash Flow Valuation

Are you curious about how professional investors decide whether a stock might be one of the best undervalued stocks to b...

blog post title

Technical Analysis 101: Understanding Support and Resistance

Technical analysis is a fundamental approach used by traders to forecast price movements based on historical market data...

blog post title

How an Economic Moat Provides a Competitive Advantage

Introduction In the competitive landscape of modern business, companies that consistently outperform their peers ofte...