1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| fullx <- cbind(x)
> for(k in 1:n){
+ fullx[(n-k+1):n, k+1] <- fullx[(n-k+1):n,k]*f[k]
+ }
Error in `[<-`(`*tmp*`, (n - k + 1):n, k + 1, value = c(NA_real_, NA_real_, :
subscript out of bounds
> round(fullx)
V1 V2 V3 V4 V5 V6
2014 1001 2856 5279 8267 11602 15085
2015 1113 3216 5990 9412 13256 17236
2016 1269 3702 6935 10912 15343 19949
2017 1490 4363 8243 12946 18204 23668
2018 1725 4986 9328 14650 20599 26783
2019 1889 5475 10242 16086 22619 29409
> #totale provision
> sum(fullx[ ,5] - getLatestCumulative(x))
[1] 47251.08
> getLatestCumulative
function (Triangle, na.values = NULL)
{
if (!is.matrix(Triangle))
stop("Triangle '", deparse(substitute(Triangle)), "' must be a matrix")
f <- if (is.null(na.values))
function(x) ifelse(length(w <- which(!is.na(x))) > 0L,
tail(w, 1L), 1)
else function(x) ifelse(length(w <- which(!is.na(x) & !(x %in%
na.values))) > 0L, tail(w, 1L), 1)
latestcol <- apply(Triangle, 1L, f)
latestdiag <- Triangle[cbind(seq_along(latestcol), latestcol)]
attr(latestdiag, "latestcol") <- latestcol
nms <- names(dmnms <- dimnames(Triangle))
nms1 <- nms[1L]
nms2 <- nms[2L]
if (!is.null(dmnms[[1L]])) {
names(latestdiag) <- dmnms[[1L]]
attr(latestdiag, "rowsname") <- nms1
}
if (!is.null(dmnms[[2L]])) {
attr(latestdiag, "colnames") <- dmnms[[2L]][latestcol]
attr(latestdiag, "colsname") <- nms2
}
return(latestdiag)
}
<environment: namespace:ChainLadder> |
Partager