Diff of /inst/quotapanning.m [000000] .. [d39d4b] Maximize Restore

  Switch to unified view

a b/inst/quotapanning.m
1
## Copyright (C) 2009 Esteban Cervetto <estebancster@gmail.com>
2
##
3
## Octave is free software; you can redistribute it and/or modify it
4
## under the terms of the GNU General Public License as published by
5
## the Free Software Foundation; either version 3 of the License, or (at
6
## your option) any later version.
7
##
8
## Octave is distributed in the hope that it will be useful, but
9
## WITHOUT ANY WARRANTY; without even the implied warranty of
10
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
## General Public License for more details.
12
##
13
## You should have received a copy of the GNU General Public License
14
## along with Octave; see the file COPYING.  If not, see
15
## <http://www.gnu.org/licenses/>.
16
17
## -*- texinfo -*-
18
## @deftypefn {Function File} {@var{quotas} =} quotapanning (@var{s})
19
## Calculate the cumulative quotas by the Panning method.
20
##
21
## @var{s} is a mxn matrix that contains the run-off triangle, where m is the number of accident-years
22
## and n is the number of periods to final development. @var{s} may contain u = m-n complete years.
23
## The value @var{s}(i,k), 1<=i<=m, 0<=k<=n-1 represents the cumulative losses from accident-period i
24
## settled with a delay of at most k years. 
25
## The values @var{s}(i,k) with i + k > m must be zero because is future time. 
26
##
27
## The Panning method asumes that exists a development pattern on the incremental ratios.
28
## This means that the identity 
29
## @group
30
## @example
31
##          E[Z(i,k) ]
32
## B(k) =  ------------
33
##          E[Z(i,0) ]
34
## @end example
35
## @end group
36
## holds for all k = {0,...,n-1} and for all i = {1,...,m}. 
37
## Z represents the incremental losses; then losses satisfy 
38
## Z(k) = (S(k) - S(k-1) ),Z(0) = S(0) for all i = {1,...,m}.
39
##
40
## @var{quotas} returns a row vector with the cumulative quotas. The transformation
41
## from incremental ratios to cumulative quotas is:
42
## @group
43
## @example
44
##                    l=k  
45
##                     E    B(l)
46
#                     l=0   
47
## @var{quotas}(k) =  -----------
48
##                   l=n-1    
49
##                     E    B(l)
50
##                    l=0     
51
## @end example
52
## @end group
53
##
54
## @seealso {bferguson, ultimatepanning, quotald, quotaad, quotamack}
55
## @end deftypefn
56
57
## Author: Act. Esteban Cervetto ARG <estebancster@gmail.com>
58
##
59
## Maintainer: Act. Esteban Cervetto ARG <estebancster@gmail.com>
60
##
61
## Created: jul-2009
62
##
63
## Version: 1.1.0 
64
##
65
## Keywords: actuarial reserves insurance bornhuetter ferguson chainladder
66
67
function quotas = quotapanning (S)
68
69
[m,n] = size (S);           #triangle with m years (i=1,2,u,...u+1,u+2,....m) and n periods (k=0,1,2,...n-1)
70
u = m - n;                                     #rows of the upper square
71
S = fliplr(triu(fliplr(S),-u));                   #ensure S is triangular  
72
73
# calculate Z
74
Z = [S(:,1), S(:,2:n)-S(:,1:n-1)];
75
Z = fliplr(triu(fliplr(Z),-u));        #clean Z
76
77
# calc empirical values of the incremental factors
78
B = Z ./ (Z * [ones(n,1),zeros(n,n-1)]');
79
 
80
# weights Z(i,0)^2/Z(0)^2
81
 W = repmat((Z(:,1).^2),1,n);          #numerator
82
 W =fliplr(triu(fliplr(W),-u));        #clean low triangle
83
 a = repmat(sum(W),m,1);               #denominator
84
 a = fliplr(triu(fliplr(a),-u));       #clean low triangle
85
 W = W./a; #divido
86
 W = fliplr(triu(fliplr(W),-u));       #clean low triangle
87
88
# Pannings incremental factors
89
B_Pan  = diag(B' * W)';                #weighted product
90
quotas = cumsum(porcentual(B_Pan));    #cumulated quota
91
 
92
end