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
##   2001-01-01 357848 1124788 1735330 2218270 2745596 3319994 3466336
##   2002-01-01 352118 1236139 2170033 3353322 3799067 4120063 4647867
##   2003-01-01 290507 1292306 2218525 3235179 3985995 4132918 4628910
##   2004-01-01 310608 1418858 2195047 3757447 4029929 4381982 4588268
##   2005-01-01 443160 1136350 2128333 2897821 3402672 3873311      NA
##   2006-01-01 396132 1333217 2180715 2985752 3691712      NA      NA
##   2007-01-01 440832 1288463 2419861 3483130      NA      NA      NA
##   2008-01-01 359480 1421128 2864498      NA      NA      NA      NA
##   2009-01-01 376686 1363294      NA      NA      NA      NA      NA
##   2010-01-01 344014      NA      NA      NA      NA      NA      NA
##             dev
## origin             8       9      10
##   2001-01-01 3606286 3833515 3901463
##   2002-01-01 4914039 5339085      NA
##   2003-01-01 4909315      NA      NA
##   2004-01-01      NA      NA      NA
##   2005-01-01      NA      NA      NA
##   2006-01-01      NA      NA      NA
##   2007-01-01      NA      NA      NA
##   2008-01-01      NA      NA      NA
##   2009-01-01      NA      NA      NA
##   2010-01-01      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
##   2001-01-01 349741.1 1109368 1737850 2265706 2749056 3318464 3469142
##   2002-01-01 352821.5 1245621 2132200 3377061 3820987 4148933 4610189
##   2003-01-01 296547.8 1275881 2198221 3235844 3944931 4113276 4623159
##   2004-01-01 313669.5 1392038 2171462 3774168 4035879 4461897 4661352
##   2005-01-01 443940.5 1138787 2190873 2905444 3371444 3849587      NA
##   2006-01-01 391526.6 1324732 2230006 3000719 3742811      NA      NA
##   2007-01-01 446941.9 1292116 2416001 3404734      NA      NA      NA
##   2008-01-01 349330.2 1425022 2844242      NA      NA      NA      NA
##   2009-01-01 369893.1 1368242      NA      NA      NA      NA      NA
##   2010-01-01 346492.8      NA      NA      NA      NA      NA      NA
##             devyear
## ay                 8       9      10
##   2001-01-01 3549578 3769684 3980606
##   2002-01-01 4891852 5311927      NA
##   2003-01-01 4900318      NA      NA
##   2004-01-01      NA      NA      NA
##   2005-01-01      NA      NA      NA
##   2006-01-01      NA      NA      NA
##   2007-01-01      NA      NA      NA
##   2008-01-01      NA      NA      NA
##   2009-01-01      NA      NA      NA
##   2010-01-01      NA      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        357848
## 2             2               1        352118
## 3             3               1        290507
## 4             4               1        310608
## 5             5               1        443160
## 6             6               1        396132

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()