## pricing.price_portfolio()


Prices a portfolio and allocates the price to its components.


Usage


``` python
pricing.price_portfolio(
    pd,
    assets,
    *,
    cost_of_capital=None,
    distortion=None,
)
```


Premium and assets are each allocated by co-measure (the natural allocation): component prices add up to the portfolio's, and a component that diversifies the portfolio is priced below its standalone price. With a cost of capital, every component earns the rate on its allocated capital.


## Parameters


`pd: PredictiveDistribution`  
Components that add up to the portfolio: segments or covers, not gross, ceded and net side by side.

`assets: Distortion`  

`cost_of_capital: float = None`  

`distortion: Distortion = None`  
Exactly one of `cost_of_capital` and `distortion`, as in [price](pricing.price.md#prospicio.pricing.price).


## Returns


`PortfolioPrice`  


## Examples

``` python
>>> from prospicio.distributions import PredictiveDistribution
>>> from prospicio.pricing import price_portfolio
>>> from prospicio.risk import Distortion
>>> pd = PredictiveDistribution(["cover"], [("a",), ("b",)],
...                             [[0.0, 2.0], [1.0, 1.0], [4.0, 0.0], [8.0, 0.0]])
>>> p = price_portfolio(pd, Distortion.tvar(0.5), cost_of_capital=0.1)
>>> [round(c.premium, 6) for c in p.allocated]
```

\[3.5, 0.681818\]

``` python
>>> p.allocated[1].margin < 0  # the second cover hedges the first
```

True
