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

  Switch to unified view

a/inst/quotaad.m b/inst/quotaad.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 Additive method.
19
## Calculate the cumulative quotas by the Additive 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
...
...
54
## @seealso {bferguson, quotald, quotapanning}
54
## @seealso {bferguson, quotald, quotapanning}
55
## @end deftypefn
55
## @end deftypefn
56
56
57
function [quotas] = quotaad (S,V)
57
function [quotas] = quotaad (S,V)
58
58
59
[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)
59
  [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)
60
u = m - n;                                     #rows of the upper square
60
  u = m - n;                                     #rows of the upper square
61
S = fliplr(triu(fliplr(S),-u));                   #ensure S is triangular  
61
  S = fliplr(triu(fliplr(S),-u));                   #ensure S is triangular
62
if (size(V) ~= [m,1])
62
  if (size(V) ~= [m,1])
63
 usage(strcat("volume V must be of size [",num2str(m),",1]" ));
63
    error(strcat("volume V must be of size [",num2str(m),",1]" ));
64
end
64
  end
65
65
66
# Z triangle
66
  # Z triangle
67
Z = [S(:,1), S(:,2:n)-S(:,1:n-1)];
67
  Z = [S(:,1), S(:,2:n)-S(:,1:n-1)];
68
Z = fliplr(triu(fliplr(Z),-u));                #clean Z
68
  Z = fliplr(triu(fliplr(Z),-u));                #clean Z
69
69
70
# calc the empirical incremental loss ratios
70
  # calc the empirical incremental loss ratios
71
LRI = Z ./ repmat (V,1,n);
71
  LRI = Z ./ repmat (V,1,n);
72
 
73
#weights V(i)/sum(1,n-k,V(i))
74
W = repmat(V,1,n);                             #numerator
75
W =fliplr(triu(fliplr(W),-u));                 #clean low triangle
76
a = repmat(sum(W),m,1);                        #denominator
77
a = fliplr(triu(fliplr(a),-u));                #clean low triangle
78
W = W./a;                                      #divide by
79
W = fliplr(triu(fliplr(W),-u));
80
72
73
  #weights V(i)/sum(1,n-k,V(i))
74
  W = repmat(V,1,n);                             #numerator
75
  W =fliplr(triu(fliplr(W),-u));                 #clean low triangle
76
  a = repmat(sum(W),m,1);                        #denominator
77
  a = fliplr(triu(fliplr(a),-u));                #clean low triangle
78
  W = W./a;                                      #divide by
79
  W = fliplr(triu(fliplr(W),-u));
80
81
# incremental Loss Ratios AD
81
  # incremental Loss Ratios AD
82
LRI_AD  = diag(LRI' * W)';                     #weighted product
82
  LRI_AD = diag(LRI' * W)';                     #weighted product
83
quotas = cumsum(porcentual(LRI_AD));           #calc cumulated quota 
83
  quotas = cumsum(porcentual(LRI_AD));           #calc cumulated quota 
84
84
85
end
85
end