FMP
Aug 20, 2025 10:55 PM - amy Lyons
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.
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.
Detecting anomalies requires selecting the right analytical approach for the dataset and objective. These methodologies work together to reveal different anomaly types:
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 − μ) / σ
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) |
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") |
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) |
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.
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.
Clean and standardize the dataset to ensure accurate comparisons:
Run statistical checks to uncover anomalous data:
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.
Once your anomaly detection system flags a value, the next step is anomaly analysis—determining if the anomaly is meaningful or just noise.
Pro Tip: Investigating anomalies in databases tied to product or geographic segments often reveals the underlying cause faster than reviewing aggregated figures.
Scenario: Detecting unusual revenue growth in a fictional tech company.
https://financialmodelingprep.com/api/v3/income-statement/FAKE?apikey=YOUR_API_KEY
This anomalous example demonstrates the full loop from raw data to strategic decision-making.
Transforming these steps into an anomaly-based detection system ensures anomalies are spotted and analyzed consistently.
System Workflow:
Why It Matters: This approach takes you from raw inputs to anomaly detection for professional markets that drives real, timely business decisions.
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:
Ratios API:
Analysis API:
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.
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.
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.
It's a framework that continuously compares new data to historical baselines, statistical thresholds, or peer benchmarks to flag unusual patterns in real time.
It's especially valuable during earnings season, market volatility, or when tracking company and sector metrics for early signs of change.
By applying statistical methods such as Z-score analysis, percentile thresholds, or rolling average deviation to compare current results with historical performance.
To quickly identify unexpected shifts that may signal risks, opportunities, or data errors—allowing for faster, evidence-based decisions.
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.
It uncovers hidden trends, spots risks early, validates data integrity, and identifies growth opportunities ahead of the broader market.
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.
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.
Are you curious about how professional investors decide whether a stock might be one of the best undervalued stocks to b...
Technical analysis is a fundamental approach used by traders to forecast price movements based on historical market data...
Introduction In the competitive landscape of modern business, companies that consistently outperform their peers ofte...