## pricing.Portfolio


A portfolio as the distribution of its total and each unit's


Usage

``` python
pricing.Portfolio()
```


conditional expectation given the total, `kappa_i(x) = E[X_i | X = x]`: the representation of Mildenhall and Major (*Pricing Insurance Risk*, 2022) and CAS Monograph 15, for pricing with limited liability and the natural allocation.


## Parameters


`units: list of str`  

`rows: list of list of float`  
Each scenario's loss by unit; non-negative.

`probs: list of float`  
The scenarios' probabilities; equal when omitted.


## Examples

``` python
>>> from prospicio.pricing import Portfolio
>>> from prospicio.risk import Distortion
>>> rows = [[15, 7, 0], [15, 13, 0], [5, 20, 11], [7, 33, 0], [13, 20, 7],
...         [5, 27, 8], [15, 16, 9], [26, 19, 10], [17, 8, 40], [16, 20, 64]]
>>> insco = Portfolio(["A", "B", "C"], rows)
>>> price = insco.price(Distortion.ccoc(0.15), assets=100)
>>> round(price.total.premium, 6)
```

53.565217

``` python
>>> [round(u.assets, 6) for u in price.allocated]
```

\[16.0, 20.0, 64.0\]


## Attributes

| Name | Description |
|----|----|
| [probs](#probs) | The probability of each total. |
| [totals](#totals) | The distinct totals, ascending. |
| [units](#units) | Unit names. |

------------------------------------------------------------------------


#### probs


The probability of each total.


`probs: list[float]`


------------------------------------------------------------------------


#### totals


The distinct totals, ascending.


`totals: list[float]`


------------------------------------------------------------------------


#### units


Unit names.


`units: list[str]`


## Methods

| Name | Description |
|----|----|
| [allocation_set()](#allocation_set) | The range of each unit's premium over the natural allocation set: |
| [assets()](#assets) | Assets at the capital standard [p](models.Elpd.md#prospicio.models.Elpd.p): the lower [p](models.Elpd.md#prospicio.models.Elpd.p) quantile of |
| [assets_for_epd()](#assets_for_epd) | The smallest assets whose total EPD ratio is at most [epd](pricing.Portfolio.md#prospicio.pricing.Portfolio.epd). |
| [bodoff()](#bodoff) | Bodoff's percentile layer of capital: each unit's share of the |
| [bodoff_price()](#bodoff_price) | Bodoff's percentile layer of capital priced by a distortion: each |
| [calibrate()](#calibrate) | The member of a distortion family that prices the loss capped at |
| [comonotonic_kappa()](#comonotonic_kappa) | Each unit's comonotonic allocation at each total, a non-decreasing |
| [epd()](#epd) | The expected policyholder deficit ratio with these assets: in |
| [expected()](#expected) | Each unit's expected loss. |
| [from_independent()](#from_independent) | From independent units, each a Grid with the same step; the total |
| [from_predictive()](#from_predictive) | From a joint simulation: each component is a unit, each simulation |
| [kappa()](#kappa) | A unit's conditional expectation at each total. |
| [premium_bounds()](#premium_bounds) | The range of each unit's premium over every distortion that prices |
| [price()](#price) | The premium of the loss capped at the assets, and its natural |
| [price_stand_alone()](#price_stand_alone) | Each unit priced as if it were the whole book, at its own lower |
| [priority()](#priority) | The priority ladder: each unit's recovery from the assets when it |
| [priority_kappa()](#priority_kappa) | Where in the total the shortfall `(X - a)+` falls when `unit` is |
| [tvar_threshold()](#tvar_threshold) | The level [t](distributions.Pareto.md#prospicio.distributions.Pareto.t) at which the total's TVaR reaches its VaR at [p](models.Elpd.md#prospicio.models.Elpd.p), |

------------------------------------------------------------------------


#### allocation_set()


The range of each unit's premium over the natural allocation set:


Usage

``` python
allocation_set(distortion, assets=None, p=None)
```


every order of the outcomes whose totals, capped at the assets, tie. The linear and lifted allocations lie in it. Needs a portfolio built from rows.


##### Parameters


`distortion: Distortion`  

`assets: float = None`  

`p: float = None`  


##### Returns


`list of dict`  
One per unit: `unit`, [lower](distributions.Grid.md#prospicio.distributions.Grid.lower), [upper](distributions.Custom.md#prospicio.distributions.Custom.upper).


##### Examples

*Pricing Insurance Risk*'s Example 259, where the total 10 is 9 + 1 or 10 + 0:

``` python
>>> from prospicio.pricing import Portfolio
>>> from prospicio.risk import Distortion
>>> rows = [[a, b] for a in (0, 9, 10) for b in (0, 1, 90)]
>>> probs = [p * q for p in (0.5, 0.25, 0.25) for q in (0.5, 0.25, 0.25)]
>>> port = Portfolio(["X1", "X2"], rows, probs)
>>> x1 = port.allocation_set(Distortion.proportional_hazard(0.5), assets=100)[0]
>>> round(x1["lower"], 4), round(x1["upper"], 4)
```

(6.2009, 6.2085)

------------------------------------------------------------------------


#### assets()


Assets at the capital standard [p](models.Elpd.md#prospicio.models.Elpd.p): the lower [p](models.Elpd.md#prospicio.models.Elpd.p) quantile of


Usage

``` python
assets(p)
```


the total.


##### Parameters


`p: float`  


##### Returns


`float`  


------------------------------------------------------------------------


#### assets_for_epd()


The smallest assets whose total EPD ratio is at most [epd](pricing.Portfolio.md#prospicio.pricing.Portfolio.epd).


Usage

``` python
assets_for_epd(epd)
```


##### Parameters


`epd: float`  


##### Returns


`float`  


------------------------------------------------------------------------


#### bodoff()


Bodoff's percentile layer of capital: each unit's share of the


Usage

``` python
bodoff(assets=None, p=None)
```


assets.


##### Parameters


`assets: float = None`  

`p: float = None`  


##### Returns


`list of float`  


------------------------------------------------------------------------


#### bodoff_price()


Bodoff's percentile layer of capital priced by a distortion: each


Usage

``` python
bodoff_price(distortion, assets=None, p=None)
```


layer of assets, its cost `g(S)` and its capital `1 - g(S)` are shared in Bodoff's proportions, so every layer earns its own return. The assets are [bodoff](pricing.Portfolio.md#prospicio.pricing.Portfolio.bodoff)'s, the losses the equal-priority recoveries, and the premiums add up to the price of the capped total.


##### Parameters


`distortion: Distortion`  

`assets: float = None`  

`p: float = None`  


##### Returns


`NaturalPrice`  


##### Examples

Bodoff's Thought Experiment 1 at a 10% return (*Pricing Insurance Risk*, Table 15.24):

``` python
>>> from prospicio.pricing import Portfolio
>>> from prospicio.risk import Distortion
>>> port = Portfolio(["Hu", "EQ"], [[0, 0], [99, 0], [0, 100], [99, 100]],
...                  [0.76, 0.19, 0.04, 0.01])
>>> plc = port.bodoff_price(Distortion.ccoc(0.1), assets=100)
>>> [round(u.premium, 4) for u in plc.allocated]
```

\[24.8729, 5.8635\]

------------------------------------------------------------------------


#### calibrate()


The member of a distortion family that prices the loss capped at


Usage

``` python
calibrate(
    family,
    assets=None,
    p=None,
    *,
    premium=None,
    return_on_capital=None,
    loss_ratio=None,
    r0=0.0
)
```


the assets at a target: give exactly one of [premium](pricing.Price.md#prospicio.pricing.Price.premium), [return_on_capital](pricing.Price.md#prospicio.pricing.Price.return_on_capital) and [loss_ratio](pricing.Price.md#prospicio.pricing.Price.loss_ratio).


##### Parameters


`family: str`  
As for [prospicio.risk.calibrate](risk.calibrate.md#prospicio.risk.calibrate).

`assets: float = None`  

`p: float = None`  

`premium: float = None`  

`return_on_capital: float = None`  

`loss_ratio: float = None`  

`r0: float = ``0.0`  


##### Returns


`Distortion`  


------------------------------------------------------------------------


#### comonotonic_kappa()


Each unit's comonotonic allocation at each total, a non-decreasing


Usage

``` python
comonotonic_kappa()
```


function of the total that still adds up to it: Denuit et al.'s (2025) improvement of [kappa](pricing.Portfolio.md#prospicio.pricing.Portfolio.kappa), [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `make_comonotonic_allocations`.


##### Returns


`dict of str to list of float`  
Unit name to its allocation at each of [totals()](pricing.Portfolio.md#prospicio.pricing.Portfolio.totals).


------------------------------------------------------------------------


#### epd()


The expected policyholder deficit ratio with these assets: in


Usage

``` python
epd(assets)
```


total, and by unit under equal priority.


##### Parameters


`assets: float`  


##### Returns


`tuple of (float, list of float)`  


------------------------------------------------------------------------


#### expected()


Each unit's expected loss.


Usage

``` python
expected()
```


##### Returns


`list of float`  


------------------------------------------------------------------------


#### from_independent()


From independent units, each a Grid with the same step; the total


Usage

``` python
from_independent(units, grids)
```


and the conditional expectations are computed by FFT.


##### Parameters


`units: list of str`  

`grids: list of Grid`  


##### Returns


`Portfolio`  


------------------------------------------------------------------------


#### from_predictive()


From a joint simulation: each component is a unit, each simulation


Usage

``` python
from_predictive(pd)
```


an equally likely scenario.


##### Parameters


`pd: PredictiveDistribution`  


##### Returns


`Portfolio`  


------------------------------------------------------------------------


#### kappa()


A unit's conditional expectation at each total.


Usage

``` python
kappa(unit)
```


##### Parameters


`unit: str`  


##### Returns


`list of float`  


------------------------------------------------------------------------


#### premium_bounds()


The range of each unit's premium over every distortion that prices


Usage

``` python
premium_bounds(premium, assets=None, p=None)
```


the total, capped at the assets, at [premium](pricing.Price.md#prospicio.pricing.Price.premium) (linear allocation). The extremes are BiTVaR distortions, found exactly.


##### Parameters


`premium: float`  

`assets: float = None`  

`p: float = None`  


##### Returns


`list of dict`  
One per unit: `unit`, [lower](distributions.Grid.md#prospicio.distributions.Grid.lower), [upper](distributions.Custom.md#prospicio.distributions.Custom.upper), and the Distortion giving each, `lower_distortion` and `upper_distortion`.


------------------------------------------------------------------------


#### price()


The premium of the loss capped at the assets, and its natural


Usage

``` python
price(
    distortion,
    assets=None,
    p=None,
    allocation="linear",
    *,
    bottom_layer="limit",
    atom="separate"
)
```


allocation to the units.


##### Parameters


`distortion: Distortion`  

`assets: float = None`  
The asset level; or give [p](models.Elpd.md#prospicio.models.Elpd.p). The largest total by default.

`p: float = None`  
The capital standard: assets at the total's lower [p](models.Elpd.md#prospicio.models.Elpd.p) quantile.

`allocation: (linear, lifted) = ``"linear"`  
The unit share of the assets above the asset level: expected (linear) or distorted (lifted).

`bottom_layer: (limit, none) = ``"limit"`  
Capital in the layer below the smallest total, where the return is undefined: at its limit from above, or none (Monograph 15's equation 8.5 as printed).

`atom: (separate, lumped) = ``"separate"`  
For the linear allocation, a total exactly at the assets keeps its own weight, or is lumped with the default outcomes (*Pricing Insurance Risk*'s linear allocation).


##### Returns


`NaturalPrice`  


##### Notes

The defaults follow [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate) (1.0.1 and 1.2.0 alike). A total exactly at the assets keeps its own weight in the linear allocation, where *Pricing Insurance Risk* lumps it with the default outcomes (its Example 235: 4.3 against 4.16 here); `atom="lumped"` gives the book's numbers, and [p](models.Elpd.md#prospicio.models.Elpd.p) always lands on a total. In the bottom layer of capital, below the smallest total, the units' margins (which sum to zero) take capital at `g'(1) / (1 - g'(1))`: `1/r` for CCoC, `rho / (1 - rho)` for the proportional hazard, 0 for Wang, dual power and TVaR. Monograph 15's equation 8.5 gives that layer none (`bottom_layer="none"`), so CCoC and PH capital by unit differ from it; the total and the premiums do not.


##### Examples

``` python
>>> from prospicio.pricing import Portfolio
>>> from prospicio.risk import Distortion
>>> x1 = [1, 2, 3, 4, 5, 6, 7, 8, 12, 10]
>>> x2 = [1, 2, 3, 4, 5, 9, 8, 12, 13, 20]
>>> port = Portfolio(["X1", "X2"], [[float(a), float(b)] for a, b in zip(x1, x2)])
>>> book = port.price(Distortion.tvar(0.8), assets=10, atom="lumped")
>>> [round(u.premium, 6) for u in book.allocated]
```

\[4.3, 5.7\]

------------------------------------------------------------------------


#### price_stand_alone()


Each unit priced as if it were the whole book, at its own lower


Usage

``` python
price_stand_alone(distortion, p)
```


[p](models.Elpd.md#prospicio.models.Elpd.p) quantile, against the book priced together at the VaR of its total, [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s [Portfolio.price_stand_alone](pricing.Portfolio.md#prospicio.pricing.Portfolio.price_stand_alone). The excess of [sum](pricing.StandAlone.md#prospicio.pricing.StandAlone.sum) over [total](risk.Allocation.md#prospicio.risk.Allocation.total) is the diversification benefit.


##### Parameters


`distortion: Distortion`  

`p: float`  
The VaR capital standard, in `(0, 1)`.


##### Returns


`StandAlone`  


##### Raises


`ValueError`  
If [p](models.Elpd.md#prospicio.models.Elpd.p) is outside `(0, 1)`.


##### Examples

``` python
>>> from prospicio.pricing import Portfolio
>>> from prospicio.risk import Distortion
>>> port = Portfolio(["a", "b"], [[0, 0], [1, 4], [4, 1], [5, 5]])
>>> s = port.price_stand_alone(Distortion.proportional_hazard(0.5), 0.75)
>>> [u.assets for u in s.stand_alone], s.total.assets
```

(\[4.0, 4.0\], 5.0)

------------------------------------------------------------------------


#### priority()


The priority ladder: each unit's recovery from the assets when it


Usage

``` python
priority(assets=None, p=None)
```


ranks ahead of the other units pooled (senior), pro rata (equal), or behind them (junior), as [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `priority_epd_df`. Each is unit against the rest pooled, so on three or more units only the equal recoveries add up to the total. Exact under any dependence for a portfolio built from scenarios.


##### Parameters


`assets: float = None`  
The largest total by default.

`p: float = None`  
The capital standard: assets at the total's lower [p](models.Elpd.md#prospicio.models.Elpd.p) quantile.


##### Returns


`dict`  
Columns, one row per unit and a last `"total"` row: `unit`, [mean](esg.Cir.md#prospicio.esg.Cir.mean), the recoveries `senior`, `equal` and `junior`, and the EPD ratios `senior_epd`, `equal_epd` and `junior_epd` (the total row is `E[X ∧ a]` under every rule); and [assets](pricing.Price.md#prospicio.pricing.Price.assets).


##### Examples

``` python
>>> from prospicio.pricing import Portfolio
>>> port = Portfolio(["A", "B"], [[15, 7], [5, 20], [26, 19], [17, 48]])
>>> ladder = port.priority(assets=50)
>>> round(ladder["senior"][0] + ladder["junior"][1], 9) == ladder["senior"][2]
```

True

------------------------------------------------------------------------


#### priority_kappa()


Where in the total the shortfall `(X - a)+` falls when `unit` is


Usage

``` python
priority_kappa(unit, assets=None, p=None)
```


junior to the rest pooled: at each of [totals](pricing.Portfolio.md#prospicio.pricing.Portfolio.totals), the junior unit's expected part `E[min((X - a)+, X_i) | X = x]` and the senior pool's, which add up to `(x - a)+`. As [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s [priority_kappa](pricing.Portfolio.md#prospicio.pricing.Portfolio.priority_kappa).


##### Parameters


`unit: str`  

`assets: float = None`  

`p: float = None`  


##### Returns


`tuple of (list of float, list of float)`  
The junior and the senior parts.


------------------------------------------------------------------------


#### tvar_threshold()


The level [t](distributions.Pareto.md#prospicio.distributions.Pareto.t) at which the total's TVaR reaches its VaR at [p](models.Elpd.md#prospicio.models.Elpd.p),


Usage

``` python
tvar_threshold(p)
```


[aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s `Portfolio.tvar_threshold(p, 'lower')`.


##### Parameters


`p: float`  


##### Returns


`float`  


##### Raises


`ValueError`  
If [p](models.Elpd.md#prospicio.models.Elpd.p) is outside `[0, 1]`.
