Turn the repo into a validation-ready risk engine where:
- the engine is the source of truth (VaR/ES/EL),
- the backtesting module validates model behavior,
- the Streamlit app only displays outputs (no math in the UI).
This migration is intentionally minimal: move only what increases credibility for pensions / model validation / risk boutiques.
Move all functions that answer: "What is the risk number?"
- Historical VaR / ES logic
- Parametric (Normal) VaR / ES logic
- Monte Carlo VaR / ES logic
- Filtered Historical (GARCH-lite / FHS) VaR / ES logic
- Supporting utilities required by those methods (only if used by the above)
Rule: VaR and ES must be reported as positive loss numbers (single loss convention).
Move all functions that answer: "Did the model work?"
- Kupiec POF test
- Rolling backtest loop (build VaR series over time)
- Exception counting (losses > VaR)
- Backtest summary outputs (exceptions, expected, p-values)
Rule: The app should call backtest functions and display tables/plots—not implement backtesting itself.
These can remain in place while we stabilize the engine:
- Streamlit UI layout and charting (Plotly / Streamlit elements)
- Data loading (e.g., yfinance, CSV demos)
Rule: UI/plots may visualize VaR/ES, but must never recompute VaR/ES internally.
These reduce clarity and create "doing too much" signals.
- Duplicate VaR implementations with inconsistent conventions
- Any
abs()band-aids used to fix sign issues - Any risk calculations performed inside
app/app.py - Extra features not required for validation sandbox V1 (e.g., ERC weights, marginal VaR decomposition)
Rule: If it’s not part of "measure → validate → document", it moves to extras.py or is marked deprecated.
- One loss convention (losses positive)
- ES ≥ VaR (tested)
- 99% VaR ≥ 95% VaR (tested)
- Backtest returns exceptions, expected exceptions, Kupiec p-value
app/app.pycalls the engine; it does not compute risk
- portfolio_returns
- var_parametric
- es_parametric
- var_historical
- es_historical
- _cov_shrink
- var_es_monte_carlo
- garch11_filter
- garch11_forecast_sigma_next
- fhs_var_es_next
- kupiec_pof
- backtest_var_historical
- backtest_fhs_var
- (optional) backtest_var utility wrapper
- var_parametric_normal_parts
- incremental_var_normal
- erc_weights_from_cov
- erc_weights
- normalize_weights / _normalize_weights (keep one)