Catch More Suspicious Activity with Fewer False Alerts
Every transaction-monitoring team lives with the same tension. Regulators expect you to detect specific laundering typologies. Your analysts, however, can only review a limited number of alerts per day. Set thresholds too low and the alert queue floods with false positives. Set them too high and genuinely suspicious customers slip through.
In this article we turn that tension into a constrained optimization problem and solve it exactly in Python. We build a synthetic portfolio of 20,000 accounts, define three monitoring rules, search the full threshold space, and visualize the trade-offs with a single multi-panel figure that includes 3D surfaces.
1. Problem Setting
We observe $N = 20{,}000$ accounts over a one-week window. Each account $i$ has three behavioral features:
- $x_{i1}$: the largest single transaction amount (USD)
- $x_{i2}$: the peak number of transactions within any 24-hour period
- $x_{i3}$: the number of transactions in the “just below reporting threshold” band, $[8{,}000,\ 10{,}000)$ USD
Three rules monitor these features, each with its own threshold:
$$
\theta = (t_1, t_2, t_3), \qquad r_{ik}(\theta) = \mathbb{1}\left[x_{ik} \ge t_k\right], \quad k = 1,2,3
$$
An account raises an alert if any rule fires:
$$
a_i(\theta) = 1 - \prod_{k=1}^{3}\bigl(1 - r_{ik}(\theta)\bigr)
$$
The portfolio contains 2% truly suspicious accounts belonging to three typologies: large cash movement, rapid movement of funds, and structuring (also called smurfing). Each typology $s$ has a severity weight $w_s$ that reflects regulatory priority. Let $\mathcal{S}$ be the set of suspicious accounts and $w_i$ the weight of account $i \in \mathcal{S}$. The weighted detection rate is:
$$
R_w(\theta) = \frac{\sum_{i \in \mathcal{S}} w_i , a_i(\theta)}{\sum_{i \in \mathcal{S}} w_i}
$$
The alert rate, which drives analyst workload, is:
$$
A(\theta) = \frac{1}{N}\sum_{i=1}^{N} a_i(\theta)
$$
The rule-design problem is then:

Here $R_{\text{struct}}$ is the detection rate restricted to structuring accounts. We use $\alpha_{\max} = 4%$, $\rho_{\text{reg}} = 0.85$, and $T_{\text{reg}} = 20{,}000$ USD.
The decision space is small and discrete: 27 values of $t_1$, 12 values of $t_2$, and 8 values of $t_3$, which gives $2{,}592$ candidate rule sets. Because the space is so small, we can enumerate it completely and obtain the global optimum on the grid rather than a heuristic approximation.
2. Complete Source Code
1 | import time |
3. Code Walkthrough
Step 1: Synthetic portfolio. Legitimate accounts split into retail (92%) and business (8%) customers. Transaction amounts follow log-normal distributions, which reproduce the heavy right tail seen in real payment data, while the two count features follow Poisson distributions. Business accounts have higher means in all three features, which is exactly what makes naive rules noisy: a legitimate company can look more “suspicious” than a retail customer who is genuinely laundering money.
The three typologies each have a distinctive footprint:
- Large cash accounts have a very high maximum amount (log-normal centered near 18,000 USD).
- Rapid movement accounts have a high 24-hour transaction count (Poisson mean 11).
- Structuring accounts keep every amount just below the 10,000 USD reporting line (clipped at 9,990) and make many such deposits (Poisson mean 4.5 in the near-threshold band).
The vector w holds severity weights (1.0, 1.2, 1.5), and ws is a normalized indicator used to measure structuring recall separately, which the regulatory constraint requires.
Step 2: Constraints and grid. The search grid contains 27 amount thresholds, 12 velocity thresholds, and 8 structuring-count thresholds. Note that the amount grid extends to 30,000 USD, beyond the policy cap $T_{\text{reg}} = 20{,}000$. Those candidates are deliberately kept in the grid so the figures show where the infeasible region lies.
Step 3: Vectorized exhaustive search. This is the performance-critical block. A naive implementation would use three nested Python loops and recompute a boolean OR over 20,000 accounts at every combination. Instead, for each $t_1$ the code builds the three rule masks and combines them by broadcasting:

All $n_2 \times n_3 = 96$ combinations of the other two thresholds are evaluated in a single array operation. The alert rate is a mean along the account axis. The weighted recall and structuring recall are matrix-vector products between the alert tensor (cast to float) and the weight vectors. The outer loop has only 27 iterations, and each temporary tensor holds about 1.9 million booleans, so memory stays small.
Step 4: Selecting the optimum. The boolean tensor feas encodes all three constraints at once. The score is the weighted recall minus a tiny penalty on the alert rate, $R_w - 10^{-4}A$, which breaks ties in favor of the quieter rule set. Infeasible candidates receive $-\infty$. A penalty-based fallback exists purely as a safeguard in case a different random seed or constraint setting ever produces an empty feasible set.
Step 5: Evaluation and report. The helper evaluate recomputes every metric directly from the raw features for any threshold triple, so the baseline (a typical un-tuned configuration: 10,000 USD amount rule, 5 transactions per day, 2 near-threshold deposits) and the optimized configuration are compared on equal footing.
Step 6: The combined figure. One figure with six panels is produced. Panels (a) and (b) are 3D surfaces, and the red marker in each is the selected optimum.
4. Execution Results
================================================================== AML MONITORING RULE OPTIMIZATION ================================================================== Accounts: 20,000 Suspicious: 400 (2.0%) Candidate rule sets evaluated: 2,592 Feasible: 50 Search time: 0.151 s ------------------------------------------------------------------ Baseline : t1=10,000, t2=5, t3=2 Optimized : t1=17,000, t2=8, t3=3 ------------------------------------------------------------------ Metric Baseline Optimized Alerts 2,842 781 Alert rate 14.21% 3.91% False positives 2,464 478 Precision 13.30% 38.80% Weighted recall 95.13% 78.07% Recall: Large cash 87.86% 56.43% Recall: Rapid movement 99.09% 81.82% Recall: Structuring 97.33% 89.33% ------------------------------------------------------------------ False-positive reduction: 80.6% ==================================================================

5. Reading the Results
Panel (a): the detection surface. Lowering either threshold can only add alerts, never remove them, so $R_w(\theta)$ is non-increasing in both $t_1$ and $t_2$. The surface therefore descends toward the corner where both thresholds are high. Its steepness shows which rule contributes more marginal detection: a steep slope along one axis means the rule is responsible for catching many suspicious accounts that no other rule would catch. Flat plateaus mean another rule already covers those accounts, so tightening that threshold costs little recall.
Panel (b): the workload surface. The alert rate $A(\theta)$ is likewise monotone, but its shape differs from panel (a). Legitimate business accounts populate the mid-range of both the amount and velocity distributions, so the alert surface rises sharply once thresholds enter that region. The translucent cyan plane marks the analyst capacity $\alpha_{\max}$. Only the part of the surface lying below the plane is operationally acceptable. The red optimum sits on or just beneath the plane, which is exactly what we expect from a capacity-constrained maximization: the optimizer spends the whole alert budget, but no more.
Panel (c): the trade-off curve. Each dot is one of the 2,592 candidate rule sets. The yellow Pareto frontier shows the best weighted recall achievable at each alert rate. It rises quickly at first and then flattens, which is the classic diminishing-returns shape. Beyond a certain point, each additional percentage point of alert volume buys very little extra detection. The baseline (orange square) typically lies far to the right of the frontier’s knee: it generates many more alerts than necessary for a comparable level of detection. The optimized point (red star) lies on the feasible side of the capacity line. It does not necessarily coincide with the unconstrained frontier, because the structuring-coverage and policy-cap constraints can force it below the frontier’s best value at that alert rate.
Panel (d): the feasible region. At the optimal $t_3$, this map shows $R_w$ only where all constraints hold. White-space gaps (missing cells) show where one of the constraints is violated: low thresholds break the alert budget, while a high $t_1$ breaks the policy cap. The feasible region is a band rather than a single point, which gives the compliance team room to choose slightly different thresholds with nearly the same performance. That flexibility is valuable in practice, since thresholds are often rounded to policy-friendly values.
Panel (e): the headline comparison. Three numbers summarize the improvement: alert rate, weighted recall, and precision. The expected pattern is a sharp drop in alert rate and a corresponding rise in precision, accompanied by recall that is maintained or improved. The same analyst hours are spent on a much richer pool of alerts.
Panel (f): the typology view. Aggregate recall can hide a weakness in one typology. This panel exposes it. The red dashed line is the regulatory floor for structuring. The optimized rule set must sit above it, while the baseline may or may not. Watching all three typologies at once confirms the optimizer did not “buy” overall recall by neglecting a high-severity pattern.
6. Why This Formulation Works
Three design choices make this approach practical for a real compliance function:
- Constraints are first-class. Regulatory coverage and policy caps are encoded as hard constraints instead of being folded into a vague score. The resulting rule set is defensible in an audit because every threshold choice can be traced to an explicit requirement.
- Severity weights express priorities. Because $w_s$ weights the objective, an increase in structuring detection counts more than an equal increase in large-cash detection. Changing the weights changes the optimum in a transparent, explainable way.
- Exhaustive search gives a guarantee. With a small discrete rule space, enumeration returns the true optimum on the grid. There is no risk of getting stuck in a local optimum, and the vectorized implementation makes the search effectively instantaneous.
7. Extensions
The same skeleton scales to richer settings. Rules can be extended to many more features (country risk, counterparty concentration, dormant-account reactivation). When the grid becomes too large to enumerate, the exhaustive search can be replaced by differential evolution or a mixed-integer program, while keeping the identical objective and constraints. In production, the synthetic portfolio would be replaced by labeled historical cases, and the thresholds would be re-optimized on a rolling basis with out-of-time validation to guard against overfitting. Finally, the alert-budget constraint can be refined from a single global limit to separate capacity limits per analyst team or per customer segment.








