The function splits rows with a time period longer than one month to multiple rows with a time period of exactly one month each. Values in numeric columns (e.g. exposure or premium) are divided over the months proportionately.

period_to_months(df, begin, end, ...)

Arguments

df

data.frame

begin

column in df with begin dates

end

column in df with end dates

...

numeric columns in df to split

Value

data.frame with same columns as in df, and one extra column called id

Details

In insurance portfolios it is common that rows relate to periods longer than one month. This is for example problematic in case exposures per month are desired.

Since insurance premiums are constant over the months, and do not depend on the number of days per month, the function assumes that each month has the same number of days (i.e. 30).

Author

Martin Haringa

Examples

library(lubridate)
#> Loading required package: timechange
#> 
#> Attaching package: ‘lubridate’
#> The following objects are masked from ‘package:base’:
#> 
#>     date, intersect, setdiff, union
portfolio <- data.frame(
begin1 = ymd(c("2014-01-01", "2014-01-01")),
end = ymd(c("2014-03-14", "2014-05-10")),
termination = ymd(c("2014-03-14", "2014-05-10")),
exposure = c(0.2025, 0.3583),
premium =  c(125, 150))
period_to_months(portfolio, begin1, end, premium, exposure)
#>    id     begin1        end termination   exposure  premium
#> 1:  1 2014-01-01 2014-01-31  2014-03-14 0.08209459 50.67568
#> 2:  1 2014-02-01 2014-02-28  2014-03-14 0.08209459 50.67568
#> 3:  1 2014-03-01 2014-03-31  2014-03-14 0.03831081 23.64865
#> 4:  2 2014-01-01 2014-01-31  2014-05-10 0.08268462 34.61538
#> 5:  2 2014-02-01 2014-02-28  2014-05-10 0.08268462 34.61538
#> 6:  2 2014-03-01 2014-03-31  2014-05-10 0.08268462 34.61538
#> 7:  2 2014-04-01 2014-04-30  2014-05-10 0.08268462 34.61538
#> 8:  2 2014-05-01 2014-05-31  2014-05-10 0.02756154 11.53846