End-to-End Stock Analytics — live demo

A scientific notebook turned into a deployable web service. Twelve quantitative methods (Monte Carlo + VaR/CVaR, Efficient Frontier, correlation, distributions, t-test, derivatives, PCA, Black-Scholes) on any yfinance ticker, with an incremental parquet cache, FastAPI backend, and vanilla-JS Plotly frontend.

← Home LinkedIn Notebook View on GitHub
About this project

This started as a research notebook — 1,689 lines of Python analysing twelve U.S. stocks (AAPL, MSFT, TSLA, GOOG, NVDA, META, SNPS, CDNS, XOM, JPM, WMT, AMC) with twelve quantitative methods. Outputs were Matplotlib plots and printed tables; nobody else could use it. The original notebook lives at scientific-source/12-stock-analysis.py in the repo.

Over seven phases (scaffold → port analytics → FastAPI → SPA → daily-refresh + Docker → end-to-end regression) it was turned into this deployable web service. The maths is unchanged — Black–Scholes is still Black–Scholes — but the delivery surface now goes any-yfinance-ticker → incremental parquet cache → typed JSON API → interactive Plotly browser charts. Per-phase build log in HANDOFF.md; mindset shifts in learning-notes.md.

A Phase 6 regression replays the scientific notebook's exact 12-ticker / 2023-11-16 → 2024-06-03 window through the commercial code and asserts numerical agreement. PCA PC1 explained variance: 29.83 % commercial vs 29.90 % scientific (0.07 pp drift, well inside the 2 pp tolerance). Black-Scholes Greeks match to 1e-6 on the textbook ATM case. See docs/COMMERCIAL_VS_SCIENTIFIC.md for the full reconciliation table.

Commercial Python: 2,464 lines SPA frontend: 1,146 lines Documentation: 1,590 lines Scientific source: 1,689 lines Tests: 32 / 32 green

Tech stack: FastAPI · Pydantic v2 · yfinance · pandas · numpy · scipy · scikit-learn · statsmodels · pyarrow · vanilla HTML/JS (no framework, no build pipeline) · Plotly.js · Docker. Full source, plans, and journey writeup in the GitHub repository — see README.md, HANDOFF.md, learning-notes.md, transformation-plan.md, and docs/COMMERCIAL_VS_SCIENTIFIC.md.

Disclaimer: Analytics are informational only and are not financial advice. Monte Carlo and Efficient Frontier outputs depend on assumptions (multivariate-normal returns, no transaction costs, no rebalancing) that do not predict the future. Black-Scholes Greeks are textbook valuations, not live market quotes.

Portfolio Builder

Inspect recent OHLCV + summary stats for a single ticker. Fetches lazily; the first request for a new symbol triggers an incremental yfinance backfill.

Risk Dashboard — Monte Carlo + VaR/CVaR

Correlated multivariate normal paths via Cholesky decomposition of the realised covariance. VaR is the loss at the worst α% of paths; negative VaR means even the worst paths ended in profit.

Portfolio Optimiser — Efficient Frontier

Random long-only weight sampling. Each dot is one portfolio; colour = Sharpe. The starred portfolio maximises Sharpe over the sampled set.

Diversification Check — Pearson Correlation

Side-by-side heatmaps for daily returns and trading-volume correlations. Toggle between the two without a second backend round-trip.

Return Profile — Distributions, Moments, t-test

Histogram of daily returns (or volumes) with a normal overlay, skew & kurtosis badges, and a one-sided t-test for positive drift.

Options Calculator — Black-Scholes & Implied Vol

European call/put pricing and Greeks. Implied volatility solved with Newton-Raphson; vega and rho scaled by 1/100, theta by 1/365 to match standard market quoting conventions.

Greeks update live as you change any input.


Implied volatility

Uses spot, strike, expiry, rate, and option type from the calculator above.

Advanced

PCA factor exposure and 1st / 2nd derivatives of returns (momentum / acceleration). Collapsed by default elsewhere; here they live as separate sub-cards.

PCA biplot
Derivatives (momentum & acceleration)