Sub topic 10
Detecting structuring with aggregation windows
This chapter assumes you know what structuring is, why cash reporting thresholds exist, and how to read short Python and SQL snippets. It also assumes you know that a transaction monitoring rule turns account data into alerts. Here you will build the detection logic: group cash deposits over time, compare them with the threshold, and decide which alerts to keep.
Why single-transaction rules miss structuring
A rule such as "alert on any cash deposit of 10,000 or more" is what the reporting regime already requires. The bank files a currency transaction report automatically, so the rule adds nothing for detection.
Structuring deliberately keeps each deposit below the threshold. Each deposit looks harmless on its own. The pattern only shows when you aggregate, which means summing and counting transactions over a group and a time span.
Two choices define an aggregation rule:
- The grouping key. This is what you add up: usually the account, better the customer, and sometimes the customer plus linked parties.
- The window. This is the time span you add up over: for example three days, a week, or thirty days.
The shape of a structuring rule
A typical scenario has three conditions on cash deposits within one window:
- At least N deposits fall in a "near-threshold band", for example 8,000 up to but not including 10,000.
- The total of the cash deposits in the window exceeds the threshold.
- The window is short enough that the deposits look like one act split into pieces.
A rule in Python
The reference rule slides a window forward from each deposit:
from collections import defaultdict
from datetime import date, timedelta
THRESHOLD = 10_000
FLOOR = 8_000
def flag_structuring(deposits, window_days=3, min_count=3):
"""deposits: iterable of (account, date, amount) cash deposits."""
by_account = defaultdict(list)
for account, day, amount in deposits:
by_account[account].append((day, amount))
alerts = []
for account, items in by_account.items():
items.sort()
for i, (start, _) in enumerate(items):
end = start + timedelta(days=window_days)
window = [amt for day, amt in items[i:] if day < end]
near = [amt for amt in window if FLOOR <= amt < THRESHOLD]
if len(near) >= min_count and sum(window) > THRESHOLD:
alerts.append((account, start, sum(window)))
break
return alerts
deposits = [
("A-1", date(2026, 11, 2), 9_500),
("A-1", date(2026, 11, 3), 9_000),
("A-1", date(2026, 11, 4), 9_800),
("B-2", date(2026, 11, 2), 9_500),
("B-2", date(2026, 11, 20), 9_200),
("B-2", date(2026, 11, 25), 9_700),
]
print(flag_structuring(deposits))Running this prints [('A-1', datetime.date(2026, 11, 2), 28300)]. Account A-1 made three near-band deposits on three consecutive days. Account B-2 made similar deposits, but they are spread over weeks, so no window holds three of them.
How it works:
- Sorting puts each account's deposits in date order. That lets each deposit act as the start of a window.
- The window covers
[start, start + window_days). The end is exclusive, so a 3-day window starting on the 2nd covers the 2nd, 3rd and 4th. breakstops after the first alert for an account. This avoids a flood of overlapping alerts for the same behaviour. If you need every window, remove it and merge overlapping alerts afterwards.
The same rule in SQL
Compute window aggregates in the database when the data is already there:
-- PostgreSQL syntax
WITH windowed AS (
SELECT account_id,
deposit_date,
COUNT(*) FILTER (WHERE amount >= 8000 AND amount < 10000) OVER w AS near_count,
SUM(amount) OVER w AS window_total
FROM cash_deposits
WINDOW w AS (
PARTITION BY account_id
ORDER BY deposit_date
RANGE BETWEEN CURRENT ROW AND INTERVAL '2 days' FOLLOWING
)
)
SELECT account_id,
deposit_date AS window_start,
near_count,
window_total
FROM windowed
WHERE near_count >= 3
AND window_total > 10000
ORDER BY window_total DESC;This assumes a table cash_deposits(account_id, deposit_date date, amount numeric). The RANGE ... INTERVAL '2 days' FOLLOWING frame includes the start date and the two days after it, which matches the Python 3-day window for date values. The query returns one row per qualifying start date, so one account can appear several times. Add DISTINCT ON (account_id) or a GROUP BY if you want one row per account.
Choosing the parameters
Each parameter trades missed cases against noise.
| Parameter | Lower value | Higher value |
|---|---|---|
| `FLOOR` (band bottom) | Catches looser patterns, more false positives | Misses people who deposit well below the threshold |
| `min_count` | More alerts, including ordinary repeat deposits | Fewer alerts, misses short bursts |
| `window_days` | Misses patterns spread out over time | Catches slow structuring, but ordinary activity accumulates and triggers alerts |
Set these values with below-the-line testing. Run the rule with looser settings on historical data and sample the alerts it would not normally raise. If analysts would have wanted them, tighten less. If they are clearly innocent, the current settings are reasonable.
Edge cases that change results
- Customer, not account. Someone who spreads deposits across a current account, a savings account and a business account will pass an account-level rule. Group by customer ID, and where you have the data, by linked parties.
- Branches and channels. Deposits at different branches or ATMs belong in the same window. Make sure the input table includes all cash channels.
- Cash only. Cheques and transfers are not part of this threshold logic. Filter on a reliable cash indicator, not a free-text description.
- Timestamps and business days. Deposits late on Friday and early on Monday are close in practice but three calendar days apart. Decide whether your window counts calendar days or business days, and use the bank's time zone to assign each deposit to a date.
- Currency. Convert to the reporting currency before you compare with the threshold, and say which exchange rate you use.
- Tumbling versus sliding windows. A tumbling window uses fixed buckets such as calendar weeks. A sliding window starts at each deposit. Tumbling windows are simpler but miss a pattern that straddles a bucket boundary, so the sliding window above is safer.
- Threshold by jurisdiction. The 10,000 figure is an example. Use the amount that applies in the jurisdiction you work in, and keep it as a configuration value, not a number scattered through code.
Reducing false positives with customer context
Many alerts have an innocent explanation. A cash-heavy business such as a market stall, a laundrette or a restaurant deposits near-band amounts routinely. Customer due diligence (CDD) records the expected activity for each customer, so use that as the baseline:
- Compare with expected cash volume. Three deposits of 9,000 from a customer who declared 30,000 of monthly cash turnover is expected. The same deposits from a student with no declared cash income are not.
- Compare with history. Check whether the behaviour is new. A customer who has deposited near-band amounts every week for three years is different from one who began last month.
- Look at what happens next. Money that is deposited and then sent abroad or withdrawn immediately points to layering. Money that stays in the account looks more like savings.
- Check the deposit pattern. Amounts that are identical or only slightly different, paid in at several branches in one day, are more suspicious than amounts that vary with business takings.
Add these as enrichment fields on the alert, such as expected monthly cash, deposit history and the next outgoing payment, so that the analyst sees them without searching elsewhere.
What the analyst records
An alert from this rule should leave the analyst able to document:
- The window, deposit dates, amounts, branches and channels.
- The customer's expected activity and how the observed deposits compare.
- Any explanation the customer gave, and whether it fits the pattern.
- What happened to the funds afterwards.
- The decision (close or escalate) and the reason.
If the analyst escalates, these notes form the basis of the narrative in a suspicious activity report, which a later chapter covers.
Exercise
A customer with a declared monthly cash turnover of 5,000 deposits 9,400 on Monday, 9,100 on Tuesday and 9,600 on Wednesday, then sends 27,000 abroad on Thursday. Your rule uses a 3-day window, a band of 8,000 to under 10,000, min_count of 3 and a threshold of 10,000. Does it alert? Name two pieces of context you would add for the analyst, and say why a 2-day window would change the result.
Show answer
Yes. The three deposits fall within the 3-day window (Monday to Wednesday), all three are in the near band, and their total of 28,100 exceeds 10,000. Useful context: the declared monthly cash turnover of 5,000, which the deposits exceed more than five times, and the outgoing 27,000 transfer abroad on Thursday, which suggests rapid movement of the funds. A 2-day window would cover only two deposits at a time, so the near-band count would be at most 2, below min_count of 3, and the rule would not alert. This shows that a short window can miss the pattern.