Linux | Codecov |
---|---|
Utilities for economic capital assignments for a loan portfolio
This library has a relatively opinionated API for creating a portfolio of loans and performing aggregate statistics (such as loan level risk contributions and expected values).
Install
Add the following to your Cargo.toml:
loan_ec = "0.1.4"
Use
A full example is in the credit_faas_demo.
Create instances of the Loan struct:
extern crate loan_ec;
//crate is needed for computing the complex domain
extern crate fang_oost;
let loan= Loan;
Then add to the portfolio:
//the higher this number, the more accurate the numerical approximation, but the slower it will run
let num_u:usize=256;
//the truncation of the distribution for numerical purposes
let x_min=-100000.0;
let x_max=0.0;//the maximum of the distribution
let mut ec= new;
let u_domain:= get_u_domain.collect;
//the characteristic function for the random variable for LGD...in this case, degenerate (a constant)
let lgd_fn=;
//cf enhancement for ec
let liquid_fn= get_liquidity_risk_fn;
let log_lpm_cf= get_log_lpm_cf;
ec.process_loan;
//keep adding until there are no more loans left...
Retrieve the (discretized) characteristic function for the portfolio:
//variance of macro variables
let variance=vec!; //must have same length as the weight vector
//in this example, macro variables are Gamma distributed
let v_mgf=;
let final_cf:=ec.get_full_cf;
Using the characteristic function, obtain any number of metrics including expected shortfall and value at risk (from my cf_dist_utils repository).
let quantile=0.01;
let = get_expected_shortfall_and_value_at_risk_discrete_cf.unwrap;