| Crates.io | credit_portfolio_model |
| lib.rs | credit_portfolio_model |
| version | 0.1.1 |
| created_at | 2025-03-28 19:08:50.514332+00 |
| updated_at | 2025-04-03 20:36:19.485306+00 |
| description | Simulation of factor model to calculate loss distribution of a credit portfolio |
| homepage | |
| repository | https://github.com/zoonders/credit_portfolio_model |
| max_upload_size | |
| id | 1610008 |
| size | 63,419 |
A rust implementaiton of a credit portfolio model.
This is an early implementation of a credit portfolio model that simulates correlated rating migrations in a portfolio. The correlation structure is based on a Merton-type factor model. Rating migrations are based on the asset value $z$ exceeding a certain threshold.
z>c
The random variable z is standard normally distributed. Hence, the thresholds are calculated from pre-defined migration or default probabilities
using the cumulative normal distribution. The asset value $z$ itself is a linear combination of multiple standard normal random variables
z=\sqrt{r^2}\cdot y+\sqrt{1-r^2}\cdot\left(\sqrt{1-\epsilon}\cdot e_1 + \sqrt{\epsilon}\cdot e_2\right)
Here, the variables are defined as follows:
e_1$ is the idiosyncratic risk variable only corresponding to the borrowere_2$ is the idiosyncratic risk variable of the risk group that the borrower belongs to, e.g. linked to other companies through ownershipy$ is the systematic risk, which is defined as a linear combination of the vector $x$ which is distributed according to a multivariate
normal distribution with covariance matrix $\Sigma$. Besides, the borrower dependency to the risk drives is specified by weights $\phi$.
The resulting random variable is then defined as $y=\frac{\phi\cdot x}{\sqrt{\phi^T\cdot\Sigma\cdot\phi}}$.r^2$ and $\epsilon$ specifiy the correlation of the borrowers asset value to the systematic component or the risk group.The following features are implemented:
Features that could be implemented, but are not at the moment
Install the package via
cargo install credit_portfolio_model
The crate comes with a binary that reads csv-data with the portfolio information and outputs the loss-distribution. Besides, Mean and quantile information of the loss distribution is provided on stdout.
credit_portfolio_model --input /path/to/read/input/csv/files/from --output /path/to/store/output/csv --num-trials NUMBERTRIALS --chunk-size TRIALSPERTHREAD
The input consists of six files. The files are
correlation_matrix.csv
risk_factor_1, risk_factor_2 - Number index of column and row, respectively. Starts with 0 and must be continuouscorrelation - Correlation value. Note that the matrix needs to be symmetric and positive semi-definiteborrower.csv
borrower_id - Unique identifier of Borrower (string-like) that is used to map with other filesrisk_group - Unique identifier of Risk Group (string-like). Risk Groups share one of the idiosyncratic risk driversrating - Current rating, given as index to a vector, i.e. starting at 0 and continuous.
The last rating class is considered default, although the current implementation does no special treatment of defaultsr2 - Correlation to the systematic risk factor, i.e. $\rho$.eps - Correlation to the risk group, i.e. $\epsilon$.risk_factors.csv
borrower_id - See borrower, must match the other filerisk_factor - Mapping to risk factor of correlation factorweight - Borrower dependency to the risk factor (relative to the other risk factors)transition_probabilities.csv
borrower_id - See borrower, must match the other filerating - Resulting rating classprobabiliy - Probability to migrate into this class, must sum to 100%.exposure.csv
exposure_id - Unique identifier of Exposure (string-like) that is used to map with other filesborrower_id - See borrower, must match the other fileoutstanding - Current outstanding, not used at the momentvaluations.csv
exposure_id - See exposure, must match the other filerating - Resulting rating classvaluation - Valuation of the exposure given the rating class.Full API documentation is available on docs.rs.
This project is licensed under the MIT License - see the LICENSE file for details.