This repository is the scenario and stress-testing layer in the commercial credit-risk stack. It uses upstream PD, LGD, EAD, and expected loss style inputs together with defined downturn scenarios to produce stressed facility, segment, and portfolio loss views. The outputs are designed to support downstream pricing, monitoring, capital analysis, and lending strategy review in a clear portfolio-project format.
This project demonstrates how a commercial lending portfolio can be stress tested once the core risk component outputs already exist. It is structured as a recruiter-friendly workflow with transparent scenario assumptions, reproducible code, and reporting outputs that are easy to interpret across both institutional portfolio review and non-bank portfolio management.
Upstream inputs:
industry-analysisPD-and-scorecard-commercialLGD-commercialEAD-CCF-commercialexpected-loss-engine-commercial
Downstream consumers:
RAROC-pricing-and-return-hurdleportfolio-monitor-commercialRWA-capital-commercial
This project can be applied in:
- Portfolio stress testing for downturn review, risk appetite discussion, and capital-style analysis
- Segment and product stress views for structured portfolio risk assessment
- Scenario overlays for management packs and stress-based monitoring
- Approval strategy and pricing review under adverse scenarios
- Portfolio performance stress views by cohort, segment, or product
- Early risk planning for funding, collections, and growth decisions under downside assumptions
data/raw/demo_upstream_risk_inputs.csv: sample facility-level upstream risk dataset with PD, LGD, EAD, expected loss, collateral, industry, and maturity fields.data/external/stress_scenarios.csv: reusable scenario table covering Base, Mild downturn, and Severe downturn assumptions.
outputs/tables/stress_scenario_results.csvoutputs/tables/pd_stress_uplift.csvoutputs/tables/lgd_stress_uplift.csvoutputs/tables/ead_stress_uplift.csvoutputs/tables/stress_loss_dashboard_inputs.csvoutputs/tables/stressed_expected_loss_by_facility.csvoutputs/tables/stressed_expected_loss_by_segment.csvoutputs/tables/portfolio_stress_summary.csvoutputs/tables/validation_report.csv
outputs/tables/portfolio_stress_summary.csv: portfolio-level comparison of base versus stressed EAD and expected loss by scenario.outputs/tables/stressed_expected_loss_by_segment.csv: segment view showing which borrower groups absorb the largest downturn uplift.outputs/tables/stress_loss_dashboard_inputs.csv: reporting-ready table for charting scenario results in dashboards or presentation packs.outputs/reports/stress_testing_run_summary.md: run summary with validation checks and generated file references.outputs/charts/portfolio_stressed_el_by_scenario.png: chart showing expected loss movement across scenarios.outputs/charts/segment_stressed_el_severe_downturn.png: chart highlighting segment concentrations in the severe scenario.outputs/samples/sample_portfolio_stress_summary.csv: lightweight sample for quick review without rerunning the pipeline.
- Load the facility-level upstream demo dataset and scenario table.
- Validate required fields, duplicate structure, and scenario definitions.
- Apply scenario multipliers to PD, LGD, EAD, collateral values, and recovery timing.
- Recalculate stressed expected loss for each facility under each scenario.
- Aggregate results to facility, segment, and portfolio outputs.
- Write tables, charts, sample outputs, and a validation summary to
outputs/.
A portfolio manager wants to understand how a severe downturn would affect commercial property, SME, and agribusiness exposures before repricing or capital review. This repo makes that easy to show: the reviewer can open portfolio_stress_summary.csv, trace the uplift into stressed_expected_loss_by_segment.csv, and see which segments drive the change.
RAROC-pricing-and-return-hurdle: usesoutputs/tables/portfolio_stress_summary.csvandoutputs/tables/stress_loss_dashboard_inputs.csvas “stress context” for pricing and hurdle discussion.portfolio-monitor-commercial: can reuseoutputs/tables/stress_loss_dashboard_inputs.csvas scenario inputs for monitoring packs and early-warning overlays.RWA-capital-commercial: can reuseoutputs/tables/portfolio_stress_summary.csvand facility/segment stress tables as the stress leg of capital reporting.
data/: raw, processed, and external stress scenario inputssrc/: reusable scenario, stress engine, validation, and reporting modulesscripts/: pipeline entry-point wrappersdocs/: methodology, assumptions, data dictionary, and validation notesnotebooks/: walkthrough notebooks for reviewer contextoutputs/: exported tables, charts, reports, and sample artifactstests/: validation and regression checks
Quick start:
pip install -r requirements.txt
python scripts/run_pipeline.pyAfter the run, start with:
outputs/reports/stress_testing_run_summary.mdoutputs/tables/portfolio_stress_summary.csvoutputs/charts/portfolio_stressed_el_by_scenario.png
Run validation tests:
python -m pytesttests/test_stress_pipeline.pychecks that demo inputs pass validation before the engine runs.- The test suite confirms scenario ordering, so Severe downturn produces higher expected loss than Mild downturn, and Mild downturn is above Base.
- Base scenario outputs are checked against upstream components to confirm that unstressed PD, LGD, and EAD are preserved.
- Facility-level stressed outputs are reconciled back to the portfolio summary, and the generated
outputs/tables/validation_report.csvrecords the same validation logic in a reviewer-friendly format.
- All data is synthetic and is provided for demonstration only.
- Scenario multipliers and overlays are illustrative rather than macro-model calibrated.
- The repo is intended to show workflow design and reporting quality, not to represent a live bank stress-testing framework.