## aggregate.EventSet


Simulated years of individual losses, for applying per-loss terms such


Usage


``` python
aggregate.EventSet()
```


as reinsurance layers.

Created by [simulate_events](aggregate.simulate_events.md#prospicio.aggregate.simulate_events). Year `i` was drawn from stream `i` of the generator keyed by [seed](aggregate.EventSet.md#prospicio.aggregate.EventSet.seed), so results do not depend on the number of threads.


## Attributes

| Name | Description |
|----|----|
| [has_sums_insured](#has_sums_insured) | Whether the losses carry sums insured. |
| [has_times](#has_times) | Whether the losses carry times. |
| [n_sims](#n_sims) | Number of simulated years. |
| [seed](#seed) | The seed the years were drawn from. |

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


#### has_sums_insured


Whether the losses carry sums insured.


`has_sums_insured: bool`


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


#### has_times


Whether the losses carry times.


`has_times: bool`


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


#### n_sims


Number of simulated years.


`n_sims: int`


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


#### seed


The seed the years were drawn from.


`seed: int`


## Methods

| Name | Description |
|----|----|
| [counts()](#counts) | Number of losses in each year. |
| [events()](#events) | Year `sim`'s individual losses, in the order they were drawn. |
| [from_years()](#from_years) | Years of losses from elsewhere (your own simulation, or a |
| [sums_insured()](#sums_insured) | Year `sim`'s sums insured, one per loss, or `None`. |
| [times()](#times) | Year `sim`'s times, one per loss, or `None`. |
| [totals()](#totals) | Each year's total loss. |
| [with_seasonal_times()](#with_seasonal_times) | The same events at times drawn from a seasonal density. |
| [with_uniform_times()](#with_uniform_times) | The same events at times spread uniformly over the year. |

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


#### counts()


Number of losses in each year.


Usage


``` python
counts()
```


##### Returns


`list of int`  


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


#### events()


Year `sim`'s individual losses, in the order they were drawn.


Usage


``` python
events(sim)
```


##### Parameters


`sim: int`  


##### Returns


`list of float`  


##### Raises


`IndexError`  
If `sim` is not a simulated year.


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


#### from_years()


Years of losses from elsewhere (your own simulation, or a


Usage


``` python
from_years(years, sums_insured=None, seed=0, times=None)
```


catastrophe model's event loss table by year), optionally with the sum insured of the risk each loss hit, which a surplus treaty needs.


##### Parameters


`years: list of list of float`  
Each year's losses, in order.

`sums_insured: list of list of float = None`  
The same shape: each loss's sum insured, at least the loss.

`seed: int = ``0`  
Recorded in results' provenance.

`times: list of list of float = None`  
The same shape: each loss's time, as the fraction of the year elapsed (in `[0, 1]`, non-decreasing within a year), which reinstatements pro rata as to time need.


##### Returns


`EventSet`  


##### Examples

``` python
>>> from prospicio.aggregate import EventSet
>>> e = EventSet.from_years([[5.0, 2.0], [], [9.0]], [[10.0, 2.0], [], [50.0]])
>>> e.counts(), e.sums_insured(2)
```

(\[2, 0, 1\], \[50.0\])

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


#### sums_insured()


Year `sim`'s sums insured, one per loss, or `None`.


Usage


``` python
sums_insured(sim)
```


##### Parameters


`sim: int`  


##### Returns


`list of float or None`  


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


#### times()


Year `sim`'s times, one per loss, or `None`.


Usage


``` python
times(sim)
```


##### Parameters


`sim: int`  


##### Returns


`list of float or None`  


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


#### totals()


Each year's total loss.


Usage


``` python
totals()
```


##### Returns


`PredictiveDistribution`  


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


#### with_seasonal_times()


The same events at times drawn from a seasonal density.


Usage


``` python
with_seasonal_times(weights)
```


The year is cut into `len(weights)` equal periods (12 for months, 52 for weeks) starting at the contract's inception, and a loss falls in period `k` with probability `weights[k] / sum(weights)`, uniformly within it. A zero weight means no losses in that period. The draws are those of [with_uniform_times](aggregate.EventSet.md#prospicio.aggregate.EventSet.with_uniform_times), mapped through the season's quantile, so equal weights give the uniform times.


##### Parameters


`weights: list of float`  
Each period's relative weight: non-negative, not all zero.


##### Returns


`EventSet`  


##### Examples

``` python
>>> from prospicio.aggregate import EventSet
>>> e = EventSet.from_years([[5.0, 2.0, 7.0]], seed=3)
>>> t = e.with_seasonal_times([0.0, 1.0]).times(0)
>>> all(x >= 0.5 for x in t) and t == sorted(t)
```

True

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


#### with_uniform_times()


The same events at times spread uniformly over the year.


Usage


``` python
with_uniform_times()
```


Year `i`'s losses take sorted uniform draws, in their order, from a stream of the generator keyed by the set's seed apart from the losses' own, so the losses are unchanged and any year replays alone.


##### Returns


`EventSet`  


##### Examples

``` python
>>> from prospicio.aggregate import EventSet
>>> e = EventSet.from_years([[5.0, 2.0, 7.0]], seed=3).with_uniform_times()
>>> t = e.times(0)
>>> t == sorted(t) and e.has_times
```

True
