Loss distributions and event capacities
The risk module represents a finite empirical loss distribution as a loss vector plus an event capacity on the same scenario set.
ProbabilityCapacity
import numpy as np
from capacities_ml_fin.risk import ProbabilityCapacity
capacity = ProbabilityCapacity(
weights=np.array([0.1, 0.2, 0.3, 0.4])
)
Weights are normalized by the constructor. For a Boolean event mask \(A\),
Because it implements BaseCapacity, it can be passed directly to generic Choquet and validation utilities.
DistortedCapacity
from capacities_ml_fin.risk import (
DistortedCapacity,
ExpectedShortfallDistortion,
)
risk_capacity = DistortedCapacity(
capacity,
ExpectedShortfallDistortion(alpha=0.95),
)
For any event \(A\):
No assumption of additivity is imposed on the base capacity. This means the same distortion class can be applied to a probability capacity or to an ambiguity capacity.
Probability envelopes
Upper envelope
For priors \(P_1,\ldots,P_m\) represented by rows of scenario weights:
from capacities_ml_fin.risk import UpperEnvelopeCapacity
upper = UpperEnvelopeCapacity(
prior_weights=np.array(
[
[0.25, 0.25, 0.25, 0.25],
[0.10, 0.20, 0.30, 0.40],
]
)
)
Each prior row is normalized independently.
Lower envelope
from capacities_ml_fin.risk import LowerEnvelopeCapacity
lower = LowerEnvelopeCapacity(prior_weights=priors)
implements
These capacities provide a simple finite representation of model ambiguity.
EmpiricalLossDistribution
from capacities_ml_fin.risk import EmpiricalLossDistribution
sample = EmpiricalLossDistribution(losses)
If neither sample_weight nor capacity is provided, equal scenario weights are used.
Weighted empirical probability:
Non-additive event capacity:
Use either sample_weight or capacity, not both.
Survival and generalized distribution
The survival function is evaluated as
The generalized distribution is
This definition is important for non-additive capacities: the implementation does not replace it by a potentially different expression involving \(\mu(L\le x)\).
Lower and upper quantiles
The implemented definitions are
and
In a finite empirical distribution they may differ at jumps, which is why the API exposes both explicitly.
Event probabilities
Any Boolean scenario event can be queried directly:
The result is additive only if the underlying capacity is additive.
Validation with generic capacity tools
Because risk capacities implement BaseCapacity, generic validation can be reused for small finite scenario sets:
from capacities_ml_fin.base.capacities import (
validate_capacity,
is_concave_capacity,
)
validate_capacity(risk_capacity, max_elements=8)
is_concave_capacity(risk_capacity, max_elements=8)
For realistic historical samples with hundreds of scenarios, exhaustive \(2^n\) validation is not computationally appropriate; validate the mathematical construction or smaller representative instances instead.