---
title: "Worked Example"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Worked-Example}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

A worked example follows to serve as motivation for the use case.

TODO

```{r }
library(eltr)

raw_elt <-example_elt

```

### Calculate ELT parameters and modify raw ELT table


```{r}
elt <- create_elt(raw_elt, ann_rate="rate", mu="mean", sdev_i = "sdevi" , sdev_c = "sdevc", expval = "exp")

elt
```

### apply Monte Carlo simulation to turn ELT into YLT

```{r}
ylt <- create_ylt(elt, sims=10 ,ann_rate = "rate" , event_id = "id", expval = "exp" , mu ="mean")

ylt
```

### apply insurance structure to calculate limited losses

```{r}

# Layer 500 xs 50

ylt[ , layer1_loss := layer_loss(Loss, Excess = 50 , Limit = 500  ) ] 

ylt
```

### Summarise losses by year and calculated average expected loss

```{r}


ann <-ylt[, lapply( .SD , sum), by=Year, .SDcols = c("Loss","layer1_loss") ] 

ann

expected_loss <- ann[ , lapply(.SD, mean) , .SDcols = c("Loss","layer1_loss")      ]

expected_loss


```

### Calculate OEP

```{r}

ep <-create_oep_curve(ann , y= "Year", z="Loss")
ep

```



### calculate AAL and OEP







