Pre-Trade Compliance Checker
Every fund trade has to clear a stack of German regulations before it executes. I built the system that runs that check — AI classification, a rule engine, and a decision log at every step.
The Problem
In fund compliance, every decision needs a paper trail. If a trade gets audited six months later, the system has to say exactly what was decided and why — which model, which version, what confidence, who reviewed it.
The actual task: before a fund advisor's order reaches a broker, verify it doesn't breach KAGB and BaFin rules. The math is simple — sum positions, compare ratios. The hard part is the classification work feeding the math. Which securities qualify as InvStG-compliant? Which parent company owns each issuer? These questions mean interpreting legal definitions against market data that's frequently messy, incomplete, or just wrong.
The Approach
AI classification pipeline. Three GPT-4 Turbo prompts with KAGB definitions baked in handle the ambiguous calls. Confidence-routed: >95% auto-approved, 80–95% flagged for a human, <80% goes to manual classification entirely. A circuit breaker trips after 5 consecutive failures — I'd rather halt than cascade bad classifications into trade decisions.
Deterministic rules engine. Pure Python. Each compliance rule is one self-contained class. New rule = new subclass. No config files, no touching existing code.
The hardest piece was Konzern resolution — figuring out which entities share a parent company. Source data leaves the parent company field blank more often than not. The AI infers relationships from issuer names, LEI codes, and public filings, assigns a confidence score with cache expiry, and surfaces anything low-confidence for review instead of guessing silently.
Every classification gets logged: model version, prompt version, raw response, confidence score. Overrides require a written justification — enforced by a CHECK constraint at the database level, not a UI prompt you can click past.
The Outcome
Working demo against a representative fund portfolio. InvStG compliance calculates correctly across mixed security types. The Konzern concentration rule groups positions by resolved parent company and blocks trades that would breach the 10% issuer limit. Output follows the Prüfung format that compliance officers actually expect to see.
The Constraint That Shaped Everything
If BaFin examines a trade from six months ago, the system has to show exactly why that position was classified the way it was. Which model. Which prompt version. What confidence score. Who approved it. That one requirement is why the classification log is immutable, why overrides need justification, and why I picked a deterministic rules engine over something more flexible.