We present a semi-structural model of default risk, which is a function of loan and borrower characteristics, economic conditions, and the regulatory environment. We use this model to simulate bank credit losses for stress-testing purposes and to calibrate borrower-based macroprudential tools. The proposed approach is very flexible and is particularly useful when there is limited history of crisis episodes, when crises bring unanticipated shocks where past tail events offer little guidance and when structural shocks or changes in financial regulations have altered the loan default process. We apply the model to quantify mortgage lending risk in two distinct mortgage markets. For each application, we show a range of modeling adjustments that can be made to capture country-specific institutional features. The model uses bank portfolio data broken down by risk bucket and vintage, which enables us to take explicit account of the loan life cycle and to incorporate the housing and economic cycles. This feature facilitates a timely assessment of banks’ loss-absorbing capacity and the buildup of systemic risk conditional on policy. It also enables counterfactual analysis and the evaluation of macroprudential policy interventions.