Under the Hood
How Agentic Market Explainer works
Every stock move gets a headline. Almost none of them get a real answer. You open a chatbot, ask why your position is down 8%, and it gives you a plausible-sounding paragraph pulled from training data that’s months old, with no idea what the price, volume, or news actually did today. I built this because that isn’t good enough for anyone trying to understand what happened. Agentic Market Explainer pulls the actual price, volatility, and events first, then the news, options, and analyst data it needs, before it says why a stock moved. It shows its work, and when the evidence doesn’t point to a cause, it is told to say so.
Designed, built and run by Sakthivel Baskaran. The code, tests and design decisions are on GitHub.
Deterministic first
Live price, volatility, and a statistical significance check run in plain code before any model call. The model reads that verdict; it never decides whether a move is unusual.
Agentic when it counts
A bounded agent decides for itself which evidence is worth pulling: news, options, analysts, sector, or macro. A routine move usually needs none of it, so the answer stays short and cheap.
Swappable tools and models
Each data source is a separate tool with its own fallback, and OpenAI and Claude run the same loop behind one interface, so either can change without redesigning the agent.
Pipeline
1. Pull price, volatility & events, always, no LLM call
Every investigation starts the same way: latest price, multi-horizon % change, realized volatility, and the earnings and events calendar are fetched in parallel by code, before the model is invoked.
2. Statistical significance verdict
Each horizon is compared with the stock's own realized volatility (typical below 1.5×, unusual from 2.5×) and with an absolute size floor. Code also writes the “what happened” paragraph, which you see before the model has written anything.
3. Results handed over as tool calls
The pre-fetched price and events are spliced into the conversation as if the model had asked for them itself, which saves a model round trip.
4. The LLM decides what else is needed
Reasoning is handled by a fast, low-cost model, OpenAI by default or Claude Haiku, switchable from the logo at the left of the search bar. Both run the same tool-use loop on the same data. In at most 7 turns, the model decides what is still missing, such as news, analyst actions, options, sector, or macro, and calls the relevant tools in parallel.
5. Synthesize, with a hard grounding rule
The model must finish by submitting one structured answer: evidence tiles, then ranked hypotheses with confidence, then the explanation. It cites headlines by number, and the server turns each number into a real link or removes it. It is instructed to say “Data unavailable” rather than invent a number.
Data Tools
get_price_dataprice.pyLatest price, multi-horizon % change, and annualized realized volatility. Finnhub quote first for the live tick, yfinance always for the historical series (and as the price fallback).
get_options_dataoptions.pyATM implied volatility, where it sits across strikes in the same chain (not a historical IV rank), put/call ratio, and skew.
get_options_positioningoptions.pyDeeper 2–4 week positioning: max pain, call/put open-interest walls, IV term-structure trend, and unusual volume-vs-open-interest activity.
get_newsnews.pyHeadlines for the ticker from the last 7 days. Finnhub first, yfinance fallback.
get_macromacro.pyMarket-wide context, cached once and shared across tickers: VIX from FRED (yfinance fallback) and the S&P 500's daily change from yfinance, each with its own date.
get_eventsevents.pyEarnings in both directions — the quarter just reported (with the actual-vs-expected beat or miss) and the next one scheduled (Finnhub, yfinance fallback) — plus recent ex-dividend dates and the next FOMC meeting.
get_analyst_sentimentanalyst.pyRecent analyst upgrades and downgrades with their price-target changes, plus where the Street stands now: consensus rating, whether it's been improving or deteriorating, and how far apart the price targets are.
get_sector_comparisonsector.pyCompares the stock's multi-horizon moves against its sector ETF's moves, to separate stock-specific news from a sector-wide drift.
How It’s Tested
390+ offline tests
They cover the data tools and their fallbacks, the agent loop, scope and ticker checks, caching, the API, both vendors' adapters, and the eval harness, with no network or model calls. Scripted fake model streams drive the real loop. Separate live checks confirm every week that the data sources still return what the code expects.
Replay evaluation
Recorded trading days are replayed through the production loop and scored in plain code for structure, figures that match the data, citations, length, speed, and cost. 480 runs: 40 cases, four model setups, three repeats each.
Claude vs. OpenAI
The evaluation found the production model at the time, Claude Haiku 4.5, cost 12 to 20 times more than the alternatives and broke more writing rules. Claude runs moved to Haiku 5.5 after its failures were fixed, and GPT-6 Luna became the default.
Under $2 per 1,000 investigations
Measured over 120 replayed runs, counting model cost only, on both vendors and with the prompt cache both cold and warm. Both list the same prices; Claude costs more because it counts more tokens for the same text.
The main limitation: there is no labelled ground truth yet, so none of this shows whether the top-ranked cause is the true one, and a real number attached to the wrong fact would pass the figure check. Hand-labelled cases are the next step. Methods, full tables and caveats are in the evaluation report.
FAQs
Is this financial advice?
No. This is an informational and educational tool that describes recent price action. It does not predict future moves or recommend buying, selling, or holding anything. Always verify important numbers against a primary source and consult a licensed financial advisor before acting.
Where does the data come from?
Every number comes from a live API call inside one of these tools, or a short-lived cache of one: Finnhub for live quotes and news (with yfinance fallback), FRED for macro (yfinance ^VIX fallback), and yfinance for history, options chains, analyst consensus, earnings dates, and sector classification. Every tool degrades gracefully — if a source fails, it falls through to the next rather than erroring out the whole query.
Why didn't it look at news or options for my query?
Usually because the move didn't clear the significance bar. Every horizon is scored on two axes: a relative ratio against the stock's own realized volatility, and an absolute magnitude floor. A routine 0.5% drift fails both, so the model is told to give a short answer instead of hunting for a catalyst.
Can the AI make up numbers?
It's discouraged, not impossible. Price and volatility are computed in plain code, and the model is told to use only numbers from its tool results. In the 480-run model evaluation, 96% to 100% of the % and $ figures matched the recorded data, depending on the model. It can still misread a headline or attach a real number to the wrong fact, so verify anything you act on.
What's the difference between this and a normal chatbot?
A general chatbot answers a “why did this stock move” question from stale training data and a confident guess. This app pulls current price, volatility, and event data before the model reasons about anything, lets it fetch more evidence, and requires a structured answer whose news links come from the server, never from the model.
Does this work for non-US stocks?
Best support is US-listed equities and ETFs. Non-US tickers may resolve with sparse or missing data, or not at all — treat results outside US markets as unreliable for now.
Limitations
- US-market only. Price, options, news, and macro sources are all oriented around US-listed equities and ETFs; non-US tickers aren't reliably supported and thinly-covered US names may come back with sparse evidence.
- No intraday tick data or Level 2 order book. Options positioning and price moves are summarized, not tick-by-tick.
- The significance check means small, “boring” moves intentionally get a shallow investigation. This is a deliberate cost/latency tradeoff, not a coverage gap to fix.
- Like any LLM system, outputs can be incomplete, out of date, or simply wrong. Every claim should be checked against a primary source before you act on it.
On the Roadmap
Crypto & FX coverage
Extend beyond equities/ETFs to major crypto and FX pairs.
Multi-ticker comparisons
Ask about two tickers at once (“AAPL vs MSFT this week”) in a single run.
Persistent query history
Save past investigations across sessions instead of resetting on refresh.