Skip to content

jamalishaq/apex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apex — Trade & Risk Intelligence Platform

An AI-powered incident intelligence platform for trading operations. Eliminates 20–45 minutes of manual context gathering per incident by pre-assembling a complete operational briefing the moment a trade break or risk limit breach alert fires.


The Problem

When a trade break or risk limit breach alert fires, operations teams manually reconstruct context across 4–6 systems — trade records, position blotters, risk limit dashboards, counterparty records, regulatory obligation references — before they can act. This takes 20–45 minutes per incident under normal conditions. Under pressure, with multiple alerts firing simultaneously, things get missed.

Apex eliminates the manual gathering step. The alert arrives → Apex assembles the full context automatically → the operations team receives a ready-to-act briefing in seconds.


Architecture

External alert source
(Grafana / PagerDuty)
        │
        ▼ POST /analyse
  Internet-facing ALB
  (IP-restricted listener rule)
        │
        ▼
  FastAPI on ECS Fargate
        │
        ├─► SQS Queue ──► Lambda ──► SES notification
        │
        ▼
  AI Pipeline
  ┌─────────────────────────────────────┐
  │                                     │
  │  1. RAG pipeline step               │
  │     Cohere Embed v4 + Rerank 3.5    │
  │     S3 Vectors                      │
  │                                     │
  │  2. Reasoning agent                 │
  │     Claude Sonnet 4.6               │
  │     5 tools (structured data)       │
  │                                     │
  │  3. LLM-as-judge (async)            │
  │     Claude Haiku 4.5                │
  │     4 scoring dimensions            │
  │                                     │
  └─────────────────────────────────────┘
        │
        ▼
  DynamoDB (incident store)
        │
        ▼
  React + Vite Frontend
  (S3 + CloudFront)

Infrastructure: All AWS. Terraform with S3 backend (native locking). GitHub Actions with OIDC authentication (no long-lived keys). ECS Fargate, DynamoDB, S3 Vectors, SQS, Lambda, SES, CloudFront.


The 8 Demo Scenarios

# Alert type Instrument Desk Complexity
S01 Trade break — price mismatch TSLA Equity Derivatives Low
S02 Trade break — settlement failure UK Gilt 4.25% 2034 Fixed Income Low
S03 Position limit breach — float % NVDA Equity Derivatives Medium
S04 VaR breach — tech basket NVDA/AAPL/MSFT/GOOGL/META Equity Derivatives Medium
S05 Counterparty credit breach Goldman Sachs Equity Derivatives Medium
S06 Margin call E-mini S&P 500 Dec 2025 Macro Rates High
S07 Cascading trade break AAPL Equity Derivatives High
S08 Sector concentration + UCITS regulatory flag XOM/CVX/SLB Energy & Commodities High

Key Design Decisions

RAG as a pipeline step, not an agent tool. Regulatory document retrieval happens before the agent runs and is injected into the system prompt. This keeps latency low and retrieval deterministic per alert type. See docs/adr/ADR-001-002-design-decisions.md.

No agent frameworks. The agentic loop is implemented directly against the Anthropic SDK. No LangChain, no LlamaIndex. This keeps the pipeline transparent and the dependencies minimal.

5 tools, no more. The reasoning agent has exactly 5 structured data tools. Tool count is a design decision — more tools means longer loops and more opportunity for drift.

Mock data only. All trading data is synthetic. There are no real trading system connections. The fixture data is realistic enough to demonstrate genuine domain knowledge.


Domain Context

Trade breaks occur when there is a mismatch between what Apex's firm recorded for a trade and what the counterparty (e.g. Goldman Sachs, JPMorgan) confirmed. Unresolved breaks can become failed settlements, triggering regulatory reporting obligations and counterparty relationship damage.

Risk limit breaches occur when a desk exceeds its authorised exposure — whether by position size (float %), daily VaR, counterparty credit, or sector concentration. Breaches must be reported to risk management immediately.

Margin calls are urgent collateral demands from clearing houses (e.g. CME) when a leveraged position moves against the firm. If unmet within the deadline, the position is liquidated — typically at the worst possible time.

The operations team currently gathers context from: the trading system (Murex/Calypso), counterparty confirmation systems (SWIFT), the position blotter, the risk system (Bloomberg AIM/RiskMetrics), the counterparty record, and regulatory reference documents. Apex replaces those 6 manual lookups with one structured briefing.


Getting Started

Local development

# Backend
cd backend
pip install -r requirements.txt
APEX_ENV=local uvicorn app.main:app --reload --port 8000

# Frontend
cd frontend
npm install
VITE_API_BASE_URL=http://localhost:8000 npm run dev

# Fire a demo alert (S06 — margin call)
curl -X POST http://localhost:8000/analyse \
  -H "Content-Type: application/json" \
  -d @data/scenarios/s06_sp500_margin_call/alert.json

Infrastructure

cd infra
terraform init
terraform plan -var-file=dev.tfvars
# terraform apply — only via CI/CD pipeline

Embed the knowledge base

cd knowledge_base
python embed.py --raw-dir raw/ --chunks-dir chunks/ \
  --s3-bucket apex-vectors-$(aws sts get-caller-identity --query Account --output text) \
  --region us-east-1

Environment Variables

Variable Description Required
APEX_ENV local / mock / production Yes
APEX_AWS_REGION AWS region Yes
APEX_DYNAMODB_TABLE DynamoDB table name Yes
APEX_S3_VECTORS_BUCKET S3 Vectors bucket name Yes
AWS_ACCESS_KEY_ID AWS credentials (local only) Local
AWS_SECRET_ACCESS_KEY AWS credentials (local only) Local
VITE_API_BASE_URL Backend URL for frontend Build time
VITE_DEMO_MODE Enable scenario trigger panel Build time

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages