The stress test page had several confusing aspects:
-
Misleading UI: The page showed "Multi-Factor" scenarios with different shocks for bonds, commodities, credit spreads, etc., but the backend was only applying a single uniform shock to everything.
-
Confusing Date Range: A date range picker was shown but completely unused - stress tests apply hypothetical shocks, not historical analysis.
-
No Explanations: Users had no clear understanding of:
- How stress tests actually work
- What the calculations mean
- Why results look the way they do
-
Unclear Sensitivity Analysis: The sensitivity chart had no explanation that it's just a linear approximation.
-
Historical Scenarios Misconception: Users might think "COVID Crash" replays actual March 2020 data, when it just applies a -34% shock uniformly.
-
Asset-Type Specific Shocks for Multi-Factor Scenarios
# Now multi-factor scenarios properly apply different shocks by asset type MULTI_FACTOR_SCENARIOS = { "STAGFLATION": { "equity_shock": -0.15, "bond_shock": -0.10, "commodity_shock": 0.20, ... } }
-
Asset Type Mapping
- Added
ASSET_TYPE_MAPPINGto classify common symbols (TLT=bond, GLD=commodity, etc.) - Added
_get_asset_type()function to determine asset type - Added
_get_shock_for_asset()to apply appropriate shock based on asset type
- Added
-
Better Documentation
- Extensive docstrings explaining exactly how the calculations work
- Clear notes that this is a simplified linear model
- Examples showing the math:
weight Γ shock = P&L
-
Added Prominent Info Banner
- Explains how stress tests work in plain English
- Shows the calculation formula clearly
- Clarifies what multi-factor and historical scenarios actually do
-
Removed Confusing Date Range Picker
- Date range is not used in stress tests (only for API consistency)
- Removed UI element to avoid confusion
-
Enhanced Scenario Descriptions
- Each scenario type now has clear explanatory text
- Multi-factor scenarios show which assets get which shocks
- Historical scenarios clarify they're approximations, not replays
-
Added Results Explanation Banner
- Shows the calculation formula with an example
- Appears right above results to help users understand what they're seeing
-
Improved Sensitivity Analysis
- Added explanation that it's a linear approximation
- Better comments in the code explaining the calculation
-
Backend README (
backend/README.md)- Added "How Stress Tests Work" section
- Listed all scenario types with clear descriptions
- Added example response with explanation
- Clear notes about limitations
-
API Route Documentation (
backend/app/api/routes_stress.py)- Extensive Swagger/OpenAPI documentation
- Step-by-step explanation of how calculations work
- Complete list of all supported scenarios
- Clear notes about what the model does and doesn't do
For each asset in your portfolio:
P&L Impact = Asset Weight Γ Shock
For the entire portfolio:
Portfolio P&L = Sum of all asset P&L impacts
Portfolio:
- AAPL: 40% weight
- TLT: 60% weight
Scenario: EQUITY_-10 (uniform -10% shock)
Calculation:
- AAPL impact: 0.40 Γ -0.10 = -0.04 (-4%)
- TLT impact: 0.60 Γ -0.10 = -0.06 (-6%)
- Total Portfolio P&L: -0.10 (-10%)
Scenario: STAGFLATION
- Stocks: -15% shock
- Bonds: -10% shock
- Commodities: +20% shock
Portfolio:
- AAPL (stock): 40% β 0.40 Γ -0.15 = -0.06
- TLT (bond): 40% β 0.40 Γ -0.10 = -0.04
- GLD (commodity): 20% β 0.20 Γ 0.20 = +0.04
- Total Portfolio P&L: -0.06 (-6%)
- Linear Model: Assumes P&L is directly proportional to shock magnitude
- No Historical Data: Doesn't use actual price movements or correlations
- No Rebalancing: Assumes static portfolio weights
- Simplified Classification: Asset types determined by symbol mapping
- No Dynamic Effects: Doesn't model volatility spikes, liquidity effects, etc.
-
Start the backend:
cd backend uvicorn app.main:app --reload --port 8000 -
Test the API directly:
curl -X POST "http://localhost:8000/api/stress/run" \ -H "Content-Type: application/json" \ -d '{ "portfolio": [ {"symbol": "AAPL", "weight": 0.4, "asset_type": "stock"}, {"symbol": "TLT", "weight": 0.4, "asset_type": "bond"}, {"symbol": "GLD", "weight": 0.2, "asset_type": "commodity"} ], "start": "2023-01-01", "end": "2024-12-01", "scenario": "STAGFLATION" }'
-
Check the Swagger docs: Visit: http://localhost:8000/docs Navigate to
/api/stress/runto see the new documentation -
Test the frontend:
- Navigate to the Stress Tests page
- Notice the new info banners explaining how it works
- Try different scenario types and see the appropriate shocks applied
- Check that multi-factor scenarios now properly differentiate between asset types
The stress test page now:
- β Clearly explains what stress tests are and how they work
- β Properly implements multi-factor scenarios with asset-specific shocks
- β Removes confusing/unused UI elements (date range)
- β Provides helpful context throughout the user experience
- β Sets correct expectations about limitations
- β Has comprehensive documentation for developers and users