FieldTrade AI
Turning global news noise into explainable, risk-calibrated market intelligence.
A case study on how I designed and built AI FieldTrade, a local-first market intelligence platform. It ingests live global news, deduplicates and classifies events, propagates shocks through sectors and supply chains, and issues BUY / HOLD / SELL / WATCH calls through a multi-agent forecasting graph where every number can be traced.
Project Snapshot
The problem, the users and the approach at a glance
Thousands of news items, decrees and supply-chain shocks arrive every hour. Teams need explainable signals before the market prices them in.
Portfolio managers, risk and compliance officers, quant researchers, and the IT teams who run the platform.
The reasoning core should be deterministic and auditable. An LLM is only an optional layer that phrases the output.
Pure-Python NLP, 14 analytical engines and a multi-agent forecasting graph with a quality gate and adversarial critique.
FastAPI and Supabase PostgreSQL with SQLite failover, Entra ID sign-in, and Microsoft Graph email alerts.
Predictions are reconciled against realized 7–30 day outcomes, and Brier-based calibration adjusts confidence weights.
Why I Built FieldTrade
Markets react to events: a trade restriction, a rate decision, a factory fire. The hard part isn't finding the news. It's knowing which of today's thousands of headlines matter, who is affected two steps down the supply chain, and whether a model's call can be trusted and explained to a risk committee.
The same story appears across dozens of feeds, so the signal gets lost in duplicates.
The first-order company is obvious. The suppliers and customers one hop away are where value is missed.
Risk and compliance teams can't sign off on a score nobody can explain or reproduce.
Running every headline through a large model is expensive, slow and ties you to one vendor.
Models rarely say “I don't know”, even when data is stale or signals contradict each other.
Most signal tools never check their past calls against what the market actually did.
“Every call the system makes should come with its reasons, its risks, its critic's view, and a record of whether it turned out right.”
Understanding the Problem Before Writing Code
I started from the people who would rely on the output and what each of them couldn't live without. Most of the architecture came from their constraints: explainability, cost and auditability.
Stakeholder Pain Mapping
Mapped what portfolio managers, risk officers, quant researchers and IT each need and fear.
News-to-Price Workflow
Broke down how an analyst moves from a headline to a sector view to a position decision.
Compliance Constraints
Listed the auditability, prompt-injection and forward-looking-statement risks the system must handle.
Cost & Ops Constraints
Set a hard goal: the core must run locally, offline and without paid LLM inference.
Who I Was Building For
| STAKEHOLDER | PAIN POINT | WHAT THEY NEED FROM THE SYSTEM |
|---|---|---|
| Portfolio Managers | Slow to spot multi-industry second-order effects. | 2-hop supply-chain and sector ripple analysis showing upstream and downstream winners and losers. |
| Risk & Compliance | Black-box AI, audit gaps, prompt-injection risk. | Deterministic scoring, guardrails and immutable prediction traces. |
| Quant Researchers | Overfitting and opaque deep-learning signals. | A transparent multi-agent graph combining technical, macro, precedent and adversarial signals. |
| Operations & IT | High LLM inference costs and vendor lock-in. | A zero-dependency local analytical core with low compute overhead. |
- ✓12 macro event taxonomies
- ✓3 impact horizons (0–5d, 1–4w, 1–12m)
- ✓2-hop supply-chain ripple analysis
- ✓Deduplication & clustering of news
- ✓Technicals: SMA/EMA, RSI(14), MACD, Bollinger
- ✓Volatility regimes via VIX & macro benchmarks
- ✓Beta, sector ETF co-movement, precedents
- ✓Integrity gate that can abstain
- ✓Match breaking news to user holdings
- ✓Severity / shock threshold alerts
- ✓Board-ready HTML email briefs
- ✓Log every recommendation (ACID)
- ✓Reconcile against 7–30 day outcomes
- ✓Brier-based bounded recalibration
- ✓Portfolio-aware chat
- ✓Real-time quote lookups
- ✓Guardrails & domain confinement
- ✓Executive surveillance hub
- ✓Supply-chain explorer
- ✓3D geopolitical risk globe
- ✓Multi-agent lab
Explainability
Plain-English causal logic, catalysts, tail risks and parameter traces for every call.
Determinism
The same inputs give the same scores, regardless of which orchestration backend runs.
Local-first
The core runs offline on pure Python with SQLite, and no API keys are required.
Graceful fallbacks
Every cloud dependency has a local fallback: DB, auth, email and agent runtime.
Safety
Prompt-injection defence, domain confinement and regulatory disclaimers on forecasts.
Auditability
Predictions and alerts are persisted with timestamps, channels and recipients.
Translating Requirements Into Product Decisions
Once I had the requirements, the question became what each user should actually see and trust. I turned each complaint into the underlying need and then into a specific product decision.
“I learn about a supply-chain shock after the price has already moved.”
Users need early visibility of indirect effects, not just the headline company.
A 2-hop supply-chain engine plus immediate, short-term and long-term impact horizons.
“I can't take a black-box score to the risk committee.”
Every call must be reproducible and explained in plain language.
Deterministic scoring, an explainability engine and a stored trace ID for every prediction.
“Half my feed is the same story ten times.”
Events should be the unit, not articles.
TF-IDF + cosine clustering: merge at ≥ 0.62 similarity, new event cluster at ≥ 0.42.
“Just tell me when it hits my holdings.”
Alerts should be tied to the user's portfolio.
Holdings matching with severity thresholds and Microsoft Graph email briefs.
“The model is confident even when the data is garbage.”
The system should know when not to answer.
A Quality Agent that can abstain, plus a Critique Agent that attacks every thesis.
“LLM bills scale with every headline.”
Reasoning should not depend on paid inference.
A zero-LLM analytical core. Azure OpenAI is only an optional phrasing layer.
The User Journey I Designed For
Morning briefing
The executive hub shows the daily macro outlook, sector movers and portfolio warnings.
Live intelligence
Streaming news, event clusters, sentiment and causal breakdowns.
Trace the ripple
The supply-chain explorer shows upstream and downstream exposure two hops out.
Run a forecast
The multi-agent lab shows every agent's vote, weights, debate log and VaR.
Watch the portfolio
Holdings, P&L and alerts when news crosses shock thresholds.
Ask the copilot
Portfolio-aware questions with guardrails and live quotes.
How the Architecture Was Designed, Step by Step
The architecture came from one early decision: the core reasoning had to be deterministic. Everything else followed as a series of separation and fallback choices.
Where is an LLM worth the cost and the opacity?
The whole analytical core (NLP, scoring, risk, propagation) is pure Python. An LLM is optional and only rephrases outputs.
Reproducible scores for compliance, near-zero inference cost and no vendor lock-in.
How do we keep ingestion, analysis and orchestration independently testable?
Ingestion & NLP → Analytical Engines → Multi-Agent Graph → API & Persistence → React presentation.
Each tier can be tested, replaced or scaled without touching the others.
What is the unit of analysis?
Clustered events, not articles: tokenize → TF-IDF dedup → 12-class classification → entities → sentiment → horizon.
Removes duplicate noise before any expensive analysis runs.
How do we keep the domain logic understandable?
14 engines, each doing one job (sector, supply chain, policy, commodity, risk, scoring and more).
Small engines are easy to test and easy to explain.
How do we combine conflicting signals honestly?
Collector → Quality Gate → Regime → parallel specialists → Risk → Conflict Resolver → Synthesizer → Critique → Narrator.
Each signal is visible, disagreement is resolved explicitly, and the thesis is always challenged.
What happens if LangGraph isn't installed?
Use a compiled LangGraph StateGraph with parallel fan-out when available, otherwise an in-memory sequential runner. Both produce contract-identical numbers.
Scales up without losing local-first behaviour or determinism.
How does it stay usable offline or during outages?
Supabase → SQLite WAL; Entra ID → Google OAuth → local session; Microsoft Graph → SMTP.
The platform degrades gracefully instead of failing.
How does the system get better?
Persist every prediction, ingest realized outcomes and recalibrate category weights with bounded Brier-based updates.
It improves over time while the bounds prevent a runaway feedback spiral.
Layered System Architecture
Ingestion & Pure-Python NLP
From raw text to clean events
Specialized Analytical Engines
Domain reasoning
Multi-Agent Prediction Graph
Forecasting & consensus
API, Persistence & Integrations
Serve, store, secure, notify
React Web Presentation
Analyst workspace
End-to-End Data Flow
Inside the Engines and Agents
How a headline becomes an event, how an event becomes a forecast, and how the forecast learns from the market.
Pure-Python NLP Ingestion Pipeline
The 14 In-House Analytical Engines
| Engine | Purpose |
|---|---|
| Sector Impact | Maps direct and secondary shocks across 14 market sectors. |
| Company Exposure | Maps revenue streams, operational footprint and geographic exposure to catalysts. |
| Commodity | Analyzes supply/demand shocks across energy, metals and agriculture. |
| Policy & Central Bank | Interprets rates, QE/QT, tariffs, subsidies and fiscal stimulus. |
| Supply Chain | Models supplier → manufacturer → distributor dependency trees across two hops. |
| Historical Similarity | Matches live events against benchmark historical shocks using cosine similarity. |
| 4D Event Scoring | Severity, Urgency, Duration and Economic Breadth. |
| 7D Risk Assessment | Political, Economic, Regulatory, Commodity, Currency, Supply Chain and Volatility risk. |
| Opportunity Heatmap | Normalizes sector scores for real-time visual surveillance. |
| Explainability | Translates quantitative models into structured natural-language briefings. |
| Event Timeline Builder | Constructs forward-looking milestones and catalyst calendars. |
| Portfolio Impact | Computes delta-risk, estimated P&L sensitivity and hedging actions. |
| Country & Geopolitical | Scores sovereign stability, FDI attractiveness and trade vulnerability for 40+ countries. |
| Continuous Feedback | Applies directional Brier-score calibration to sector confidence weights. |
Multi-Agent Forecasting Graph
Agent Responsibilities
| Agent | Responsibility | Techniques / Metrics |
|---|---|---|
| Collector | Gathers OHLCV history, fundamentals, market caps | Yahoo Finance / Finnhub, local caching, split adjustment |
| Quality | Validates data integrity; can trigger Abstain | Missing dates, stale quotes, splits, anomaly spreads |
| Regime | Identifies the macro risk environment | VIX, SPY moving averages, Treasury yield spread |
| Trend | Evaluates price action and momentum | SMA/EMA, RSI, MACD, Bollinger bands |
| Correlation | Assesses systemic co-movement | Rolling beta, sector ETF correlation |
| Historical | Matches corporate/sector shock patterns | Forward-return profiles, event similarity |
| News Intel | Extracts active corporate catalysts | Event scoring, sentiment, disruption magnitude |
| Sentiment | Measures institutional and retail tone | News polarity, analyst consensus |
| Risk | Evaluates downside and tail risk | 95% historical VaR, max drawdown, volatility skew |
| Conflict Resolver | Resolves opposing signals | Dynamic weighting by volatility regime |
| Synthesizer | Combines signals into the forecast | Directional probability, target band, conviction |
| Critique | Challenges the thesis | Confirmation bias, tail risks, contrarian failure points |
| Narrator | Produces the executive briefing | Narrative constrained to the mathematical trace |
Forecast API Contract
POST /api/stock/NVDA/predict
{
"horizon": "SHORT_TERM",
"risk": "balanced",
"offline": false,
"backend": "auto" // LangGraph if available, else sequential runner
}Continuous Self-Learning Calibration Loop
Infrastructure With Fallbacks
| Area | Primary | Fallback / Notes |
|---|---|---|
| Database | Supabase PostgreSQL | SQLite 3 with WAL for local/offline use |
| Identity | Microsoft Entra ID / MSAL | Google OAuth 2.0 / OIDC, local sessions |
| Session security | HttpOnly, SameSite=Lax cookies | SHA-256 token verification |
| AI guardrails | Prompt-injection defence + domain confinement | Regulatory disclaimers on forward-looking statements |
| Notifications | Microsoft Graph API | TLS SMTP |
| Agent runtime | LangGraph StateGraph (parallel) | In-memory sequential runner, same numbers |
Tech Stack & Why Each Piece Was Chosen
Python 3.10+ · FastAPI · Uvicorn
Lightweight async I/O for ingestion and API serving.
Pure Python
Deterministic and dependency-free, with minimal compute.
LangGraph StateGraph
Parallel fan-out, with a pure-Python sequential fallback.
Supabase PostgreSQL · SQLite WAL
Cloud persistence plus offline capability.
Microsoft Entra ID · Google OAuth
Corporate SSO with a consumer and local fallback.
Microsoft Graph · SMTP
Board-ready Outlook briefs, with SMTP as the fallback.
Next.js 16 · React 19 · Tailwind
A modern component architecture for a dense analyst workspace.
Three.js / WebGL
Interactive geopolitical risk globe.
Yahoo Finance · Finnhub
OHLCV and fundamentals with local caching.
Building It Phase by Phase
I built FieldTrade bottom-up, following the tiers, so each layer was tested before the next one depended on it. Phase 1 (Foundation) is complete, and Phase 2 (Cloud Hardening) is where the work is now.
- 1
NLP ingestion pipeline
Goal: Turn raw feeds into clean, deduplicated events.
- •Tokenization, stop-words, stemming
- •TF-IDF vectors + cosine dedup/clustering
- •12-class classifier, NER and bounded sentiment
Output: An event stream instead of an article stream.
- 2
The 14 analytical engines
Goal: Encode domain reasoning as small, testable units.
- •Sector, company, commodity and policy engines
- •2-hop supply-chain propagation
- •4D event scoring and 7D risk assessment
Output: Per-event impact across sectors, companies and countries.
- 3
Multi-agent forecasting graph
Goal: Honest, explainable stock forecasts.
- •Collector, Quality Gate and Regime agents
- •Parallel specialists, Risk and Conflict Resolver
- •Synthesizer, Critique and Narrator, with a dual backend
Output: Forecasts with direction, conviction, critique and a full trace.
- 4
API & data contracts
Goal: Expose everything through clean endpoints.
- •FastAPI endpoints for briefing, analysis, prediction and portfolio
- •Stable response contracts
- •Guardrails on the chat endpoint
Output: A documented API the frontend and integrations can rely on.
- 5
Next.js analyst dashboard
Goal: Make the intelligence usable.
- •Executive hub, live intelligence and supply-chain explorer
- •3D geopolitical risk globe
- •Portfolio hub, copilot studio and multi-agent lab
Output: An institutional dark-theme workspace.
- 6
Cloud hardening (current phase)
Goal: Enterprise-ready persistence, identity and alerts.
- •Supabase persistence with SQLite failover
- •Entra ID sign-in and Microsoft Graph email
- •Live financial news ingestion
Output: Portfolio-linked alerts delivered to Outlook.
- 7
Feedback & calibration loop
Goal: Make the system learn.
- •Persist every prediction
- •Outcome ingestion endpoint
- •Bounded Brier-based weight updates
Output: Confidence weights that track real-world accuracy.
How I Verified It Works
Since the core is deterministic, most of it can be tested like ordinary software, with exact expected numbers rather than a vague sense that the answer looks plausible.
Unit tests (pytest)
Engines and NLP stages are tested in isolation with fixed inputs.
- ✓Deduplication thresholds (0.62 merge / 0.42 cluster)
- ✓Event classification and bounded sentiment
- ✓Scoring and risk engines return stable values
- ✓Calibration weights stay within [0.50, 1.50]
Backend parity
Both orchestration backends must agree exactly.
- ✓LangGraph and sequential runners give contract-identical numbers
- ✓Response schema matches the API contract
- ✓Agent contributions and trace ID are always present
Integrity & safety
The system must fail safe.
- ✓Stale or missing data → Quality Gate abstains
- ✓High agent divergence → abstention
- ✓Prompt-injection and off-domain prompts are refused
- ✓Disclaimers are attached to forward-looking statements
Offline & fallback paths
Every fallback is exercised on purpose.
- ✓run_demo.py runs end to end with no network
- ✓Supabase unavailable → SQLite WAL
- ✓Graph unavailable → SMTP alert delivery
Success Criteria → How Each Was Verified
| CRITERION | VERIFIED BY |
|---|---|
| Explainability | Every forecast response includes thesis, catalysts, critique and agent contributions. |
| Determinism | Backend parity tests with identical numeric outputs. |
| Local-first | The offline demo run with SQLite and no API keys. |
| Safe abstention | Quality-gate tests with corrupted and stale market data. |
| Bounded learning | Calibration tests at extreme win rates. |
| Resilience | Forced failures of the DB, identity and email providers. |
Shipping It
FieldTrade runs in two modes: fully local, or connected to cloud services. The same codebase switches between them purely through configuration.
Configure persistence
Set the Supabase PostgreSQL connection, or leave it empty to use SQLite WAL.
Set agent controls
Agent mode, minimum data quality, minimum agreement, maximum risk cutoff and latency budget.
Wire up identity
Entra ID client and tenant settings, with Google OAuth as an alternative.
Connect data & notifications
Optional Finnhub enrichment and Microsoft Graph for email briefs.
Optional LLM phrasing
Azure OpenAI endpoint and deployment, used only to rephrase the deterministic output.
Run & verify
Run the test suite, the offline demo, then start the API and the dashboard.
Local-first mode
Pure-Python core, SQLite, local sessions and no keys required. Runs on a laptop.
Cloud mode
Supabase PostgreSQL, Entra ID SSO, Microsoft Graph alerts and live news ingestion.
# Run tests python -m pytest -q # Offline market intelligence demo python run_demo.py # Start FastAPI backend python -m fieldtrade serve # Start Next.js frontend cd webapp && npm install && npm run dev
What I Learned & What's Next
Determinism is a feature.
Keeping the reasoning core LLM-free made the system cheaper, faster, testable and explainable to compliance.
Let the model say “I don't know”.
A quality gate that abstains is worth more than a confident wrong answer.
Build in the critic.
A dedicated agent that attacks the thesis catches confirmation bias that one model can't see in itself.
Every dependency needs a fallback.
Designing SQLite, SMTP and a sequential runner up front made the platform usable anywhere.
Bound your feedback loops.
Self-learning without limits drifts. Clamping weights to [0.50, 1.50] keeps calibration stable.
Small engines, big picture.
Fourteen single-purpose engines turned out to be easier to reason about than one clever model.
Roadmap
Phase 1 — Foundation
Pure-Python NLP, 14 analytical engines, multi-agent graph, Next.js 16 / React 19 dashboard.
Phase 2 — Cloud Hardening
Supabase persistence, SQLite failover, Entra ID, Graph email, guardrails, live news ingestion.
Phase 3 — Institutional Scale
FIX/OMS/EMS connectivity, alternative data (AIS, satellite, patents), multi-tenancy and RBAC.
FieldTrade is a research and engineering project. Its outputs are analytical signals, not investment advice.