## aggregate.JointGrid


A joint distribution of two losses on a grid, \`\`P(A = i \* step_a, B = j


Usage


``` python
aggregate.JointGrid()
```


- step_b)\`\`: rows are line A and columns line B. The mass past the last row or column is carried on it.


## Parameters


`steps: tuple of (float, float)`  

`probs: list of list of float`  
One row per point of A, one column per point of B, summing to 1.


## Attributes

| Name | Description |
|----|----|
| [probs](#probs) | The probabilities, one list per row. |
| [shape](#shape) | The number of rows (line A) and columns (line B). |
| [steps](#steps) | The step on each axis. |

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


#### probs


The probabilities, one list per row.


`probs: list[list[float]]`


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


#### shape


The number of rows (line A) and columns (line B).


`shape: tuple[int, int]`


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


#### steps


The step on each axis.


`steps: tuple[float, float]`


## Methods

| Name | Description |
|----|----|
| [correlation()](#correlation) | Pearson's correlation of `A` and `B`; NaN if either is constant. |
| [covariance()](#covariance) | `Cov(A, B)`. |
| [from_copula()](#from_copula) | The joint per-event severity of two losses coupled by a copula. |
| [independent()](#independent) | The joint law of two independent losses. |
| [marginal()](#marginal) | The marginal distribution of line A (`axis=0`) or B (`axis=1`). |
| [mean()](#mean) | The mean of line A (`axis=0`) or B (`axis=1`). |
| [moment()](#moment) | The raw mixed moment `E[A^p B^q]`. |
| [prob()](#prob) | `P(A = i * step_a, B = j * step_b)`. |
| [total()](#total) | The distribution of the total `A + B`: exact when the steps are |
| [variance()](#variance) | The variance of line A (`axis=0`) or B (`axis=1`). |

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


#### correlation()


Pearson's correlation of `A` and `B`; NaN if either is constant.


Usage


``` python
correlation()
```


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


#### covariance()


`Cov(A, B)`.


Usage


``` python
covariance()
```


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


#### from_copula()


The joint per-event severity of two losses coupled by a copula.


Usage


``` python
from_copula(a, b, copula, *, trigger_a=1.0, trigger_b=1.0)
```


Each line is hit with its `trigger` probability and then loses from its grid ([a](distributions.Beta.md#prospicio.distributions.Beta.a) for line A, the rows; [b](pricing.Mbbefd.md#prospicio.pricing.Mbbefd.b) for B), so mass at 0 is an event that misses the line; the two per-event marginals are joined by the copula's rectangle probabilities over their cdfs, as [aggregate](aggregate.Clash.md#prospicio.aggregate.Clash.aggregate)'s copula `bivariate`. The marginals come back exactly. Give the result to [fft_bivariate](aggregate.fft_bivariate.md#prospicio.aggregate.fft_bivariate).


##### Parameters


`a: Grid`  
The loss to each line given that the event hits it.

`b: Grid`  
The loss to each line given that the event hits it.

`copula: GaussianCopula or ArchimedeanCopula`  
Two-dimensional, with a distribution function.

`trigger_a: float = ``1.0`  
The probability that an event hits each line.

`trigger_b: float = ``1.0`  
The probability that an event hits each line.


##### Returns


`JointGrid`  


##### Examples

``` python
>>> from prospicio.aggregate import JointGrid
>>> from prospicio.distributions import Grid
>>> from prospicio.risk import ArchimedeanCopula
>>> a = Grid(1.0, [0.25, 0.5, 0.25])
>>> b = Grid(1.0, [0.5, 0.5])
>>> s = JointGrid.from_copula(a, b, ArchimedeanCopula("gumbel", 2.0, 2), trigger_a=0.5)
>>> s.correlation() > 0
```

True

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


#### independent()


The joint law of two independent losses.


Usage


``` python
independent(a, b)
```


##### Parameters


`a: Grid`  

`b: Grid`  


##### Returns


`JointGrid`  


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


#### marginal()


The marginal distribution of line A (`axis=0`) or B (`axis=1`).


Usage


``` python
marginal(axis)
```


##### Parameters


`axis: int`  


##### Returns


`Grid`  


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


#### mean()


The mean of line A (`axis=0`) or B (`axis=1`).


Usage


``` python
mean(axis)
```


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


#### moment()


The raw mixed moment `E[A^p B^q]`.


Usage


``` python
moment(p, q)
```


##### Parameters


`p: int`  

`q: int`  


##### Returns


`float`  


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


#### prob()


`P(A = i * step_a, B = j * step_b)`.


Usage


``` python
prob(i, j)
```


##### Parameters


`i: int`  

`j: int`  


##### Returns


`float`  


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


#### total()


The distribution of the total `A + B`: exact when the steps are


Usage


``` python
total()
```


equal, otherwise on the larger step with each cell's mass split to keep the mean.


##### Returns


`Grid`  


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


#### variance()


The variance of line A (`axis=0`) or B (`axis=1`).


Usage


``` python
variance(axis)
```
