## risk.shapley()


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


Usage


``` python
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](risk.Allocation.md#prospicio.risk.Allocation.total) is `cost` of the whole portfolio, [standalone](risk.Allocation.md#prospicio.risk.Allocation.standalone) that of each component, [allocated](risk.Allocation.md#prospicio.risk.Allocation.allocated) the Shapley values, summing to [total](risk.Allocation.md#prospicio.risk.Allocation.total); [method](risk.Allocation.md#prospicio.risk.Allocation.method) is `"shapley"`.


## Raises


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


## Examples

``` python
>>> 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
