Finance#
The normix.finance subpackage turns a fitted mixture into portfolio analytics.
Because a normal variance-mean mixture is conditionally Gaussian given the latent
\(Y\), portfolio quantities — and crucially their gradients and Hessians — are
computable by a fast conditional Monte Carlo over \(Y\) alone.
Portfolio projection#
Any linear combination \(w^\top X\) of a mixture’s assets is again a univariate member of the same family, with parameters available in closed form. No re-fitting is needed:
proj = model.project(w) # a Univariate* distribution of wᵀX
proj.mean(); proj.std()
proj.ppf(0.05) # 5% quantile (a VaR level)
This makes it cheap to evaluate many candidate weightings against one fitted model. See A multivariate stock basket.
Tail risk: VaR and CVaR#
CVaR(alpha) computes Value-at-Risk and Conditional Value-at-Risk at tail
probability alpha:
from normix.finance import CVaR
cvar = CVaR(0.05) # 5% tail probability
Y = proj.subordinator().rvs(100_000, seed=0) # conditional-MC draws
var_95 = cvar.var(proj) # deterministic quantile
cvar_95 = cvar.value(proj, Y) # conditional Monte Carlo over Y
Conditioning on \(Y\) makes the estimator far lower-variance than sampling returns directly.
Differentiable risk#
The payoff for the exponential-family structure is analytic risk sensitivities, in both the projected scalar parametrization and the portfolio weights:
cvar.gradient_scalar(proj, Y) # ∂CVaR/∂(μ̃, γ̃, σ̃)
cvar.hessian_scalar(proj, Y) # 3×3 Hessian
cvar.gradient_w(model, w, Y) # ∇_w CVaR (chain rule through the projection)
cvar.hessian_w(model, w, Y) # weight-space Hessian
These match finite differences to machine precision and plug straight into
gradient- or Newton-based portfolio optimizers. The WeightFunctional helper
bundles a risk measure, model, and Y into a callable with .grad and .hess.
See Portfolio CVaR and its derivatives for verification and a
worked CVaR-reduction loop.
Mean-risk optimization#
MeanRiskProblem solves the mean-risk problem
\(\min_w \rho(w^\top X)\) s.t. \(w^\top e = 1,\, E[w^\top X] \ge m\) by exploiting
the normal-mixture reduction to two coordinates
\((\tilde\mu, \tilde\gamma) = (w^\top\mu, w^\top\gamma)\):
from normix.finance import MeanRiskProblem, CVaR
prob = MeanRiskProblem(model, CVaR(0.05))
Y = model.joint.subordinator().rvs(20_000, seed=0)
prob.weights(mu_t, gamma_t) # min-dispersion weights for a target (μ̃, γ̃)
prob.min_variance_point() # reduced coords of the global min-variance portfolio
surface = prob.efficient_surface(mu_grid, gamma_grid, Y) # CVaR over a (μ̃, γ̃) grid
frontier = prob.efficient_frontier(targets, Y, gamma_bounds=(lo, hi)) # min risk per return
frontier.weights # realised portfolio weights along the frontier
The efficient_surface is the convex surface of Shi2016
(Fig. 8); the efficient_frontier is the classical risk–return frontier of
Fig. 9. See Mean-risk optimization and the efficient surface for a worked
replication across all four mixture families.
Transaction costs#
An \(\ell_1\) turnover penalty breaks the two-dimensional reduction, so rebalancing with costs uses a local quadratic program at the current portfolio \(w_0\):
import jax.numpy as jnp
from normix.finance import TransactionCostProblem, CVaR
tc = TransactionCostProblem(model, CVaR(0.05), c1=5.0, c2=5e-2)
Y = model.joint.subordinator().rvs(15_000, seed=0)
A = -jnp.eye(model.d) # optional long-only
result = tc.solve(w0, Y, A=A, b=jnp.zeros(model.d))
result.weights # w* (or w0 if the approx. gain is ≤ 0)
result.turnover # ‖w* − w0‖₁
result.qp.m_tilde, result.qp.H_tilde # theory matrices for an external QP
The risk measure is unchanged — only gradient_w / hessian_w at \(w_0\) enter
the QP. See Transaction costs and local-quadratic rebalancing.
Scaling to many assets#
At portfolio scale the factor mixtures replace a dense covariance with \(\Sigma = F F^\top + \operatorname{diag}(D)\), cutting covariance parameters from \(O(d^2)\) to \(O(d r)\) and routing every solve through the Woodbury identity. The GH tail behaviour is retained. See Factor mixtures for a Dow Jones 30 portfolio.
Further reading#
The mathematical background — CVaR derivatives, mean–risk optimization, transaction costs, and factor analysis — is developed in the theory notes.