iamjeshurun.com
LinkedIn Résumé
Portfolio Risk Analytics demo opening on a labelled example portfolio, showing growth of one dollar above a baseline and the drawdown below it.

04 · Backend · Financial data

Portfolio Risk Analytics

Measures a stock portfolio’s historical return, volatility, drawdown and correlations, and returns an error instead of guessing when data is missing.

Opens on a precomputed, labelled example. Historical analysis only, not investment advice.

01Problem

Portfolio risk numbers are easy to compute wrongly. Forward-filled gaps, adjusted prices mixed from different fetches, and silent rebalancing assumptions all produce figures that look confident but are wrong.

02What I built

I built a FastAPI service with pure pandas analytics, a SQLite price cache, documented endpoints with a single error format, and a dependency-free dashboard with hand-built SVG charts.

Portfolio Risk Analytics demo example analysis: holdings form, summary measures and growth chart.
Portfolio Risk Analytics demo: drawdown chart, daily-return histogram and correlation table.

03Data flow

  1. Holdings + dates
  2. Validate (Pydantic)
  3. SQLite cache or Yahoo fetch
  4. Data-quality rules
  5. Pure analytics → JSON

04Decisions

Refuse to fill gaps

An interior gap returns MISSING_DATA instead of being dropped or forward-filled. Dropping the date would turn a multi-day move into one “daily” return.

Replace, don’t patch, the cache

A refresh replaces a symbol’s whole cached history, because adjusted closes change retroactively after splits and dividends.

05Validation

  • Offline tests use deterministic price fixtures and dependency overrides. One test pins buy-and-hold against daily rebalancing.
  • JavaScript tests check that the page’s own calculations reproduce the API’s volatility and drawdown dates.

06Limits

There is no trading calendar, so a date missing for every asset looks like a holiday. Yahoo Finance is unofficial and can rate-limit requests. Annualizing with √252 is an approximation.

Precomputed example40% AAPL, 35% MSFT, 25% GOOG, 2023–2025. An illustration, not my own returns.
Live resultLabelled with fetch and calculation time. Errors never fall back to stale numbers.

07Links

Next projectInsightPulse