Skip to content

Commit

Permalink
update for ExperienceAnalysis v2
Browse files Browse the repository at this point in the history
  • Loading branch information
alecloudenback authored Jun 5, 2024
1 parent dcde0f8 commit bc03e1e
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,27 +554,47 @@ Adding, substracting, multiplying, dividing, and comparing rates is supported.
> Meeting your exposure calculation needs.

### QuickStart
### Quickstart

```julia
using ExperienceAnalysis
using Dates
df = DataFrame(
policy_id = 1:3,
issue_date = [Date(2020,5,10), Date(2020,4,5), Date(2019, 3, 10)],
end_date = [Date(2022, 6, 10), Date(2022, 8, 10), Date(2022,12,31)],
status = ["claim", "lapse", "inforce"]
)

issue = Date(2016, 7, 4)
termination = Date(2020, 1, 17)
basis = ExperienceAnalysis.Anniversary(Year(1))
exposure(basis, issue, termination)
```
This will return an array of tuples with a `from` and `to` date:
df.policy_year = exposure.(
ExperienceAnalysis.Anniversary(Year(1)),
df.issue_date,
df.end_date,
df.status .== "claim"; # continued exposure
study_start = Date(2020, 1, 1),
study_end = Date(2022, 12, 31)
)

```julia
4-element Array{NamedTuple{(:from, :to),Tuple{Date,Date}},1}:
(from = Date("2016-07-04"), to = Date("2017-07-04"))
(from = Date("2017-07-04"), to = Date("2018-07-04"))
(from = Date("2018-07-04"), to = Date("2019-07-04"))
(from = Date("2019-07-04"), to = Date("2020-01-17"))
df = flatten(df, :policy_year)

df.exposure_fraction =
map(e -> yearfrac(e.from, e.to + Day(1), DayCounts.Thirty360()), df.policy_year)
# + Day(1) above because DayCounts has Date(2020, 1, 1) to Date(2021, 1, 1) as an exposure of 1.0
# here we end the interval at Date(2020, 12, 31), so we need to add a day to get the correct exposure fraction.
```

| **policy\_id**<br>`Int64` | **issue\_date**<br>`Date` | **end\_date**<br>`Date` | **status**<br>`String` | **policy\_year**<br>`@NamedTuple{from::Date, to::Date, policy\_timestep::Int64}` | **exposure\_fraction**<br>`Float64` |
|--------------------------:|--------------------------:|------------------------:|-----------------------:|---------------------------------------------------------------------------------:|------------------------------------:|
| 1 | 2020-05-10 | 2022-06-10 | claim | (from = Date("2020-05-10"), to = Date("2021-05-09"), policy\_timestep = 1) | 1.0 |
| 1 | 2020-05-10 | 2022-06-10 | claim | (from = Date("2021-05-10"), to = Date("2022-05-09"), policy\_timestep = 2) | 1.0 |
| 1 | 2020-05-10 | 2022-06-10 | claim | (from = Date("2022-05-10"), to = Date("2023-05-09"), policy\_timestep = 3) | 1.0 |
| 2 | 2020-04-05 | 2022-08-10 | lapse | (from = Date("2020-04-05"), to = Date("2021-04-04"), policy\_timestep = 1) | 1.0 |
| 2 | 2020-04-05 | 2022-08-10 | lapse | (from = Date("2021-04-05"), to = Date("2022-04-04"), policy\_timestep = 2) | 1.0 |
| 2 | 2020-04-05 | 2022-08-10 | lapse | (from = Date("2022-04-05"), to = Date("2022-08-10"), policy\_timestep = 3) | 0.35 |
| 3 | 2019-03-10 | 2022-12-31 | inforce | (from = Date("2020-01-01"), to = Date("2020-03-09"), policy\_timestep = 1) | 0.191667 |
| 3 | 2019-03-10 | 2022-12-31 | inforce | (from = Date("2020-03-10"), to = Date("2021-03-09"), policy\_timestep = 2) | 1.0 |
| 3 | 2019-03-10 | 2022-12-31 | inforce | (from = Date("2021-03-10"), to = Date("2022-03-09"), policy\_timestep = 3) | 1.0 |
| 3 | 2019-03-10 | 2022-12-31 | inforce | (from = Date("2022-03-10"), to = Date("2022-12-31"), policy\_timestep = 4) | 0.808333 |


### Available Exposure Basis

- `ExperienceAnalysis.Anniversary(period)` will give exposures periods based on the first date
Expand Down Expand Up @@ -759,4 +779,4 @@ julia> ? survival
### Other Repositories of Interest for Actuaries

- [RMInsurance](https://github.com/mkriele/RMInsurance.jl) is the code and examples for the second edition of the book "Value-Oriented Risk Management of Insurance Companies"
- [LifeTable.jl](https://github.com/klpn/LifeTable.jl) will calculate life tables from the Human Mortality Database.
- [LifeTable.jl](https://github.com/klpn/LifeTable.jl) will calculate life tables from the Human Mortality Database.

0 comments on commit bc03e1e

Please sign in to comment.