mfe.distributions¶
mfe.distributions ¶
mfe.distributions — Fat-tailed and multivariate distributions.
skewt_logpdf Hansen (1994) Skew-t log-PDF with analytic score skewt_ppf Skew-t quantile function (VaR/ES) ged_logpdf Generalized Error Distribution log-PDF ged_ppf GED quantile function mvnorm_loglik Multivariate normal log-likelihood (time-varying Sigma_t) mahalanobis Mahalanobis distances under a covariance sequence standardize_mvn Extract standardized multivariate residuals
skewt_logpdf ¶
Log-PDF of Hansen's Skew-t distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
FloatArray
|
|
required |
nu
|
float
|
|
required |
lam
|
skewness(-1, 1)
|
|
required |
Source code in src/mfe/distributions/skewt.py
skewt_score ¶
Analytic score of log-skewt PDF with respect to (nu, lam).
Returns (d_log_f / d_nu, d_log_f / d_lam), each (T,).
These are used in the outer MLE loop over distribution parameters, avoiding the finite-difference approach from the MATLAB source.
Source code in src/mfe/distributions/skewt.py
skewt_ppf ¶
Quantile function (inverse CDF) of Hansen's Skew-t. Used for VaR/ES computation.
Source code in src/mfe/distributions/skewt.py
ged_logpdf ¶
Log-PDF of the GED with zero mean and unit variance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
FloatArray
|
|
required |
nu
|
shape parameter (nu > 0); nu=2 is Normal
|
|
required |
Source code in src/mfe/distributions/ged.py
ged_ppf ¶
Quantile function of the GED(nu). Uses the relationship to the gamma distribution.
Source code in src/mfe/distributions/ged.py
ged_score ¶
Analytic score d_log_f / d_nu for GED.
Used in MLE to estimate nu. The MATLAB toolbox uses finite differences.
Source code in src/mfe/distributions/ged.py
mvnorm_loglik ¶
Gaussian multivariate log-likelihood for a time-varying covariance sequence.
L = sum_t [ -K/2 * log(2pi) - 0.5 * log|Sigma_t| - 0.5 * x_t' Sigma_t^{-1} x_t ]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FloatArray
|
|
required |
sigma_t
|
(T, K, K) or (K, K) conditional covariance matrices
|
|
required |
Returns:
| Type | Description |
|---|---|
float — total log-likelihood
|
|
Source code in src/mfe/distributions/mvnorm.py
mvnorm_loglik_t ¶
Single-observation Gaussian log-likelihood.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_t
|
(K,) single observation
|
|
required |
sigma
|
FloatArray
|
|
required |
Returns:
| Type | Description |
|---|---|
float — log-likelihood of this observation
|
|
Source code in src/mfe/distributions/mvnorm.py
mahalanobis ¶
Mahalanobis distances from the conditional mean.
d_t = sqrt( x_t' Sigma_t^{-1} x_t )
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FloatArray
|
|
required |
sigma_t
|
(T, K, K) or (K, K)
|
|
required |
Returns:
| Type | Description |
|---|---|
(T,) array of Mahalanobis distances
|
|
Source code in src/mfe/distributions/mvnorm.py
standardize_mvn ¶
Extract standardized residuals: z_t = L_t^{-1} x_t where L_t L_t' = Sigma_t.
Useful for diagnostic checking: if the model is correct, z_t should be approximately i.i.d. N(0, I_K).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FloatArray
|
|
required |
sigma_t
|
(T, K, K) conditional covariance matrices
|
|
required |
Returns:
| Type | Description |
|---|---|
(T, K) standardized residuals
|
|
Source code in src/mfe/distributions/mvnorm.py
ged ¶
Generalized Error Distribution (GED / Power-Exponential).
Nelson, D.B. (1991): "Conditional Heteroskedasticity in Asset Returns: A New Approach", Econometrica.
PDF: f(x; nu) = nu / (2 * lambda * Gamma(1/nu)) * exp(-0.5 * |x/lambda|^nu) where lambda = (2^{-2/nu} * Gamma(1/nu) / Gamma(3/nu))^{1/2}
Special cases: nu = 1: Laplace (double exponential) nu = 2: Normal nu -> inf: Uniform
ged_logpdf ¶
Log-PDF of the GED with zero mean and unit variance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
FloatArray
|
|
required |
nu
|
shape parameter (nu > 0); nu=2 is Normal
|
|
required |
Source code in src/mfe/distributions/ged.py
ged_ppf ¶
Quantile function of the GED(nu). Uses the relationship to the gamma distribution.
Source code in src/mfe/distributions/ged.py
ged_score ¶
Analytic score d_log_f / d_nu for GED.
Used in MLE to estimate nu. The MATLAB toolbox uses finite differences.
Source code in src/mfe/distributions/ged.py
mvnorm ¶
Multivariate normal log-likelihood and related utilities.
MFE MATLAB mvnormloglik.m equivalent. Used internally in multivariate GARCH estimation but exposed here as a clean public function because it comes up constantly in empirical work.
Also provides: - mvnorm_loglik — exact Gaussian log-likelihood for a given Sigma_t sequence - mvnorm_qmle — QMLE with a fixed Sigma_t from any multivariate model - standardize_mvn — extract Mahalanobis residuals from (T, K, K) covariances
mvnorm_loglik ¶
Gaussian multivariate log-likelihood for a time-varying covariance sequence.
L = sum_t [ -K/2 * log(2pi) - 0.5 * log|Sigma_t| - 0.5 * x_t' Sigma_t^{-1} x_t ]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FloatArray
|
|
required |
sigma_t
|
(T, K, K) or (K, K) conditional covariance matrices
|
|
required |
Returns:
| Type | Description |
|---|---|
float — total log-likelihood
|
|
Source code in src/mfe/distributions/mvnorm.py
mvnorm_loglik_t ¶
Single-observation Gaussian log-likelihood.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_t
|
(K,) single observation
|
|
required |
sigma
|
FloatArray
|
|
required |
Returns:
| Type | Description |
|---|---|
float — log-likelihood of this observation
|
|
Source code in src/mfe/distributions/mvnorm.py
mahalanobis ¶
Mahalanobis distances from the conditional mean.
d_t = sqrt( x_t' Sigma_t^{-1} x_t )
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FloatArray
|
|
required |
sigma_t
|
(T, K, K) or (K, K)
|
|
required |
Returns:
| Type | Description |
|---|---|
(T,) array of Mahalanobis distances
|
|
Source code in src/mfe/distributions/mvnorm.py
standardize_mvn ¶
Extract standardized residuals: z_t = L_t^{-1} x_t where L_t L_t' = Sigma_t.
Useful for diagnostic checking: if the model is correct, z_t should be approximately i.i.d. N(0, I_K).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FloatArray
|
|
required |
sigma_t
|
(T, K, K) conditional covariance matrices
|
|
required |
Returns:
| Type | Description |
|---|---|
(T, K) standardized residuals
|
|
Source code in src/mfe/distributions/mvnorm.py
skewt ¶
Hansen's Skewed Student-t distribution (Hansen 1994).
Hansen, B.E. (1994): "Autoregressive Conditional Density Estimation", International Economic Review, 35(3), 705-730.
Parameters: nu : degrees of freedom (nu > 2) lam : skewness parameter (-1 < lam < 1)
PDF: f(x; nu, lam) = bc * (1 + 1/(nu-2) * ((bx+a)/(1+/-lam))^2)^{-(nu+1)/2}
with sign depending on whether x < -a/b or x >= -a/b.
The MATLAB mfe-toolbox computes gradients numerically. We provide analytic score functions for faster GARCH estimation.
skewt_logpdf ¶
Log-PDF of Hansen's Skew-t distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
FloatArray
|
|
required |
nu
|
float
|
|
required |
lam
|
skewness(-1, 1)
|
|
required |
Source code in src/mfe/distributions/skewt.py
skewt_score ¶
Analytic score of log-skewt PDF with respect to (nu, lam).
Returns (d_log_f / d_nu, d_log_f / d_lam), each (T,).
These are used in the outer MLE loop over distribution parameters, avoiding the finite-difference approach from the MATLAB source.
Source code in src/mfe/distributions/skewt.py
skewt_ppf ¶
Quantile function (inverse CDF) of Hansen's Skew-t. Used for VaR/ES computation.