Sub topic 11
Detecting fan-in and rapid pass-through
This chapter assumes you can read short Python and SQL snippets. It also assumes you know what a funnel account is: an account that collects deposits from many sources and moves the money out elsewhere. Here you turn that description into two checks you can run on transfer data.
The pattern in two measurements
A funnel or mule account usually shows two features together:
- Fan-in: money arrives from many distinct senders.
- Pass-through: most of that money leaves again soon after it arrives.
Either feature alone is common. A shop receives money from many customers. A savings account may receive one salary and keep it. Both together on an account whose profile does not explain them is the signal.
Step 1: find fan-in with SQL
Start by counting distinct senders per destination account over a recent window. Counting rows is not enough. Ten transfers from one sender is a different situation from ten transfers from ten senders.
-- PostgreSQL syntax
SELECT dst_account,
COUNT(DISTINCT src_account) AS distinct_senders,
SUM(amount) AS total_inflow
FROM transfers
WHERE ts >= CURRENT_DATE - INTERVAL '7 days'
GROUP BY dst_account
HAVING COUNT(DISTINCT src_account) >= 5
ORDER BY total_inflow DESC;The HAVING clause filters after grouping, so it can use the distinct count. The result is a starting list for review, not a list of suspects.
Step 2: add the pass-through test in Python
Fan-in tells you about inflow. To test pass-through, compare outflow with inflow for the same account in the same window.
from collections import defaultdict
def flag_passthrough(transfers, min_sources=5, ratio=0.9):
"""transfers: iterable of (source, destination, amount) within one review window."""
inflow = defaultdict(float)
outflow = defaultdict(float)
sources = defaultdict(set)
for src, dst, amount in transfers:
inflow[dst] += amount
outflow[src] += amount
sources[dst].add(src)
return [
acct for acct in inflow
if len(sources[acct]) >= min_sources
and outflow[acct] >= ratio * inflow[acct]
]The function builds three totals per account. It then returns accounts with at least min_sources distinct senders whose outflow is at least 90% of inflow.
You can try it on a small set:
transfers = [
("a1", "m", 900), ("a2", "m", 950), ("a3", "m", 1000),
("a4", "m", 920), ("a5", "m", 980),
("m", "boss", 4600),
]
print(flag_passthrough(transfers)) # ['m']Account m received 4,750 from five senders and sent 4,600 onward, which is about 97%.
Common errors
- Ignoring time. The function above uses one window and no ordering. An account that receives money in January and sends it in June looks the same as one that forwards it within an hour. Real scenarios also measure the delay between inflow and outflow, since speed is a major red flag.
- Counting rows instead of senders. Use distinct senders, as the SQL does.
- Fixed thresholds applied to everyone. Five senders in a week is normal for a small business and unusual for a student account. Compare against the customer's expected activity from due diligence.
- Missing the splitting of outflow. Mules may send out in several smaller transfers to different accounts. The ratio test handles this, because it sums all outflow. A test for a single large outgoing transfer would miss it.
Tuning
Raise min_sources or lower the window to cut alert volume. Lower ratio to catch accounts that keep a small fee. Mules often keep a cut, so a ratio of 0.8 may fit your data better than 0.9. Test each change on past confirmed cases and on normal accounts, and record how many alerts each setting produces.
Exercise
An account receives 6,000 from eight distinct senders in one week and sends out 5,700 in three transfers to two accounts. With minsources=5 and ratio=0.9, does flagpassthrough flag it? What would you check before escalating?
Show answer
Yes. It has eight distinct senders (at least 5), and outflow of 5,700 is 95% of inflow (at least 90%). Before escalating, compare the activity with the customer's expected activity and occupation or business type, check how quickly the money left after arriving, and look at who the two receiving accounts are.