Version 0.2.14 [2021-11-11]

Version 0.2.13 [2021-10-06]

Version 0.2.12 [2021-01-05]

Version 0.2.11 [2020-02-10]

Version 0.2.10 [2019-05-27]

Thanks to Marco De Virgilis.

Version 0.2.9 [2018-12-06]

Version 0.2.8 [2018-11-10]

Version 0.2.7 [2018-10-16]

Version 0.2.6 [2018-05-29]

Version 0.2.5 [2017-10-19]

Version 0.2.4 [2017-01-01]

Version 0.2.3 [2016-10-20]

Changes

NEWS file

Moved NEWS file into RMarkdown package vignette format.

Triangles may now have non-numeric rownames

Previously it was required that the row and column names of a triangle be convertible to numeric, although that “requirement” did not always cause a problem. For example, the following sets the rownames of GenIns to the beginning Date of the accident year.

x <- GenIns
rownames(x) <- paste0(2001:2010, "-01-01")
x
##             dev
## origin           1    2    3    4    5    6    7    8    9   10
##   2001-01-01 357.8 1125 1735 2218 2746 3320 3466 3606 3834 3901
##   2002-01-01 352.1 1236 2170 3353 3799 4120 4648 4914 5339   NA
##   2003-01-01 290.5 1292 2219 3235 3986 4133 4629 4909   NA   NA
##   2004-01-01 310.6 1419 2195 3757 4030 4382 4588   NA   NA   NA
##   2005-01-01 443.2 1136 2128 2898 3403 3873   NA   NA   NA   NA
##   2006-01-01 396.1 1333 2181 2986 3692   NA   NA   NA   NA   NA
##   2007-01-01 440.8 1288 2420 3483   NA   NA   NA   NA   NA   NA
##   2008-01-01 359.5 1421 2864   NA   NA   NA   NA   NA   NA   NA
##   2009-01-01 376.7 1363   NA   NA   NA   NA   NA   NA   NA   NA
##   2010-01-01 344.0   NA   NA   NA   NA   NA   NA   NA   NA   NA

A plot with the lattice=TRUE option, which previously would blow up, now displays with nice headings.

plot(x, lattice=TRUE)

It can often be useful to have “origin” values that are not necessarily convertible to numeric. For example, suppose you have a table of claim detail at various evaluation dates. Invariably, such a table will have a Date field holding the date of loss. It would be nice to be able to summarize that data by accident year “cuts”. It turns out there’s a builtin function in R that will get you most of the way there. It’s called ‘cut’.

Here we take the GenIns data in long format and generate 50 claims per accident period. We assign each claim a random date within the year. The incurred (or paid) “value” given is a random perturbation of one-fiftieth of GenInsLong$value.

We accumulate the detail into an accident year triangle using ChainLadder’s as.triangle method. The summarized triangle displayed at the end is very similar to GenIns, and has informative row labels.

x <- GenInsLong
# start off y with x's headings
y <- x[0,]
names(y)[1] <- "lossdate"
set.seed(1234)
n = 50 # number of simulated claims per accident perior
for (i in 1:nrow(x)) {
  y <- rbind(y,
             data.frame(
               lossdate = as.Date(
                 as.numeric(as.Date(paste0(x[i, "accyear"]+2000, "-01-01"))) +
                   round(runif(n, 0, 364),0), origin = "1970-01-01"),
               devyear = x[i, "devyear"],
               incurred.claims = rnorm(n, mean = x[i, "incurred claims"] / n,
                                         sd = x[i, "incurred claims"]/(10*n))
             ))
}
# here's the magic cut
y$ay <- cut(y$lossdate, breaks = "years")
# this summarized triangle is very similar to GenIns
as.triangle(y, origin = "ay", dev = "devyear", value = "incurred.claims")
##             devyear
## ay                1       2       3       4       5       6       7       8
##   2001-01-01 349741 1109368 1737850 2265706 2749056 3318464 3469142 3549578
##   2002-01-01 352821 1245621 2132200 3377061 3820987 4148933 4610189 4891852
##   2003-01-01 296548 1275881 2198221 3235844 3944931 4113276 4623159 4900318
##   2004-01-01 313669 1392038 2171462 3774168 4035879 4461897 4661352      NA
##   2005-01-01 443941 1138787 2190873 2905444 3371444 3849587      NA      NA
##   2006-01-01 391527 1324732 2230006 3000719 3742811      NA      NA      NA
##   2007-01-01 446942 1292116 2416001 3404734      NA      NA      NA      NA
##   2008-01-01 349330 1425022 2844242      NA      NA      NA      NA      NA
##   2009-01-01 369893 1368242      NA      NA      NA      NA      NA      NA
##   2010-01-01 346493      NA      NA      NA      NA      NA      NA      NA
##             devyear
## ay                 9      10
##   2001-01-01 3769684 3980606
##   2002-01-01 5311927      NA
##   2003-01-01      NA      NA
##   2004-01-01      NA      NA
##   2005-01-01      NA      NA
##   2006-01-01      NA      NA
##   2007-01-01      NA      NA
##   2008-01-01      NA      NA
##   2009-01-01      NA      NA
##   2010-01-01      NA      NA

The user is encouraged to experiment with other cut’s – e.g., breaks = "quarters" will generate accident quarter triangles.

New as.LongTriangle function

A new function, as.LongTriangle, will convert a triangle from “wide” (matrix) format to “long” (data.frame) format. This differs from ChainLadder’s as.data.frame.triangle method in that the rownames and colnames of Triangle are stored as factors. This feature can be particularly important when plotting a triangle because the order of the “origin” and “dev” values is important.

Additionally, the columns of the resulting data frame may be renamed from the default values (“origin”, “dev”, and “value”) using the “varnames” argument for “origin”/“dev” and the “value.name” argument for “value”.

In the following example, the GenIns triangle in ChainLadder is converted to a data.frame with non-default names:

GenLong <- as.LongTriangle(GenIns, varnames = c("accident year", "development age"),
                           value.name = "Incurred Loss")
head(GenLong)
##   accident year development age Incurred Loss
## 1             1               1         357.8
## 2             2               1         352.1
## 3             3               1         290.5
## 4             4               1         310.6
## 5             5               1         443.2
## 6             6               1         396.1

In the following plot, the last accident year and the last development age are shown last, rather than second as they would have been if displayed alphabetically (ggplot’s default for character data):

library(ggplot2)
ggplot(GenLong, aes(x=`development age`, y = `Incurred Loss`,
                    group = `accident year`, color = `accident year`)) +
  geom_line()