PSX Copilot
AI Research Assistant for the Pakistan Stock Exchange
A chat assistant for Pakistan Stock Exchange investors. Ask in plain words and it answers with live market prices, analysis drawn from official filings with citations, paper trading and strategy backtesting.
- Industry
- FinTech / Capital Markets
- Location
- Pakistan
Retail investors on the Pakistan Stock Exchange work from scattered sources. Prices sit on one website, company filings are published as PDFs elsewhere, and compliance lists are somewhere else again. Answering a straightforward question about a company means opening several sites and reading documents by hand.
- Company filings locked in PDFs, many of them scans, that are hard to search or compare
- Market data, filings, and compliance lists spread across separate sources
- No practice environment where orders behave like the real exchange
- Screening stocks by fundamentals required spreadsheets and manual work
- Existing terminals are built for professionals, not for someone asking a plain question
BrainGenz built PSX Copilot, a conversational agent over Pakistan Stock Exchange data. Users ask in plain words, and the system routes each question to live prices, filings retrieval, screening, portfolio state or trade staging - with every figure it states traceable back to data the code gathered.
- Built a LangGraph agent with two-layer routing: an embedding gate filters off-topic questions before any model call, then an LLM router emits typed actions that code executes
- Parsed official PSX filings, including OCR of scanned PDFs, into 298,000+ indexed extracts with hybrid retrieval and per-citation verification
- Connected live market data on a 60-second refresh, with quality gates that decide when a quote is trustworthy enough to act on
- Built the paper trading engine: deterministic order matching at live prices, commission and slippage from configuration, orders queued outside trading hours
- Wrapped every model-written reply in audits, so any figure the model states must exist in data the code gathered, with a deterministic renderer as the fallback
How it was built
In a finance product, one wrong number costs more trust than a hundred good answers earn back. So the model is never the source of a figure. Every reply about money is composed from a fact pack that code assembled first: execution results, cash balances, costs, timestamps.
An audit then rejects any rupee figure in the draft that does not exist in the pack, the same recipe used to check citations on filings answers. When a draft fails the audit, a deterministic renderer answers instead, so the user always gets correct numbers even when the model has a bad day. Anything that must be calculated is calculated in code and handed to the model as a fact it may quote.
Questions pass through two layers before any answer is written. An embedding-based relevance gate rejects off-topic requests without spending a model call at all. Questions that pass go to a router that emits typed actions, and code, not the model, executes them.
A question that spans several subjects, say a price check plus a filings question, fans out to separate data handlers whose results are blended into one reply. The model decides what the user meant; it never decides what the data says.
The order matcher is a pure function of the order and the current quote, which makes it testable line by line. Around it sit the rules that make simulation honest: a price gate decides whether a quote is fresh enough to fill against, orders placed outside trading hours queue and fill at the next open, Friday's split sessions are modeled, and the exchange's published circuit breakers are used to warn when a limit price cannot be reached today.
Commission is charged as a cash expense and never folded into the average buy price, so the P&L reads the way a broker's statement would. All timestamps are stored in UTC and shown on the exchange's clock in PKT, alongside the published holiday calendar.
The unglamorous half of the filings work was extraction: quarterly reports arrive as PDFs, many of them scans, and a wrong reading produces a confidently wrong answer rather than an obvious failure. The pipeline runs OCR where needed, splits documents into 298,000+ indexed extracts, and retrieves with a hybrid of keyword and semantic search.
On the way out, every citation in the model's answer is verified against the retrieved evidence before the reply ships, and a coverage step fills gaps in fetched documents before answering rather than answering around them. The user sees the extract and a link to the original PDF next to the claim it supports.
- Filings readable only by opening each PDF
- Testing a strategy meant risking real money
- Prices, filings, and compliance on separate sites
- No benchmark to judge a strategy claim against
- Cited answers from official filings in one chat
- Realistic simulated fills, costs included
- One surface for prices, filings, screening, and Shariah status
- Every backtest shown next to the KSE-100 over the same period
