Inspiration

On November 14, 2026, the global SWIFT network enforces a strict mandate rejecting cross-border payment instructions containing unstructured postal addresses. At the same time, quants and institutional traders face significant operational friction trying to capture fleeting price divergences between US-listed ADRs and native foreign ordinary shares. Capturing these spreads requires immediate execution, cross-border FX hedging, tax leakage evaluation, and complex back-office bank communication before the price window closes.

We built this project to automate this multi-step institutional chore, replacing manual back-office translation with an autonomous, background AI agent.

What it does

Our agent continuously monitors cross-border price spreads and executes a complete, hands-off quantitative arbitrage workflow:

  • Signal & Anomaly Detection: Ingests market ticks via Cloud Pub/Sub and uses BigQuery ML's TimesFM foundation model (AI.DETECT_ANOMALIES) to detect true statistical spread divergences (>40 bps).
  • Active Security Boundary: Passes incoming events through Google Cloud Model Armor to intercept prompt injection attacks or PII leakage before the agent executes.
  • Institutional TCA Evaluation: Calculates True Net Spread by accounting for ADR ratio multipliers, slippage, borrow fees, creation/cancellation charges ($0.05/share), and cablewire costs.
  • Withholding Tax (WHT) Guardrails: Automatically halts execution if an ex-dividend date is imminent ($\le 21$ days with $\ge 5\%$ tax rate) to avoid severe tax leakage.
  • Covered Interest Parity (CIP) FX Pricing: Prices forward currency hedges using domestic and foreign interest differentials: $$F = S \times \frac{1 + r_d}{1 + r_f}$$
  • 2026 SWIFT CBPR+ XML Generation: Dynamically builds syntactically valid sese.023 Securities Settlement XML payloads, parsing unstructured broker notes into compliant <TwnNm> and <Ctry> elements within <PstlAdr>.
  • Closed-Loop Self-Healing: Pre-validates XML syntax using Gemma 2 9B IT; if Gemma finds structural errors, Gemini 3.5 Flash autonomously restructures the XML until verified.

How we built it

  • Reasoning Engine: Gemini 3.5 Flash (gemini-3.5-flash) running on Google ADK (google-adk), using explicit context caching (30-minute TTL) to store ISO 20022 schema rules in memory.
  • Security & Validation: Google Cloud Model Armor as an active proxy boundary, and Gemma 2 9B IT (google/gemma-2-9b-it) hosted via Hugging Face InferenceClient as an inline LLM judge.
  • Serverless Infrastructure: Google Cloud Run (quant-agent-executor) hosting a FastAPI webhook controller, configured to scale to zero (min_instance_count = 0) to preserve cloud credits.
  • Event Ingestion & ML: Cloud Pub/Sub streaming into BigQuery dataset market_spreads_prod with TimesFM stored procedure routines.
  • Observability & Deployment: OpenTelemetry OTLP exporting cascading reasoning spans to Google Cloud Trace and Cloud Logging, completely provisioned via Terraform, Docker, and a make bootstrap command pattern.

Challenges we ran into

  • Protobuf Schema Handling in Model Armor: Resolving protobuf response attributes for Google Model Armor filters (FilterMatchState vs contains_injection).
  • Pub/Sub Retry Storms: Preventing Pub/Sub from retrying failed injection attacks continuously by returning an HTTP 200 OK acknowledgment with a security_guardrail_triggered payload.
  • Terraform Circular Dependencies: Solving the "chicken-and-egg" deployment loop where Cloud Run required a container image from Artifact Registry before the registry existed, solved via a two-phase IaC bootstrapping Makefile (make bootstrap).

Accomplishments that we're proud of

  • Full 2026 SWIFT Mandate Automation: Generating fully structured XML settlement instructions from raw broker notes without human hand-holding.
  • Dual-Model Self-Healing Loop: Successfully pairing Gemini 3.5 Flash with Gemma 2 9B IT to form a self-correcting validation chain.
  • Zero-Trust Security Integration: Defending against live prompt injection attacks at the boundary using Google Model Armor.
  • One-Click Reproducibility: Packaging the entire GCP environment, build pipelines, and serverless infrastructure into a single make bootstrap command.

What we learned

  • How to configure explicit context caching in Google ADK to keep latency low and token costs near zero.
  • How to model financial friction by combining Covered Interest Parity ($F = S \times \frac{1 + r_d}{1 + r_f}$) with Withholding Tax risk checking.
  • How to configure OpenTelemetry OTLP collectors to trace reasoning chains across serverless execution environments.

What's next for ADR Arbitrage Agent and SWIFT ISO 20022 Converter

  • Production Asset Scaling: Expanding the BigQuery TimesFM anomaly procedure across thousands of global asset pairs simultaneously by setting time_series_id_col = 'adr_ticker'.
  • Direct Custodian Gateway Integration: Connecting the generated sese.023 XML output directly to live institutional SWIFT Alliance Access gateways.

Built With

Share this project:

Updates

Submission history