Create a gist now

Instantly share code, notes, and snippets.

claim_model_2.R
##actuarパッケージの読み込み
library(actuar)
##パンジャーの再帰式でクレーム総額分布を求める
#まずクレーム額分布(平均10の指数分布)を離散化
fx=discretize(pgamma(x,1,0.1),from=0, to=500,step=0.25,method="unbiased",lev=levgamma(x,1,0.1))
fx0=fx[1]
fs=rep(0,2001)
fs[1]=0.1
fs[2]=0.9*(fx[2]*fs[1])/(1-0.9*fx0)
fs[3]=0.9*(fx[3]*fs[1]+fx[2]*fs[2])/(1-0.9*fx0)
for(i in 2:2001){
k=rep(0,2001)
for(j in 2:i){
k[j]=fx[j]*fs[i-j+1]
}
fs[i]=sum(k)*0.9/(1-0.9*fx0)
}
T=seq(0, 500, by = 0.25)
FFs=cumsum(fs)
plot(T,FFs,xlim=c(0,500),ylim=c(0,1),col=1,type="l")
#理論値を赤線で書く
curve(1-0.9*exp(-0.01*x),0,500,add=TRUE,col=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment