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} =} quotaad (@var{s},@var{v})
19## Calculate the cumulative quotas by the Mack 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## @var{v} is a mx1 vector of known volume measures (like premiums or the number of contracts).
27##
28## The Mack method asumes that exists a vector @var{v} and a vector P(i) 1<=i<=m of parameters
29## such that holds for all i = {1,...,m} the next identity:
30##
31## @group
32## @example
33## ultimate(i) = V(i)*P(i)
34## @end example
35## @end group
36##
37## where
38##
39## @group
40## @example
41##                   l=n-1
42## P(i)= O_mack(i) *   E   IRL_Mack(l)
43##                    l=0
44## @end example
45## @end group
46##
47## ,
48##
49## @group
50## @example
51##                   l=n-k-1
52##                     E     Z(j,k)
53##                    j=0
54## IRL_Mack(i)   =  ---------------------
55##                   l=n-k-1
56##                     E   V(i)*O_Mack(l)
57##                    l=0
58## @end example
59## @end group
60##
61## and
62##
63## @group
64## @example
65##                   l=n-i-1
66##                     E     Z(i,l)
67##                    l=0
68## O_Mack(i)     =  ------------------
69##                   l=n-1
70##                     E   V(i)*IRL(l)    (see IRL definition in quotaad function)
71##                    l=0
72## @end example
73## @end group
74##
75## Z represents the incremental losses; then losses satisfy
76## Z(k) = (S(k) - S(k-1) ),Z(0) = S(0) for all i = {1,...,m}.
77##
78## @var{quotas} returns a row vector with the cumulative quotas. The formula is:
79## @group
80## @example
81##                    l=k
82##                     E   IRL_Mack(l)
83##                    l=0
84## @var{quotas}(k) =  ------------------
85##                   l=n-1
86##                     E   IRL_Mack(l)
87##                    l=0
88## @end example
89## @end group
90##
91## @seealso {bferguson, quotald, quotapanning, quotaad}
92## @end deftypefn
93
94## Author: Act. Esteban Cervetto ARG <estebancster@gmail.com>
95##
96## Maintainer: Act. Esteban Cervetto ARG <estebancster@gmail.com>
97##
98## Created: jul-2009
99##
100## Version: 1.1.0
101##
102## Keywords: actuarial reserves insurance bornhuetter ferguson chainladder
103
104function [quotas] = quotamack (S,V)
105
106[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)
107u = m - n;                                     #rows of the upper square
108S = fliplr(triu(fliplr(S),-u));                   #ensure S is triangular
109
110if (size(V) ~= [m,1])
111 usage(strcat("volume V must be of size [",num2str(m),",1]" ));
112end
113
114# Z triangle
115Z = [S(:,1), S(:,2:n)-S(:,1:n-1)];
116Z = fliplr(triu(fliplr(Z),-u));             #clean Z
117
118# calculate empirical individual loss ratios
119a = repmat (V,1,n);
120LRI = Z ./ a;
121
122# weights V(i)/sum(1,n-k,V(i))
123num =fliplr(triu(fliplr(a),-u));            #numerator and clean low triangle
124den = repmat(sum(num),m,1);                 #denominator
125den = fliplr(triu(fliplr(den),-u));         #clean low triangle
126W = num./den;                               #divide by
127W = fliplr(triu(fliplr(W),-u));
128
129# incremental Loss Ratios AD
130LRI_AD  = diag(LRI' * W)';                  #weighted product
131
132if (u==0)
133b = (diag(fliplr(S),-u) ./ flipud(cumsum(LRI_AD)') ) ./ V;
134else
135b = ([S(1:u,n); diag(fliplr(S),-u)] ./ [sum(LRI_AD)*ones(1,u);flipud(cumsum(LRI_AD)')] ) ./ V;
136end
137
138sZ = sum (Z);                              #sum of Z
139sb = repmat(b,1,n);
140sb = fliplr(triu(fliplr(sb),-u));
141sV = repmat(V,1,n);
142sV = fliplr(triu(fliplr(sV),-u));
143
144LRI_Mack = sZ ./ (diag(sb'*sV))';
145quotas = cumsum(porcentual(LRI_Mack));     #calculate cumulated  quota
146
147end
148