Diff of /inst/quotamack.m [88c2a4] .. [677636]  Maximize  Restore

Switch to unified view

a/inst/quotamack.m b/inst/quotamack.m
...
...
13
## You should have received a copy of the GNU General Public License
13
## You should have received a copy of the GNU General Public License
14
## along with Octave; see the file COPYING.  If not, see
14
## along with Octave; see the file COPYING.  If not, see
15
## <http://www.gnu.org/licenses/>.
15
## <http://www.gnu.org/licenses/>.
16
16
17
## -*- texinfo -*-
17
## -*- texinfo -*-
18
## @deftypefn {Function File} {@var{quotas} =} quotaad (@var{s},@var{v})
18
## @deftypefn {Function File} {@var{quotas} =} quotaad (@var{s}, @var{v})
19
## Calculate the cumulative quotas by the Mack method.
19
## Calculate the cumulative quotas by the Mack method.
20
##
20
##
21
## @var{s} is a mxn matrix that contains the run-off triangle, where m is the number of accident-years
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.
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
23
## The value @var{s}(i,k), 1<=i<=m, 0<=k<=n-1 represents the cumulative losses from accident-period i
...
...
80
## @end verbatim
80
## @end verbatim
81
##
81
##
82
## @seealso {bferguson, quotald, quotapanning, quotaad}
82
## @seealso {bferguson, quotald, quotapanning, quotaad}
83
## @end deftypefn
83
## @end deftypefn
84
84
85
function [quotas] = quotamack (S,V)
85
function [quotas] = quotamack (S, V)
86
86
87
[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)
87
  [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)
88
u = m - n;                                     #rows of the upper square
88
  u = m - n;                                     #rows of the upper square
89
S = fliplr(triu(fliplr(S),-u));                   #ensure S is triangular  
89
  S = fliplr(triu(fliplr(S),-u));                   #ensure S is triangular
90
90
91
if (size(V) ~= [m,1])
91
  if (size(V) ~= [m,1])
92
 usage(strcat("volume V must be of size [",num2str(m),",1]" ));
92
    error(strcat("volume V must be of size [",num2str(m),",1]" ));
93
end  
93
  end  
94
94
95
# Z triangle 
95
  # Z triangle 
96
Z = [S(:,1), S(:,2:n)-S(:,1:n-1)];
96
  Z = [S(:,1), S(:,2:n)-S(:,1:n-1)];
97
Z = fliplr(triu(fliplr(Z),-u));             #clean Z
97
  Z = fliplr(triu(fliplr(Z),-u));             #clean Z
98
98
99
# calculate empirical individual loss ratios
99
  # calculate empirical individual loss ratios
100
a = repmat (V,1,n);
100
  a = repmat (V,1,n);
101
LRI = Z ./ a;
101
  LRI = Z ./ a;
102
102
103
# weights V(i)/sum(1,n-k,V(i)) 
103
  # weights V(i)/sum(1,n-k,V(i)) 
104
num =fliplr(triu(fliplr(a),-u));            #numerator and clean low triangle
104
  num =fliplr(triu(fliplr(a),-u));            #numerator and clean low triangle
105
den = repmat(sum(num),m,1);                 #denominator
105
  den = repmat(sum(num),m,1);                 #denominator
106
den = fliplr(triu(fliplr(den),-u));         #clean low triangle
106
  den = fliplr(triu(fliplr(den),-u));         #clean low triangle
107
W = num./den;                               #divide by
107
  W = num./den;                               #divide by
108
W = fliplr(triu(fliplr(W),-u));
108
  W = fliplr(triu(fliplr(W),-u));
109
109
110
# incremental Loss Ratios AD
110
  # incremental Loss Ratios AD
111
LRI_AD  = diag(LRI' * W)';                  #weighted product
111
  LRI_AD  = diag(LRI' * W)';                  #weighted product
112
112
113
if (u==0)
113
  if (u==0)
114
b = (diag(fliplr(S),-u) ./ flipud(cumsum(LRI_AD)') ) ./ V;
114
  b = (diag(fliplr(S),-u) ./ flipud(cumsum(LRI_AD)') ) ./ V;
115
else
115
  else
116
b = ([S(1:u,n); diag(fliplr(S),-u)] ./ [sum(LRI_AD)*ones(1,u);flipud(cumsum(LRI_AD)')] ) ./ V;
116
  b = ([S(1:u,n); diag(fliplr(S),-u)] ./ [sum(LRI_AD)*ones(1,u);flipud(cumsum(LRI_AD)')] ) ./ V;
117
end
117
  end
118
118
119
sZ = sum (Z);                              #sum of Z
119
  sZ = sum (Z);                              #sum of Z
120
sb = repmat(b,1,n);
120
  sb = repmat(b,1,n);
121
sb = fliplr(triu(fliplr(sb),-u));
121
  sb = fliplr(triu(fliplr(sb),-u));
122
sV = repmat(V,1,n);
122
  sV = repmat(V,1,n);
123
sV = fliplr(triu(fliplr(sV),-u));
123
  sV = fliplr(triu(fliplr(sV),-u));
124
124
125
LRI_Mack = sZ ./ (diag(sb'*sV))';
125
  LRI_Mack = sZ ./ (diag(sb'*sV))';
126
quotas = cumsum(porcentual(LRI_Mack));     #calculate cumulated  quota  
126
  quotas = cumsum(porcentual(LRI_Mack));     #calculate cumulated  quota
127
127
128
end
128
end