Skip to main content

Estimate asset correlation from historical default data under the Vasicek credit-portfolio model.

Project description

pyAssetCorr

Estimate asset correlation from historical default data under the Vasicek credit-portfolio model.

A clean-room Python implementation of the most-used functionality of the R package AssetCorr: method-of-moments and maximum-likelihood estimators for intra- and inter-cohort asset correlation, with standard errors, information criteria, likelihood-ratio tests, and tools for overlapping multi-year cohorts.

See docs/USER_GUIDE.md for the full guide.

Why asset correlation?

In the Vasicek single-factor model an obligor's latent asset return is

A = sqrt(rho) * X + sqrt(1 - rho) * eps

with a systematic factor X shared across obligors and idiosyncratic eps. The obligor defaults when A falls below Phi^{-1}(PD). The asset correlation rho controls how strongly defaults cluster: it drives the tail of the portfolio loss distribution and hence economic and regulatory capital. pyAssetCorr estimates rho (and, for several cohorts, the inter-cohort coupling) from observed default-count time series.

Installation

pip install pyAssetCorr            # numpy + scipy only

From a checkout:

pip install -e ".[dev]"            # editable install with pytest

Requires Python >= 3.9. All computation is vectorized NumPy/SciPy — no compiled extensions or JIT needed. (An [accel] extra installs numba for an internal alternative kernel, but the built-in estimators run pure NumPy and do not use it, so it changes neither results nor speed.)

Quickstart

Data are two equal-length arrays: d = defaults per period, n = obligors per period.

import numpy as np
from pyassetcorr import intra_fmm, intra_mle, simulate_default_series

# Simulate a 10-year history with rho = 0.15, PD = 3%, 2000 obligors/year.
d, n = simulate_default_series(rho=0.15, pd=0.03, n=2000, T=10, seed=0)

# Method of moments (finite-sample corrected) with a confidence interval.
mom = intra_fmm(d, n, ci=True)
print(mom)                 # MomentResult(method='fmm', rho=..., se=..., ...)
print(mom.rho, mom.ci)

# Maximum likelihood, jointly estimating PD, with AIC/BIC and SE.
mle = intra_mle(d, n, pd="joint", ci=True)
print(mle.params["rho"], mle.params["pd"])
print(mle.aic, mle.bic, mle.se["rho"])

# The MLE integral is adaptive; pass `nodes` to check quadrature convergence,
# e.g. intra_mle(d, n, nodes=64). See the User Guide, "Checking quadrature
# convergence".

Several cohorts at once

from pyassetcorr import multi_cohort_mle, lr_test, multi_cohort_single_factor

# d, n are now (T x K): T periods, K cohorts.
fit = multi_cohort_mle(d_mat, n_mat)          # per-cohort rho + free gamma
print(fit.params["rho"], fit.params["gamma"])
print(fit.inter_corr)                          # inter-cohort asset-corr matrix

# Is a single common factor (gamma = 1) enough?
restricted = multi_cohort_single_factor(d_mat, n_mat)
print(lr_test(fit, restricted))                # likelihood-ratio test

The multi-cohort model nests cohorts under a single global factor Z plus per-cohort factors w_k, controlled by one coupling parameter gamma: intra-cohort correlation stays rho_k, inter-cohort correlation is gamma * sqrt(rho_i * rho_j). gamma = 1 is a single common factor, gamma = 0 independent cohorts.

Overlapping multi-year cohorts

Annual cohorts measured over an h-year horizon share calendar shocks, so the default series is autocorrelated and naive standard errors are too small. Use a HAC lag or non-overlapping subsample averaging:

from pyassetcorr import intra_fmm, group_average

intra_fmm(d, n, lag=h - 1)        # autocorrelation-robust (Frei-Wunsch) SE
group_average(d, n, horizon=h)    # average over non-overlapping subsamples

Estimators

Function Kind Description
intra_amm MoM Asymptotic method of moments (Gordy 2000)
intra_fmm MoM Finite-sample corrected method of moments
intra_jdp1 MoM Unbiased joint-default-probability matching (Lucas 1995)
intra_jdp2 MoM Biased JDP matching (literature parity)
intra_mle MLE Single-cohort Vasicek-Binomial MLE
multi_cohort_mle MLE Generalized multi-cohort MLE (nested two-level factor)

AssetCorr-style aliases (intraAMM, intraFMM, intraJDP1, intraJDP2, intraMLE) are provided for discoverability.

License

MIT. This is a clean-room implementation written from the published equations (see references below), not a translation of the GPL-3 R source, so it is free to use in both academic and commercial/financial settings.

References

  • Vasicek, O. (2002). The Distribution of Loan Portfolio Value. Risk.
  • Gordy, M. (2000). A comparative anatomy of credit risk models. J. Banking & Finance.
  • Lucas, D. (1995). Default correlation and credit analysis. J. Fixed Income.
  • Gordy, M. & Heitfield, E. (2010). Small-sample estimation of models of portfolio credit risk.
  • Duellmann, K. & Gehde-Trapp, M. (2004). Probability of default estimation.
  • Bluhm, C. & Overbeck, L. (2003). Systematic risk in homogeneous credit portfolios.
  • Frei, C. & Wunsch, M. (2018). Moment Estimators for Autocorrelated Time Series and Default Correlations. J. Credit Risk.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyassetcorr-0.1.2.tar.gz (79.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyassetcorr-0.1.2-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file pyassetcorr-0.1.2.tar.gz.

File metadata

  • Download URL: pyassetcorr-0.1.2.tar.gz
  • Upload date:
  • Size: 79.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyassetcorr-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a1e92c59d196df8628d0bd695f413da95478e52317d3808f942bc5305a32c5a1
MD5 fab941c45f3999cc13a3bf9422ea0426
BLAKE2b-256 f146468378241bb9b7f6b1fff449d7f654e8a29e6b0611996d873a64b79acbef

See more details on using hashes here.

File details

Details for the file pyassetcorr-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyassetcorr-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyassetcorr-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9b3e8ff759d9c72265c6265dbd95f96c64d2550078e298bfc902856e456b0a46
MD5 00797d4435ff423bf8ce7f4107f3752a
BLAKE2b-256 9ec23edc7972d6bb4e8979dc87670146c1669cf54a0d4628f2db7f0a83ec82e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page