Use Percentiles to Spot Anomalies
Averages hide the interesting days. Learn to use ClickHouse quantiles to define 'normal', flag unusual transfers, fees and activity, and build anomaly checks that do not cry wolf.
On-chain data is lumpy. Most transfers are small, a few are enormous; most blocks are routine, a few are packed; most days are quiet, a few are wild. Averages flatten all of that. A single whale transfer can drag the average transfer size up by an order of magnitude, while telling you nothing about the typical one. Percentiles describe lumpy data far better — and they are the simplest reliable tool for spotting anomalies.
This tutorial shows how to compute percentiles in ClickHouse, use them to define "normal", and flag the days and transactions that fall outside it. You need the Wevr query editor.
Percentiles in one paragraph
The 50th percentile — the median — is the value below which half the observations fall. The 90th percentile is the value below which 90% fall; the 99th, 99%. For transfer sizes, the median describes a typical transfer, while the 99th percentile describes the size that only one transfer in a hundred exceeds. Anything above that is, by definition, unusual.
Step 1: describe a distribution
ClickHouse computes percentiles with quantile (approximate and fast) or quantileExact (exact and slower). Several at once use quantiles:
SELECT quantiles(0.5, 0.9, 0.99)(value / 1e18) AS eth_transfer_size
FROM transactions
WHERE block_timestamp >= now() - INTERVAL 7 DAY
AND value > 0;
The result is an array: the median, 90th and 99th percentile ETH transfer sizes over the past week. Compare them with the average to see how much the average misleads.
Step 2: flag unusual transfers
Use the 99.9th percentile as a threshold and list everything above it:
WITH (
SELECT quantile(0.999)(value)
FROM transactions
WHERE block_timestamp >= now() - INTERVAL 30 DAY AND value > 0
) AS p999
SELECT block_timestamp, from_address, to_address, value / 1e18 AS eth
FROM transactions
WHERE block_timestamp >= now() - INTERVAL 1 DAY
AND value > p999
ORDER BY eth DESC;
The threshold comes from the past 30 days; the check runs on the past day. Anything listed is unusual relative to a month of history, not just relative to today. Paste interesting senders into Wevr Footprint to see who they are.
Step 3: flag unusual days
The same idea works for daily metrics. Compute a daily series, then compare each day with the distribution of the preceding days:
WITH daily AS (
SELECT toDate(block_timestamp) AS day, uniqExact(from_address) AS active
FROM transactions
WHERE block_timestamp >= now() - INTERVAL 120 DAY
GROUP BY day
)
SELECT day, active,
active > (SELECT quantile(0.95)(active) FROM daily) AS unusually_high,
active < (SELECT quantile(0.05)(active) FROM daily) AS unusually_low
FROM daily
ORDER BY day;
This flags days with active addresses in the top or bottom 5% of the period. For a stricter version, compute the percentiles over a rolling window of the preceding days only, so each day is compared with its own past rather than the whole sample.
Step 4: choose sensible thresholds
Percentile thresholds trade sensitivity against noise:
- 95th percentile — flags about one day in twenty. Good for dashboards you look at weekly.
- 99th percentile — about one day in a hundred. Good for alerts.
- 99.9th percentile — rare events only. Good for individual transfers, which are numerous.
The right choice depends on how often you want to be interrupted. Alerts that fire daily get ignored.
Step 5: account for the weekly rhythm
Activity is usually lower at weekends. A Sunday compared with all days may look unusually low when it is perfectly normal for a Sunday. Two fixes:
- compare each day with the same weekday in previous weeks, or
- use seven-day rolling totals instead of single days.
Turn it into an alert
Once you have a threshold you trust — say, the 99.9th percentile transfer size for an asset — use it on the Alerts page so unusual transfers come to you. Recompute the threshold every month or so; distributions shift as markets change.
Troubleshooting
quantile results change slightly between runs. quantile is approximate. Use quantileExact when you need repeatable exact values on smaller datasets.
Everything is flagged. Your window may include a regime change — for example, an airdrop period. Shorten the window or exclude the unusual period when computing the baseline.
Nothing is flagged. Check units: thresholds computed in wei and comparisons made in ETH will never match.
A worked example
Suppose a token's median transfer over the past month is a few hundred dollars and its 99.9th percentile is around $400,000. Today, your check lists six transfers above that level. Four go from one address to a known exchange deposit address within twenty minutes; two go from a long-dormant wallet to a fresh one.
The percentile check has done its job: it has turned thousands of transfers into six worth reading. The exchange deposits might be a large holder preparing to sell; the dormant wallet waking up might be an old holder reorganising custody. Neither conclusion comes from the query — both come from the two minutes of follow-up the query made possible. That division of labour, with the query narrowing and the analyst reading, is how anomaly detection works in practice.
What you can do now
You can describe any on-chain distribution with percentiles, flag unusual transfers and days relative to recent history, choose thresholds that match how often you want to look, and adjust for the weekly rhythm. That is the core of anomaly detection — and none of it requires anything more advanced than quantile.