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

Switch to unified view

a b/inst/bfanalisis.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}, @var{outcome} =} bfanalisis (@var{S}, @var{V}, @var{quota_ext}, @var{ultimate_ext})
19
## Calculate the extended Bornhuetter-Ferguson method for reserves in many ways. If all arguments are provided,
20
## it calculates 30 different estimations included in the @var{outcome} structure. It also returns the @var{quotas} used.
21
## 
22
##@var{outcome} had two levels:
23
##
24
##@group
25
##level 1: Type of Ultimate
26
## list of posible estimative methods:
27
##@example
28
##@multitable {xxxxxxxxxxxxx} {xxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxx} {xxxxxxxxxxxxxxxxx}
29
##@headitem FLAG @tab METHOD @tab REQUIRES @tab RELATED FUNCTION
30
##@item ultad       @tab Loss Ratio AD    @tab S,V          @tab  ultimatead.m       
31
##@item ultcc       @tab Cape Cod         @tab S,V          @tab  ultimatecc.m       
32
##@item ultexternal @tab none             @tab ultimate_ext @tab  none               
33
##@item ultld       @tab Loss Development @tab S            @tab  ultimateld.m       
34
##@item ultmack     @tab Mack             @tab S,V          @tab  ultimatemack.m     
35
##@item ultpanning  @tab Panning          @tab S            @tab  ultimatepanning.m  
36
##@end multitable
37
##@end example
38
##@end group
39
##@group
40
##level 2: Type of Quotas
41
## list of posible estimative methods:
42
##@example
43
##
44
##@multitable {xxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxx} {xxxxxxxxxxxxxxxxxx}
45
##@headitem FLAG @tab METHOD @tab REQUIRES @tab RELATED FUNCTION 
46
##@item quotasad         @tab  Loss Ratio AD    @tab S,V       @tab  quotaad.m          
47
##@item quotasexternal   @tab  none             @tab quota_ext @tab  none               
48
##@item quotasld         @tab  Loss Development @tab S         @tab  quotald.m          
49
##@item quotasmack       @tab  Mack             @tab S,V       @tab  quotamack.m        
50
##@item quotaspanning    @tab  Panning          @tab S         @tab  quotapanning.m
51
##@end multitable
52
##@end example
53
##@end group
54
##
55
## Parameters:
56
## @var{S} is a mxn matrix that contains the run-off triangle, where m is the number of accident-years
57
## and n is the number of periods to final development. @var{s} may contain u = m-n complete years.
58
## Optional:
59
## @var{v} is an mx1 vector of known volume measures (like premiums or the number of contracts).
60
## @var{quota_ext} is an 1xn vector with an external scheme of quotas.
61
## @group
62
## @example
63
## 
64
##                E[S(i,k+1)]
65
## quota(k) =   -------------,    k={0,1,n-1}
66
##                E[S(i,n) ]
67
##
68
## @end example
69
## @end group
70
## @var{ultimate_ext} is a mx1 vector wuth an external estimatios of the ultimate column.
71
##
72
##
73
## @seealso {bferguson}
74
## @end deftypefn
75
## @bye
76
77
## Author: Act. Esteban Cervetto ARG <estebancster@gmail.com>
78
##
79
## Maintainer: Act. Esteban Cervetto ARG <estebancster@gmail.com>
80
##
81
## Created: jul-2009
82
##
83
## Version: 1.1.0 
84
##
85
## Keywords: actuarial reserves insurance bornhuetter ferguson chainladder
86
87
function [quotas,outcome] = bfanalisis (S,V,quota_ext,ultimate_ext)
88
89
#check number of arguments in
90
if (nargin==0)
91
 usage("insuficient args. Enter a mxn triangle of losses at least");
92
else
93
 #check S 
94
 [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)
95
 u = m - n;                                        #rows of the upper square
96
 S = fliplr(triu(fliplr(S),-u));                   #ensure S is triangular  
97
 quotas.ld = quotald(S);                           #quotas LD
98
 quotas.panning = quotapanning(S);                 #Panning quotas
99
 for k=1:n
100
  outcome.ultld.quotasld(:,k) = bferguson(S,quotas.ld,ultimateld(S,quotas.ld),k-1);
101
  outcome.ultld.quotaspanning(:,k) = bferguson(S,quotas.panning,ultimateld(S,quotas.panning),k-1);
102
  outcome.ultpanning.quotasld(:,k) = bferguson(S,quotas.ld,ultimatepanning(S,quotas.ld),k-1);
103
  outcome.ultpanning.quotaspanning(:,k) = bferguson(S,quotas.panning,ultimatepanning(S,quotas.panning),k-1);
104
 endfor
105
 
106
 if (nargin>1)
107
  # verify V
108
  if (size(V) ~= [m,1])
109
   usage(strcat("volume V must be of size [",num2str(m),",1]" ));
110
  else 
111
  for k=1:n   
112
  quotas.ad = quotaad(S,V);                                #quotas AD
113
  quotas.mack = quotamack(S,V);                            #quotas Mack  
114
  outcome.ultld.quotasad(:,k) = bferguson(S,quotas.ad,ultimateld(S,quotas.ad),k-1);
115
  outcome.ultld.quotasmack(:,k) = bferguson(S,quotas.mack,ultimateld(S,quotas.mack),k-1);
116
  outcome.ultpanning.quotasad(:,k) = bferguson(S,quotas.ad,ultimatepanning(S,quotas.ad),k-1);
117
  outcome.ultpanning.quotasmack(:,k) = bferguson(S,quotas.mack,ultimatepanning(S,quotas.mack),k-1);  
118
  outcome.ultad.quotasld(:,k) = bferguson(S,quotas.ld,ultimatead(S,V),k-1);
119
  outcome.ultad.quotaspanning(:,k) = bferguson(S,quotas.panning,ultimatead(S,V),k-1);
120
  outcome.ultad.quotasad(:,k) = bferguson(S,quotas.ad,ultimatead(S,V),k-1);
121
  outcome.ultad.quotasmack(:,k) = bferguson(S,quotas.mack,ultimatead(S,V),k-1);
122
  outcome.ultcc.quotasld(:,k) = bferguson(S,quotas.ld,ultimatecc(S,V,quotas.ld),k-1);
123
  outcome.ultcc.quotaspanning(:,k) = bferguson(S,quotas.panning,ultimatecc(S,V,quotas.panning),k-1);
124
  outcome.ultcc.quotasad(:,k) = bferguson(S,quotas.ad,ultimatecc(S,V,quotas.ad),k-1);
125
  outcome.ultcc.quotasmack(:,k) = bferguson(S,quotas.mack,ultimatecc(S,V,quotas.mack),k-1);
126
  outcome.ultmack.quotasld(:,k) = bferguson(S,quotas.ld,ultimatemack(S,V),k-1);
127
  outcome.ultmack.quotaspanning(:,k) = bferguson(S,quotas.panning,ultimatemack(S,V),k-1);
128
  outcome.ultmack.quotasad(:,k) = bferguson(S,quotas.ad,ultimatemack(S,V),k-1);
129
  outcome.ultmack.quotasmack(:,k) = bferguson(S,quotas.mack,ultimatemack(S,V),k-1);  
130
  endfor
131
  if (nargin>2)
132
   #check out quota_ext
133
   if (size(quota_ext) ~= [1,n])
134
     usage(strcat("quota_ext must be of size [1,",num2str(n),"]" ));
135
   else
136
     for k=1:n     
137
     quotas.external = quota_ext;                           #external quotas      
138
     outcome.ultld.quotasexternal(:,k) = bferguson(S,quotas.external,ultimateld(S,quotas.external),k-1);      
139
     outcome.ultpanning.quotasexternal(:,k) = bferguson(S,quotas.external,ultimatepanning(S,quotas.external),k-1);
140
     outcome.ultad.quotasexternal(:,k) = bferguson(S,quotas.external,ultimatead(S,V),k-1);
141
     outcome.ultcc.quotasexternal(:,k) = bferguson(S,quotas.external,ultimatecc(S,V,quotas.external),k-1);
142
     outcome.ultmack.quotasexternal(:,k) = bferguson(S,quotas.external,ultimatemack(S,V),k-1);
143
     endfor
144
     if (nargin>3)
145
      #verify ultimate_ext
146
      if (size(ultimate_ext) ~= [m,1])
147
       usage(strcat("ultimate_ext must be of size [",num2str(m),",1]" ));
148
      else 
149
        for k=1:n
150
        outcome.ultexternal.quotasld(:,k) = bferguson(S,quotas.ld,ultimate_ext,k-1);
151
        outcome.ultexternal.quotaspanning(:,k) = bferguson(S,quotas.panning,ultimate_ext,k-1);
152
        outcome.ultexternal.quotasad(:,k) = bferguson(S,quotas.ad,ultimate_ext,k-1);
153
        outcome.ultexternal.quotasmack(:,k) = bferguson(S,quotas.mack,ultimate_ext,k-1);
154
        outcome.ultexternal.quotasexternal(:,k) = bferguson(S,quotas.external,ultimate_ext,k-1);
155
        endfor
156
      end
157
    end   
158
   end    
159
  end
160
 end 
161
end
162
163
end

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks