Counterfactual: a dependency engine for your portfolio
Bloomberg explains markets. Our idea with Counterfactual was to map what your portfolio depends on, model what could happen next, and helps you act on evidence rather than instinct.

We have built it for self-directed retail investors who want to understand not just what they own, but the underlying assumptions quietly connecting it all.
Inspiration
The whole project started with one uncomfortable question: what if a portfolio that looks diversified is actually a single concentrated bet?
Own Microsoft, NVIDIA, a cloud provider, and a chipmaker and you hold four tickers, but maybe just one position. Underneath, they can all lean on the same AI infrastructure cycle, the same supply chain, the same geography, the same macro conditions. Diversification isn't a ticker count. It's how independent the underlying assumptions really are.
Most retail tools show you what you own and what already happened. We wanted to show the forces underneath: which positions share hidden dependencies, how a shock would ripple through them, what evidence supports those links, and what you might do about it.
Our team which happened to form (a happy accident) was our biggest advantage, four people from very different backgrounds. Toyesh drove the product concept and AI architecture. Rita shaped the product flow and interaction design. Irfaan handled the financial engineering, the broker integration, and the technical build. Yash stress-tested the portfolio-risk reasoning at every turn. That mix is what turned an ambitious idea into something a regular investor can actually use, not just a quant or trader.
What it does
For the core, Counterfactual turns a personal portfolio into an interactive Portfolio X-ray, a risk-desk view of the assumptions connecting your investments.

It connects through Alpaca as the broker today, with a normalized portfolio layer built to support other brokers later.
Six workflows fit together:
- Overview surfaces concentration, model coverage, unmapped exposure, fragility, and shared dependencies.
- Dependencies draws companies, sectors, countries, macro factors, and themes as a live graph and a geographic map.
- Scenario Lab lets you define shocks, pick a horizon, and compare modeled outcomes side by side.
- The Wire turns curated news and market signals into scenarios you can edit and run.
- Simulation produces reproducible, scenario-conditioned runs with full diagnostics and provenance.
- Guide converts the analysis into an editable, evidence-linked action proposal, with a separate review step before anything is confirmed.

The idea is to move from "what do I own?" to "what does everything I own depend on?" Counterfactual doesn't replace your judgment. It hands that judgment a better map and sharper questions.
How we built it
The stack: Next.js, React, TypeScript, React Flow, Recharts, Alpaca APIs, OpenAI GPT-5.6, and Codex.
The knowledge engine works in stages:
Curated evidence
→ AI-assisted relationship extraction
→ RL-assisted relationship scoring
→ validation and provenance
→ versioned dependency graph
At runtime, your portfolio and scenario are evaluated against the published graph:
Portfolio + Scenario
→ Dependency propagation
→ Holding and factor attribution
→ X-ray, Graph, Map, Simulation, and Guide
The propagation engine is deterministic. It accounts for relationship strength, confidence, freshness, transmission lag, cycles, and converging paths. The graph, map, risk wheels, comparisons, and Guide all consume the same result contract, so they explain the same calculation instead of five slightly different ones.
The Alpaca connector runs against the paper environment for safe demonstration, but orders still go through the real Alpaca API workflow after explicit user confirmation.
How we worked with OpenAI
We pressure-tested the idea with ChatGPT first. It poked holes, challenged assumptions, and helped turn a rough concept into a proper build brief. Codex and Claude Code then helped assemble an early prototype in one focused two-hour session.
During Build Week, GPT-5.6 and Codex became real engineering collaborators. They helped redesign the architecture, implement the Portfolio X-ray, harden the dependency engine, build Scenario Lab and Simulation, wire the product surfaces together, write tests, chase edge cases, and even produce the Remotion submission video.

What surprised us was the continuity. The same tools moved with us from brainstorming to architecture to implementation to review, holding the context behind thousands of interconnected decisions. It felt like adding capacity to the team rather than using a tool.
The scoped Build Week work added 19,819 lines of source and tests. We estimate GPT-5.6 and Codex drove roughly 90% of the substantive progress. That number is a judgment call, not a line count. And the humans set the boundaries throughout: AI never controls the portfolio math, order sizing, or execution authorization.
Challenges we faced
The hardest part was keeping every layer honest. Dependency graphs have cycles, delays, overlapping paths, and relationships with wildly different confidence levels. We also had to make sure unmapped holdings stayed visible instead of quietly reading as zero risk.
Then there was consistency: the Overview, graph, map, simulations, comparisons, and Guide all had to explain the same result. Our answer was a shared, versioned analytical contract, rather than letting each interface compute its own story.
What we learned
Explainability turned out to be a data contract, not a tooltip. Model identity, coverage, assumptions, evidence, attribution, and limitations have to survive the trip from the engine to every screen.
We also learned that AI collaboration compounds with clarity. ChatGPT sharpened the idea, GPT-5.6 strengthened the reasoning and architecture, and Codex turned detailed plans into tested software at real speed. The better our own thinking got, the better the collaboration got.
What's next
Broader graph coverage, more broker connectors, continuously reviewed evidence ingestion, simulations calibrated against licensed historical data, and historical replay across market regimes.
The goal stays the same: make serious portfolio reasoning useful to anyone managing their own money, so they can see the assumptions beneath their holdings and act on evidence before the market tests them.
Built With
- alpaca-api
- codex
- next.js
- openai
- openai-gpt-5.6
- react
- react-flow
- typescript
