Skip to main content

risk.shapley()

The Shapley value of the game whose cost is cost of each

Usage

risk.shapley(
    pd,
    cost,
)

sub-portfolio, for any cost function, not only a distortion: a standard deviation premium, a variance, an expected utility.

cost is called with a list of the sub-portfolio’s total in each simulation, in simulation order, once for each of the 2**m - 1 non-empty sub-portfolios (the empty one costs 0), and returns a float.

Parameters

pd: PredictiveDistribution

Components that add up to the portfolio; at most 12.

cost: callable
cost(draws: list[float]) -> float.

Returns

Allocation
total is cost of the whole portfolio, standalone that of each component, allocated the Shapley values, summing to total; method is "shapley".

Raises

ValueError
For more than 12 components or a cost that is not finite.

Examples

>>> import statistics
>>> from prospicio.distributions import PredictiveDistribution
>>> from prospicio.risk import shapley
>>> pd = PredictiveDistribution(["lob"], [("motor",), ("property",)],
...                             [[1.0, 2.0], [4.0, 1.0], [2.0, 5.0], [3.0, 6.0]])
>>> a = shapley(pd, lambda x: statistics.fmean(x) + statistics.pstdev(x))
>>> round(sum(a.allocated) - a.total, 12)

0.0