This repository contains the source files for Credit Risk with R, a Quarto book by Dr. Martin Lozano. The book develops credit-risk models with reproducible R code, numerical examples, tables, and graphics.
Published site: https://mlozanoqf.github.io/tutorial_arf/
The current version focuses on:
- Logistic credit scoring, predicted PDs, cutoff rules, bad rates, ROC/AUC, calibration, and lending decisions
- Tree-based credit scoring with a single decision tree and XGBoost
- Structural credit risk with the Merton model, risk-neutral valuation, and model-implied default probabilities
- Credit spreads, corporate bond valuation, and CDS valuation in discrete time
- Portfolio credit risk with Gaussian copulas, t-copulas, correlated defaults, portfolio losses, Credit VaR, expected shortfall, and economic capital
index.qmd: preface, publication metadata, and edition notes01-logistic.qmd: logistic credit scoring02-tree-based.qmd: tree-based credit scoring02-merton.qmd: the Merton model04-credit-spreads-cds.qmd: credit spreads and CDS valuation03-gaussian-copula.qmd: copula models for portfolio credit riskreferences.qmd: references
The book configuration lives in _quarto.yml.
R/: helper scripts for data preparation, model estimation, formatting, and chapter setuploan_data_*.rds: loan data used in the credit-scoring chapters_book/: generated HTML output created byquarto render.github/workflows/publish.yml: GitHub Actions workflow for rendering and deploying the book to GitHub Pagesstyles.cssand*.htmlpartials: custom layout, navigation, progress, and page behavior_extensions/quarto-ext/fontawesome/: local Quarto extension used for iconsreferences.bib: bibliography
Legacy .Rmd files and media assets are kept in the repository, but the active book build is driven by the .qmd files listed in _quarto.yml.
Install Quarto and R, then render the book from the repository root:
quarto renderFor interactive local preview:
quarto previewThe GitHub Actions workflow installs the R packages needed for deployment. For local rendering, the main package set is:
dplyrgmodelsggplot2knitrmnormtplotlypROCrmarkdownrayshaderscatterplot3dSim.DiffProctidyrvembedrviridisxgboost
Pushing to main triggers .github/workflows/publish.yml. The workflow:
- Checks out the repository.
- Installs Quarto.
- Installs R 4.5.2.
- Installs the required R packages.
- Runs
quarto render. - Uploads
_book/as a GitHub Pages artifact. - Deploys the artifact to GitHub Pages.
- Edit the source
.qmdfiles and helper scripts, not generated files in_book/. - Keep
_quarto.ymlsynchronized with chapter additions, removals, or renames. - If custom navigation changes, review
styles.cssand the HTML partials included in_quarto.yml. - If a chapter needs new R packages, update
.github/workflows/publish.ymlso GitHub Pages can render the book. - Do not commit large local reference PDFs unless they are intentionally part of the public repository.
This project is licensed under the GNU General Public License v3.0. See LICENSE.