-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAML_Alert_Triage_clean.py
More file actions
328 lines (200 loc) · 5.49 KB
/
Copy pathAML_Alert_Triage_clean.py
File metadata and controls
328 lines (200 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
import pandas as pd
# In[ ]:
import pandas as pd
data = [
{
"Customer": "ABC Imports",
"RiskRating": "Low",
"Country": "UK",
"Counterparty": "Supplier A",
"Amount": 950,
"UsualAverage": 1200,
"NewCounterparty": "No",
"AdverseMedia": "No"
},
{
"Customer": "Global Metals Ltd",
"RiskRating": "Medium",
"Country": "UAE",
"Counterparty": "Al Noor Trading",
"Amount": 45000,
"UsualAverage": 9000,
"NewCounterparty": "Yes",
"AdverseMedia": "No"
},
{
"Customer": "Delta Commodities",
"RiskRating": "High",
"Country": "Russia",
"Counterparty": "Volga Trade",
"Amount": 38000,
"UsualAverage": 8000,
"NewCounterparty": "Yes",
"AdverseMedia": "Yes"
}
]
df = pd.DataFrame(data)
df
# In[ ]:
high_risk_countries = [
"Russia",
"Iran",
"North Korea",
"Turkey",
"UAE"
]
def calculate_risk(row):
score = 0
reasons = []
if row["Country"] in high_risk_countries:
score += 30
reasons.append("High Risk Country")
if row["Amount"] > row["UsualAverage"] * 3:
score += 25
reasons.append("Unusual Transaction Value")
if row["NewCounterparty"] == "Yes":
score += 20
reasons.append("New Counterparty")
if row["AdverseMedia"] == "Yes":
score += 25
reasons.append("Adverse Media")
if row["RiskRating"] == "High":
score += 15
reasons.append("High Customer Risk")
return score, reasons
# In[ ]:
df[["RiskScore","RiskReasons"]] = df.apply(
lambda row: pd.Series(calculate_risk(row)),
axis=1
)
df
# In[ ]:
def investigator_summary(row):
return f"""
Customer: {row['Customer']}
Risk Score: {row['RiskScore']}
Risk Indicators:
{', '.join(row['RiskReasons'])}
Investigator Recommendation:
Review transaction activity and perform Enhanced Due Diligence due to identified risk indicators.
"""
# In[ ]:
df["InvestigatorSummary"] = df.apply(
investigator_summary,
axis=1
)
df[["Customer","RiskScore","InvestigatorSummary"]]
# In[ ]:
for summary in df["InvestigatorSummary"]:
print(summary)
print("-" * 60)
# In[ ]:
df[["Customer", "RiskScore", "RiskReasons"]]
# In[ ]:
def risk_level(score):
if score >= 90:
return "High"
elif score >= 50:
return "Medium"
else:
return "Low"
df["RiskLevel"] = df["RiskScore"].apply(risk_level)
df[["Customer", "RiskScore", "RiskLevel", "RiskReasons"]]
# In[ ]:
df.sort_values("RiskScore", ascending=False)
# In[ ]:
import matplotlib.pyplot as plt
# Sort highest-risk customers first
risk_dashboard = df.sort_values("RiskScore", ascending=False)
# Create bar chart
risk_dashboard.plot(
x="Customer",
y="RiskScore",
kind="bar",
legend=False,
figsize=(8, 5)
)
plt.title("AML Alert Risk Score Dashboard")
plt.xlabel("Customer")
plt.ylabel("Risk Score")
plt.xticks(rotation=45, ha="right")
plt.tight_layout()
plt.show()
# In[ ]:
def risk_status(score):
if score >= 100:
return "🔴 Critical"
elif score >= 50:
return "🟠 Medium"
else:
return "🟢 Low"
df["AlertStatus"] = df["RiskScore"].apply(risk_status)
df[["Customer","RiskScore","AlertStatus"]]
# In[ ]:
risk_dashboard[["Customer", "RiskScore", "RiskLevel", "RiskReasons"]]
# In[ ]:
risk_dashboard = df.sort_values(
"RiskScore",
ascending=False
)
# In[ ]:
for index, row in risk_dashboard.iterrows():
print("=" * 60)
print(row["Customer"])
print("Risk Score:", row["RiskScore"])
print("Status:", row["AlertStatus"])
print("Indicators:")
for reason in row["RiskReasons"]:
print("-", reason)
print()
# In[ ]:
df.to_csv("sample_transactions.csv", index=False)
# In[ ]:
with open("output_sample.txt", "w") as file:
for index, row in risk_dashboard.iterrows():
file.write("=" * 60 + "\n")
file.write(f"Customer: {row['Customer']}\n")
file.write(f"Risk Score: {row['RiskScore']}\n")
file.write(f"Status: {row['AlertStatus']}\n")
file.write("Indicators:\n")
for reason in row["RiskReasons"]:
file.write(f"- {reason}\n")
file.write("\n")
# In[ ]:
readme_text = """# AML Alert Triage Prototype
This is a Python proof-of-concept demonstrating how transaction monitoring alerts can be risk-scored, prioritised and summarised for investigator review.
## Purpose
The prototype explores how Python and AI-assisted analytics can support Financial Crime Operations by:
- scoring alerts against AML risk indicators
- prioritising higher-risk cases
- generating investigator-style summaries
- visualising alert risk scores
## Risk Indicators Used
- High-risk jurisdiction
- Unusual transaction value
- New counterparty
- Adverse media
- Customer risk rating
## Outputs
The prototype produces:
- AML risk score
- Alert status
- Risk reasons
- Prioritised alert queue
- Investigator summary
- Risk dashboard chart
## Tools Used
- Python
- Pandas
- Matplotlib
- Jupyter Notebook
## Context
This project was created as part of my development in Python, Financial Crime analytics and AI-enabled Transaction Monitoring use cases.
It is not intended to replace enterprise TM platforms. It demonstrates how AML domain logic can be translated into a working analytics prototype.
"""
with open("README.md", "w") as file:
file.write(readme_text)
# In[ ]:
import os
print(os.getcwd())
# In[ ]: