Mandatory Hackathon Disclaimer:
I created this piece of content for the purpose of entering the All Things Agentic Hackathon.
Executive Summary & System Overview
In cross-border quantitative finance, capturing arbitrage between US-listed American Depositary Receipts (ADRs) and foreign ordinary shares requires ultra-low latency execution. However, institutional quants face severe back-office operational bottlenecks:
- Evaluating execution friction (slippage, borrow costs, custody fees, and withholding tax risk).
- Pricing currency hedges using Covered Interest Parity: F = S × (1 + r_d) / (1 + r_f).
- Complying with the impending November 14, 2026 SWIFT CBPR+ mandate, which strictly rejects cross-border payment instructions containing unstructured postal addresses.
To solve this $100M operational friction, we built Dual-Listing ADR / Ordinary Stock Arbitrage & SWIFT Converter—an autonomous, event-driven quantitative AI agent designed for the Taskmaster Track.
High-Level Architecture & Tech Stack
Our system runs asynchronously in the background on Google Cloud Platform without human hand-holding.
| Component | Technology | Architectural Purpose |
|---|---|---|
| Reasoning Engine | Gemini 3.5 Flash (gemini-3.5-flash) |
High-speed financial reasoning and 30-min Context Caching for ISO 20022 schemas. |
| Agent Framework | Google ADK (google-adk) |
Multi-step background orchestration and tool binding. |
| Active Defense | Google Cloud Model Armor | Proxy pattern scanning incoming payloads for prompt injection and PII leaks. |
| Syntax Judge | Gemma 2 9B IT (google/gemma-2-9b-it) |
Inline LLM judge enforcing 2026 SWIFT CBPR+ XML compliance. |
| Anomaly Engine | BigQuery ML (AI.DETECT_ANOMALIES / TimesFM) |
Zero-training statistical time-series anomaly detection. |
| Compute | Google Cloud Run (quant-agent-executor) |
Serverless microservice scaling to zero (min_instances = 0) to preserve cloud credits. |
| Observability | OpenTelemetry OTLP & Cloud Trace | End-to-end reasoning chain trace visualization in Google Cloud Console. |
Deep-Dive: Core Engineering Components
1. Zero-Training Signal Detection via BigQuery TimesFM
Rather than relying on brittle, fixed lookback windows or static Z-scores, we utilize Google's pre-trained TimesFM foundation model in BigQuery ML to detect true statistical spread anomalies:
SELECT * FROM AI.DETECT_ANOMALIES(
(
SELECT event_timestamp, adr_price_usd AS data_col
FROM `quantapp-1721025819770.market_spreads_prod.v_flattened_spreads`
WHERE adr_ticker = 'BABA'
),
STRUCT('event_timestamp' AS time_col, 'data_col' AS data_col, 0.95 AS anomaly_prob_threshold)
) WHERE is_anomaly = TRUE;
2. Zero-Trust Boundary via Google Model Armor Proxy
To protect our financial tools from prompt injection via unverified broker notes, incoming Eventarc webhooks pass through an inline security proxy:
class ModelArmorSecurityProxy:
"""Proxy Pattern: Scans payloads for prompt injection and PII leakage."""
async def validate_payload(self, payload: Dict[str, Any]) -> bool:
# Intercepts payload and consults Google Cloud Model Armor
is_clean = await model_armor_client.scan(payload)
if not is_clean:
logger.critical("SECURITY ALERT: Payload rejected by Model Armor guardrails.")
return False
return True
3. Institutional Financial Reasoning Tools
Our agent is equipped with modular tools that evaluate execution viability:
- Dynamic TCA Tool: Calculates True Net Spread by subtracting slippage, borrow costs, creation/cancellation fees ($0.05/share), and cablewire charges from the ratio-adjusted spread.
- WHT Risk Checker: Overrides positive spreads and issues an autonomous "No-Go" halt if an ex-dividend date is imminent (≤ 21 days) with a high Withholding Tax rate (≥ 5%).
- Covered Interest Parity (CIP): Prices forward exchange contracts F = S × (1 + r_d) / (1 + r_f) to hedge secondary currency legs.
4. Closed-Loop Self-Healing via Gemma 2
Before dispatching SWIFT instructions, Gemini 3.5 Flash passes the generated XML payload to Gemma 2 9B IT. Gemma validates that all postal addresses contain mandatory <TwnNm> and <Ctry> elements under <PstlAdr>. If Gemma flags a structural error, Gemini 3.5 Flash autonomously restructures the XML payload and resubmits it until validated.
Key Learnings & Conclusion
Building this agent demonstrated the power of decoupling data signals, security boundaries, and LLM reasoning. Utilizing Gemini 3.5 Flash's Context Caching allowed us to store massive ISO 20022 schemas in memory, achieving near-zero latency while keeping cloud costs minimal.
Check out our full source code, Terraform configurations, and spin-up instructions on GitHub:
🔗 Repository: https://github.com/evertonmendes/Dual-Listing-ADR-Ordinary-Stock-Arbitrage-SWIFT-Converter

Top comments (0)