Quant research & trading·Python·Published
Portfolio Risk Dashboard
I built this to have one place where a submitted portfolio comes back with the numbers that actually matter before I add a position. It is a FastAPI app that takes positions and prices and returns historical VaR as a non-parametric percentile and parametric VaR as a Gaussian estimate, both at 95% and 99%, plus CVaR / expected shortfall, max drawdown, a pairwise correlation matrix, sector exposure and four stress scenarios. The stress set is 2008 GFC at -37%, 2020 COVID at -34%, a +2% rate shock and a generic -10% drawdown, applied to the actual position weights rather than to a proxy index. Sector mapping is a hardcoded dictionary across Technology, Financials, Energy, Healthcare, Consumer Staples, Commodities, Broad Market, Fixed Income and Other, which is honest about being a lookup table rather than pretending to be a classification service. Market data comes from yfinance behind a 7-day in-memory cache so the UI does not hammer the API on every request. The risk math lives in app/risk.py with no I/O at all, which is why the tests can check VaR percentiles, the CVaR <= VaR invariant, known drawdown cases, correlation identity, NAV, sector weights summing to 1 and the stress scenarios on synthetic returns.



- Historical VaR and parametric VaR disagree most exactly when it matters, in fat-tailed periods, so reporting both and letting the gap be visible is more useful than picking one and calling it the number.
- CVaR is the metric to size against because it is subadditive and answers the question VaR dodges: given that we are past the threshold, how bad is it.
- Keeping the risk math in a pure module with no I/O is what makes the whole dashboard testable; the moment a VaR function calls yfinance, the test suite needs the network and stops being run.
Scale 0–100: how much this project relied on each skill.