Definitions

DiscretizeDistribution[f_,h_,xmin_,xmax_]:= Module[{points,result},
points = NestWhileList[(#+h)&,xmin, (#<xmax)&];
result=Prepend[NIntegrate[f[x],{x,Max[0,#-(h/2)],#+(h/2)}]&/@points,0];
Print["Discretized on interval (",xmin, ", ", xmax, ") by ", Length[result], " grid points"];
Print["Discretized distribution sums to ",Total[result]];
result
]
GenFunc[discretized_,variable_]:= ((variable^(#))&/@Range[0,Length[discretized]-1]).discretized
ExtractCoefficients[F_]:= Module[{expr,result},
Print["Expanding expression"];
expr=Expand[F[z]]//Chop;
Print["Calculating coefficients"];
result=Prepend[Coefficient[expr,(z^(#))]&/@Range[1,Length[expr]-1],F[0]];
Print["Calculated ", Length[result], " coefficients, with the total sum ", Total[result]];
result
]
FindQuantile[Fs_]:= Transpose[{Fs,Range[Length[Fs]]}]
GetRange[Qs_]:=Module[{p0,p1,rng},
p0=Min[Qs[[All,1]]];
p1=Max[Qs[[All,1]]];
rng=p1-p0;
p0 = p0+rng/20;
p1=p1-rng/20;
{p0,p1}
]
VaR[Qs_,α_]:=Interpolation[Qs][α]
cVaR[fs_,Qs_,α_]:=Module[{table,p0,p1},
{p0,p1}=GetRange[Qs];
table= Table[{β,(1/(1-β))Sum[n fs[[n]],{n,Round[VaR[Qs,β]],Length[fs]}]},{β,p0,p1,((p1-p0)/100)}];
Interpolation[table][α]
]

Poisson

Exponencialni

Exponencialni, θ = 0.1

Exit[]

valuesExp = {λ->0.02, θ->0.1,α->0.98};
initialValueP = {f0->(E^(-θ))};

(* Exponential distribution *)
gExp[x_] = λ (E^(-λ x))/.valuesExp;
gDiscreteExp = DiscretizeDistribution[gExp,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GExp[z_] = GenFunc[gDiscreteExp,z];

(* Poisson is already discrete, we define just the list of probabilities *)
PoissonExp = Table[ ((θ^n)/(n!))(E^(-θ))/.valuesExp,{n,0,20}]//Chop;
(* and define generating function*)
PExp[z_]=GenFunc[PoissonExp,z];

FExp[z_]=PExp[GExp[z]]; (* Panjer formula *)
fsExp=ExtractCoefficients[FExp]; (* get the coefficients of generating function F *)
FsExp=Accumulate[fsExp];

ListLinePlot[ FsExp,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsExp],1}}]}]

QsExp = FindQuantile[FsExp];

ListLinePlot[QsExp,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsExp] (* this should be reliable interval on which we can interpolate *)

varExp = VaR[QsExp,α/.valuesExp]

cvarExp=cVaR[fsExp,QsExp,α/.valuesExp]

alphas =Range[p0+0.001,p1-0.001,((p1-p0)/30)];
grafVarExp=Transpose[{alphas,VaR[QsExp,#]&/@alphas}];
grafCvarExp=Transpose[{alphas,cVaR[fsExp,QsExp,#]&/@alphas}];

ListLinePlot[{grafVarExp,grafCvarExp},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Exponencialni, θ = 0.05

Exit[]

valuesExp05 = {λ->0.02, θ->0.05,α->0.98};
initialValueP = {f0->(E^(-θ))};

(* Exponential distribution *)
gExp[x_] = λ (E^(-λ x))/.valuesExp05;
gDiscreteExp = DiscretizeDistribution[gExp,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GExp[z_] = GenFunc[gDiscreteExp,z];

(* Poisson is already discrete, we define just the list of probabilities *)
PoissonExp05 = Table[ ((θ^n)/(n!))(E^(-θ))/.valuesExp05,{n,0,20}]//Chop;
(* and define generating function*)
PExp05[z_]=GenFunc[PoissonExp05,z];

FExp05[z_]=PExp05[GExp[z]]; (* Panjer formula *)
fsExp05=ExtractCoefficients[FExp05]; (* get the coefficients of generating function F *)
FsExp05=Accumulate[fsExp05];

ListLinePlot[ FsExp05,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsExp05],1}}]}]

QsExp05 = FindQuantile[FsExp05];

ListLinePlot[QsExp05,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsExp05] (* this should be reliable interval on which we can interpolate *)

varExp05 = VaR[QsExp05,α/.valuesExp05]

cvarExp05=cVaR[fsExp05,QsExp05,α/.valuesExp05]

alphas =Range[p0+0.001,p1-0.001,((p1-p0)/30)];
grafVarExp05=Transpose[{alphas,VaR[QsExp05,#]&/@alphas}];
grafCvarExp05=Transpose[{alphas,cVaR[fsExp05,QsExp05,#]&/@alphas}];

ListLinePlot[{grafVarExp05,grafCvarExp05},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Exponencialni, θ = 0.15

Exit[]

valuesExp15 = {λ->0.02, θ->0.15,α->0.98};
initialValueP = {f0->(E^(-θ))};

(* Exponential distribution *)
gExp[x_] = λ (E^(-λ x))/.valuesExp15;
gDiscreteExp = DiscretizeDistribution[gExp,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GExp[z_] = GenFunc[gDiscreteExp,z];

(* Poisson is already discrete, we define just the list of probabilities *)
PoissonExp15 = Table[ ((θ^n)/(n!))(E^(-θ))/.valuesExp15,{n,0,20}]//Chop;
(* and define generating function*)
PExp15[z_]=GenFunc[PoissonExp15,z];

FExp15[z_]=PExp15[GExp[z]]; (* Panjer formula *)
fsExp15=ExtractCoefficients[FExp15]; (* get the coefficients of generating function F *)
FsExp15=Accumulate[fsExp15];

ListLinePlot[ FsExp15,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsExp15],1}}]}]

QsExp15 = FindQuantile[FsExp15];

ListLinePlot[QsExp15,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsExp15] (* this should be reliable interval on which we can interpolate *)

varExp15 = VaR[QsExp15,α/.valuesExp15]

cvarExp15=cVaR[fsExp15,QsExp15,α/.valuesExp15]

alphas =Range[p0+0.001,p1-0.001,((p1-p0)/30)];
grafVarExp15=Transpose[{alphas,VaR[QsExp15,#]&/@alphas}];
grafCvarExp15=Transpose[{alphas,cVaR[fsExp15,QsExp15,#]&/@alphas}];

ListLinePlot[{grafVarExp15,grafCvarExp15},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Dohromady

Show[ListLinePlot[ FsExp15,PlotRange->Full,PlotStyle->Blue,PlotLegends->{"(Subscript[F, S])(n), θ = 0.15"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsExp15],1}}]}],ListLinePlot[ FsExp,PlotRange->Full,PlotStyle->Red,PlotLegends->{"(Subscript[F, S])(n), θ = 0.1"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsExp],1}}]}],ListLinePlot[ FsExp05,PlotRange->Full,PlotStyle->Green,PlotLegends->{"(Subscript[F, S])(n), θ = 0.05"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsExp05],1}}]}]]

Show[ListLinePlot[{grafVarExp05,grafCvarExp05},PlotRange->{{0.955,0.99},{0,1020}},PlotStyle->{Green,{Green,Dashed}},PlotLegends->{"VaR, θ = 0.05","CVaR, θ = 0.05"},AxesLabel->{"α"}],ListLinePlot[{grafVarExp,grafCvarExp},PlotStyle->{Red,{Red,Dashed}},PlotLegends->{"VaR, θ = 0.1","CVaR, θ = 0.1"},AxesLabel->{"α"}],ListLinePlot[{grafVarExp15,grafCvarExp15},PlotStyle->{Blue,{Blue,Dashed}},PlotLegends->{"VaR, θ = 0.15","CVaR, θ = 0.15"},AxesLabel->{"α"}]]

Gama

Gama, θ = 0.1

Exit[]

valuesGam = {p->10,λ->1, θ->0.1,α->0.99};
initialValueP = {f0->(E^(-θ))};

(* Gamma distribution *)
gGam[x_] =  ((λ^p)/(Gamma[p]))(x^(p-1)) (E^(-λ x ))/.valuesGam;
gDiscreteGam = DiscretizeDistribution[gGam,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GGam[z_] = GenFunc[gDiscreteGam,z];

(* Poisson is already discrete, we define just the list of probabilities *)
PoissonGam = Table[ ((θ^n)/(n!))(E^(-θ))/.valuesGam,{n,0,20}]//Chop;
(* and define generating function*)
PGam[z_]=GenFunc[PoissonGam,z];

FGam[z_]=PGam[GGam[z]]; (* Panjer formula *)
fsGam=ExtractCoefficients[FGam]; (* get the coefficients of generating function F *)
FsGam=Accumulate[fsGam];

ListLinePlot[ FsGam,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsGam],1}}]}]

QsGam = FindQuantile[FsGam];

ListLinePlot[QsGam,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsGam] (* this should be reliable interval on which we can interpolate *)

pomocneQsGam=Drop[QsGam,34];

varGam = VaR[pomocneQsGam,α/.valuesGam] (*at the beginning of the interval, the interpolation fails - it is need to be cut off*)

cvarGam=cVaR[fsGam,pomocneQsGam,α/.valuesGam]

alphas =Range[p0+0.01,p1-0.01,((p1-p0)/30)];
grafVarGam=Transpose[{alphas,VaR[pomocneQsGam,#]&/@alphas}];
grafCvarGam=Transpose[{alphas,cVaR[fsGam,pomocneQsGam,#]&/@alphas}];

ListLinePlot[{grafVarGam,grafCvarGam},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Gama, θ = 0.05

Exit[]

valuesGam05 = {p->10,λ->1, θ->0.05,α->0.99};
initialValueP = {f0->(E^(-θ))};

(* Gamma distribution *)
gGam[x_] =  ((λ^p)/(Gamma[p]))(x^(p-1)) (E^(-λ x ))/.valuesGam05;
gDiscreteGam = DiscretizeDistribution[gGam,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GGam[z_] = GenFunc[gDiscreteGam,z];

(* Poisson is already discrete, we define just the list of probabilities *)
PoissonGam05 = Table[ ((θ^n)/(n!))(E^(-θ))/.valuesGam05,{n,0,20}]//Chop;
(* and define generating function*)
PGam05[z_]=GenFunc[PoissonGam05,z];

FGam05[z_]=PGam05[GGam[z]]; (* Panjer formula *)
fsGam05=ExtractCoefficients[FGam05]; (* get the coefficients of generating function F *)
FsGam05=Accumulate[fsGam05];

ListLinePlot[ FsGam05,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsGam05],1}}]}]

QsGam05 = FindQuantile[FsGam05];

ListLinePlot[QsGam05,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsGam05] (* this should be reliable interval on which we can interpolate *)

pomocneQsGam05=Drop[QsGam05,34];

varGam05 = VaR[pomocneQsGam05,α/.valuesGam05] (*at the beginning of the interval, the interpolation fails - it is need to be cut off*)

cvarGam05=cVaR[fsGam05,pomocneQsGam05,α/.valuesGam05]

alphas =Range[p0+0.01,p1-0.01,((p1-p0)/30)];
grafVarGam05=Transpose[{alphas,VaR[pomocneQsGam05,#]&/@alphas}];
grafCvarGam05=Transpose[{alphas,cVaR[fsGam05,pomocneQsGam05,#]&/@alphas}];

ListLinePlot[{grafVarGam05,grafCvarGam05},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Gama, θ = 0.15

Exit[]

valuesGam15 = {p->10,λ->1, θ->0.15,α->0.99};
initialValueP = {f0->(E^(-θ))};

(* Gamma distribution *)
gGam[x_] =  ((λ^p)/(Gamma[p]))(x^(p-1)) (E^(-λ x ))/.valuesGam15;
gDiscreteGam = DiscretizeDistribution[gGam,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GGam[z_] = GenFunc[gDiscreteGam,z];

(* Poisson is already discrete, we define just the list of probabilities *)
PoissonGam15 = Table[ ((θ^n)/(n!))(E^(-θ))/.valuesGam15,{n,0,20}]//Chop;
(* and define generating function*)
PGam15[z_]=GenFunc[PoissonGam15,z];

FGam15[z_]=PGam15[GGam[z]]; (* Panjer formula *)
fsGam15=ExtractCoefficients[FGam15]; (* get the coefficients of generating function F *)
FsGam15=Accumulate[fsGam15];

ListLinePlot[ FsGam15,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsGam15],1}}]}]

QsGam15 = FindQuantile[FsGam15];

ListLinePlot[QsGam15,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsGam15] (* this should be reliable interval on which we can interpolate *)

pomocneQsGam15=Drop[QsGam15,34];

varGam15 = VaR[pomocneQsGam15,α/.valuesGam15] (*at the beginning of the interval, the interpolation fails - it is need to be cut off*)

cvarGam15=cVaR[fsGam15,pomocneQsGam15,α/.valuesGam15]

alphas =Range[p0+0.01,p1-0.01,((p1-p0)/30)];
grafVarGam15=Transpose[{alphas,VaR[pomocneQsGam15,#]&/@alphas}];
grafCvarGam15=Transpose[{alphas,cVaR[fsGam15,pomocneQsGam15,#]&/@alphas}];

ListLinePlot[{grafVarGam15,grafCvarGam15},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Dohromady

Show[ListLinePlot[ FsGam15,PlotRange->Full,PlotStyle->Blue,PlotLegends->{"(Subscript[F, S])(n), θ = 0.15"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsGam15],1}}]}],ListLinePlot[ FsGam,PlotRange->Full,PlotStyle->Red,PlotLegends->{"(Subscript[F, S])(n), θ = 0.1"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsGam],1}}]}],ListLinePlot[ FsGam05,PlotRange->Full,PlotStyle->Green,PlotLegends->{"(Subscript[F, S])(n), θ = 0.05"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsGam05],1}}]}]]

Show[ListLinePlot[{grafVarGam05,grafCvarGam05},PlotRange->{{0.964,0.982},{45,130}},PlotStyle->{Green,{Green,Dashed}},PlotLegends->{"VaR, θ = 0.05","CVaR, θ = 0.05"},AxesLabel->{"α"}],ListLinePlot[{grafVarGam,grafCvarGam},PlotStyle->{Red,{Red,Dashed}},PlotLegends->{"VaR, θ = 0.1","CVaR, θ = 0.1"},AxesLabel->{"α"}],ListLinePlot[{grafVarGam15,grafCvarGam15},PlotStyle->{Blue,{Blue,Dashed}},PlotLegends->{"VaR, θ = 0.15","CVaR, θ = 0.15"},AxesLabel->{"α"}]]

Pareto

Pareto, θ = 0.1

Exit[]

valuesPar = {λ->4,a->200, θ->0.1,α->0.98};
initialValueP= {f0->(E^(-θ))};

(* Exponential distribution *)
gPar[x_] =  λ (a^λ)(((x+a))^(-(λ+1)))/.valuesPar;
gDiscretePar = DiscretizeDistribution[gPar,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GPar[z_] = GenFunc[gDiscretePar,z];

(* Poisson is already discrete, we define just the list of probabilities *)
PoissonPar = Table[ ((θ^n)/(n!))(E^(-θ))/.valuesPar,{n,0,20}]//Chop;
(* and define generating function*)
PPar[z_]=GenFunc[PoissonPar,z];

FPar[z_]=PPar[GPar[z]]; (* Panjer formula *)
fsPar=ExtractCoefficients[FPar]; (* get the coefficients of generating function F *)
FsPar=Accumulate[fsPar];

ListLinePlot[ FsPar,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsPar],1}}]}]

QsPar = FindQuantile[FsPar];

ListLinePlot[QsPar,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsPar] (* this should be reliable interval on which we can interpolate *)

varPar = VaR[QsPar,α/.valuesPar]

cvarPar=cVaR[fsPar,QsPar,α/.valuesPar]

alphas =Range[p0+0.005,p1-0.005,((p1-p0)/30)];
grafVarPar=Transpose[{alphas,VaR[QsPar,#]&/@alphas}];
grafCvarPar=Transpose[{alphas,cVaR[fsPar,QsPar,#]&/@alphas}];

ListLinePlot[{grafVarPar,grafCvarPar},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Pareto, θ = 0.05

Exit[]

valuesPar05 = {λ->4,a->200, θ->0.05,α->0.98};
initialValueP= {f0->(E^(-θ))};

(* Exponential distribution *)
gPar[x_] =  λ (a^λ)(((x+a))^(-(λ+1)))/.valuesPar05;
gDiscretePar = DiscretizeDistribution[gPar,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GPar[z_] = GenFunc[gDiscretePar,z];

(* Poisson is already discrete, we define just the list of probabilities *)
PoissonPar05 = Table[ ((θ^n)/(n!))(E^(-θ))/.valuesPar05,{n,0,20}]//Chop;
(* and define generating function*)
PPar05[z_]=GenFunc[PoissonPar05,z];

FPar05[z_]=PPar05[GPar[z]]; (* Panjer formula *)
fsPar05=ExtractCoefficients[FPar05]; (* get the coefficients of generating function F *)
FsPar05=Accumulate[fsPar05];

ListLinePlot[ FsPar05,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsPar05],1}}]}]

QsPar05 = FindQuantile[FsPar05];

ListLinePlot[QsPar05,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsPar05] (* this should be reliable interval on which we can interpolate *)

varPar05 = VaR[QsPar05,α/.valuesPar05]

cvarPar05=cVaR[fsPar05,QsPar05,α/.valuesPar05]

alphas =Range[p0+0.005,p1-0.005,((p1-p0)/30)];
grafVarPar05=Transpose[{alphas,VaR[QsPar05,#]&/@alphas}];
grafCvarPar05=Transpose[{alphas,cVaR[fsPar05,QsPar05,#]&/@alphas}];

ListLinePlot[{grafVarPar05,grafCvarPar05},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Pareto, θ = 0.15

Exit[]

valuesPar15 = {λ->4,a->200, θ->0.15,α->0.98};
initialValueP= {f0->(E^(-θ))};

(* Exponential distribution *)
gPar[x_] =  λ (a^λ)(((x+a))^(-(λ+1)))/.valuesPar15;
gDiscretePar = DiscretizeDistribution[gPar,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GPar[z_] = GenFunc[gDiscretePar,z];

(* Poisson is already discrete, we define just the list of probabilities *)
PoissonPar15 = Table[ ((θ^n)/(n!))(E^(-θ))/.valuesPar15,{n,0,20}]//Chop;
(* and define generating function*)
PPar15[z_]=GenFunc[PoissonPar15,z];

FPar15[z_]=PPar15[GPar[z]]; (* Panjer formula *)
fsPar15=ExtractCoefficients[FPar15]; (* get the coefficients of generating function F *)
FsPar15=Accumulate[fsPar15];

ListLinePlot[ FsPar15,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsPar15],1}}]}]

QsPar15 = FindQuantile[FsPar15];

ListLinePlot[QsPar15,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsPar15] (* this should be reliable interval on which we can interpolate *)

varPar15 = VaR[QsPar15,α/.valuesPar15]

cvarPar15=cVaR[fsPar15,QsPar15,α/.valuesPar15]

alphas =Range[p0+0.005,p1-0.005,((p1-p0)/30)];
grafVarPar15=Transpose[{alphas,VaR[QsPar15,#]&/@alphas}];
grafCvarPar15=Transpose[{alphas,cVaR[fsPar15,QsPar15,#]&/@alphas}];

ListLinePlot[{grafVarPar15,grafCvarPar15},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Dohromady

Show[ListLinePlot[ FsPar15,PlotRange->Full,PlotStyle->Blue,PlotLegends->{"(Subscript[F, S])(n), θ = 0.15"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsPar15],1}}]}],ListLinePlot[ FsPar,PlotRange->Full,PlotStyle->Red,PlotLegends->{"(Subscript[F, S])(n), θ = 0.1"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsPar],1}}]}],ListLinePlot[ FsPar05,PlotRange->Full,PlotStyle->Green,PlotLegends->{"(Subscript[F, S])(n), θ = 0.05"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsPar05],1}}]}]]

Show[ListLinePlot[{grafVarPar05,grafCvarPar05},PlotRange->{{0.959,0.982},{0,1000}},PlotStyle->{Green,{Green,Dashed}},PlotLegends->{"VaR, θ = 0.05","CVaR, θ = 0.05"},AxesLabel->{"α"}],ListLinePlot[{grafVarPar,grafCvarPar},PlotStyle->{Red,{Red,Dashed}},PlotLegends->{"VaR, θ = 0.1","CVaR, θ = 0.1"},AxesLabel->{"α"}],ListLinePlot[{grafVarPar15,grafCvarPar15},PlotStyle->{Blue,{Blue,Dashed}},PlotLegends->{"VaR, θ = 0.15","CVaR, θ = 0.15"},AxesLabel->{"α"}]]

Logaritmicko - normalni

Logaritmicko-normalni, θ = 0.1

Exit[]

valuesLN= {μ->3,rozptyl->2, θ->0.1,α->0.98};
initialValueP = {f0->(E^(-θ))};

(* Gamma distribution *)
gLN[x_] = (1/((Sqrt[2π rozptyl])x)) (E^(((-(((Log[x]-μ))^2))/(2 rozptyl)) ))/.valuesLN;
gDiscreteLN= DiscretizeDistribution[gLN,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GLN[z_] = GenFunc[gDiscreteLN,z];

(* Poisson is already discrete, we define just the list of probabilities *)
PoissonLN = Table[ ((θ^n)/(n!))(E^(-θ))/.valuesLN,{n,0,20}]//Chop;
(* and define generating function*)
PLN[z_]=GenFunc[PoissonLN,z];

FLN[z_]=PLN[GLN[z]]; (* Panjer formula *)
fsLN=ExtractCoefficients[FLN]; (* get the coefficients of generating function F *)
FsLN=Accumulate[fsLN];

ListLinePlot[ FsLN,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsLN],1}}]}]

QsLN = FindQuantile[FsLN];

ListLinePlot[QsLN,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsLN] (* this should be reliable interval on which we can interpolate *)

varLN = VaR[QsLN,α/.valuesLN] (*at the beginning of the interval, the interpolation fails - it is need to be cut off*)

cvarLN=cVaR[fsLN,QsLN,α/.valuesLN]

alphas =Range[p0+0.01,p1-0.01,((p1-p0)/30)];
grafVarLN=Transpose[{alphas,VaR[QsLN,#]&/@alphas}];
grafCvarLN=Transpose[{alphas,cVaR[fsLN,QsLN,#]&/@alphas}];

ListLinePlot[{grafVarLN,grafCvarLN},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Logaritmicko-normalni, θ = 0.05

Exit[]

valuesLN05= {μ->3,rozptyl->2, θ->0.05,α->0.98};
initialValueP = {f0->(E^(-θ))};

(* Gamma distribution *)
gLN[x_] = (1/((Sqrt[2π rozptyl])x)) (E^(((-(((Log[x]-μ))^2))/(2 rozptyl)) ))/.valuesLN05;
gDiscreteLN= DiscretizeDistribution[gLN,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GLN[z_] = GenFunc[gDiscreteLN,z];

(* Poisson is already discrete, we define just the list of probabilities *)
PoissonLN05 = Table[ ((θ^n)/(n!))(E^(-θ))/.valuesLN05,{n,0,20}]//Chop;
(* and define generating function*)
PLN05[z_]=GenFunc[PoissonLN05,z];

FLN05[z_]=PLN05[GLN[z]]; (* Panjer formula *)
fsLN05=ExtractCoefficients[FLN05]; (* get the coefficients of generating function F *)
FsLN05=Accumulate[fsLN05];

ListLinePlot[FsLN05,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsLN05],1}}]}]

QsLN05 = FindQuantile[FsLN05];

ListLinePlot[QsLN05,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsLN05] (* this should be reliable interval on which we can interpolate *)

varLN05 = VaR[QsLN05,α/.valuesLN05] (*at the beginning of the interval, the interpolation fails - it is need to be cut off*)

cvarLN05=cVaR[fsLN05,QsLN05,α/.valuesLN05]

alphas =Range[p0+0.001,p1-0.001,((p1-p0)/30)];
grafVarLN05=Transpose[{alphas,VaR[QsLN05,#]&/@alphas}];
grafCvarLN05=Transpose[{alphas,cVaR[fsLN05,QsLN05,#]&/@alphas}];

ListLinePlot[{grafVarLN05,grafCvarLN05},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Logaritmicko-normalni, θ = 0.15

Exit[]

valuesLN15= {μ->3,rozptyl->2, θ->0.15,α->0.98};
initialValueP = {f0->(E^(-θ))};

(* Gamma distribution *)
gLN[x_] = (1/((Sqrt[2π rozptyl])x)) (E^(((-(((Log[x]-μ))^2))/(2 rozptyl)) ))/.valuesLN15;
gDiscreteLN= DiscretizeDistribution[gLN,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GLN[z_] = GenFunc[gDiscreteLN,z];

(* Poisson is already discrete, we define just the list of probabilities *)
PoissonLN15 = Table[ ((θ^n)/(n!))(E^(-θ))/.valuesLN15,{n,0,20}]//Chop;
(* and define generating function*)
PLN15[z_]=GenFunc[PoissonLN15,z];

FLN15[z_]=PLN15[GLN[z]]; (* Panjer formula *)
fsLN15=ExtractCoefficients[FLN15]; (* get the coefficients of generating function F *)
FsLN15=Accumulate[fsLN15];

ListLinePlot[FsLN15,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsLN15],1}}]}]

QsLN15 = FindQuantile[FsLN15];

ListLinePlot[QsLN15,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsLN15] (* this should be reliable interval on which we can interpolate *)

varLN15 = VaR[QsLN15,α/.valuesLN15] (*at the beginning of the interval, the interpolation fails - it is need to be cut off*)

cvarLN15=cVaR[fsLN15,QsLN15,α/.valuesLN15]

alphas =Range[p0+0.001,p1-0.001,((p1-p0)/30)];
grafVarLN15=Transpose[{alphas,VaR[QsLN15,#]&/@alphas}];
grafCvarLN15=Transpose[{alphas,cVaR[fsLN15,QsLN15,#]&/@alphas}];

ListLinePlot[{grafVarLN15,grafCvarLN15},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Dohromady

Show[ListLinePlot[ FsLN15,PlotRange->Full,PlotStyle->Blue,PlotLegends->{"(Subscript[F, S])(n), θ = 0.15"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsLN15],1}}]}],ListLinePlot[ FsLN,PlotRange->Full,PlotStyle->Red,PlotLegends->{"(Subscript[F, S])(n), θ = 0.1"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsLN],1}}]}],ListLinePlot[ FsLN05,PlotRange->Full,PlotStyle->Green,PlotLegends->{"(Subscript[F, S])(n), θ = 0.05"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsLN05],1}}]}]]

Show[ListLinePlot[{grafVarLN05,grafCvarLN05},PlotRange->{{0.955,0.98},{0,800}},PlotStyle->{Green,{Green,Dashed}},PlotLegends->{"VaR, θ = 0.05","CVaR, θ = 0.05"},AxesLabel->{"α"}],ListLinePlot[{grafVarLN,grafCvarLN},PlotStyle->{Red,{Red,Dashed}},PlotLegends->{"VaR, θ = 0.1","CVaR, θ = 0.1"},AxesLabel->{"α"}],ListLinePlot[{grafVarLN15,grafCvarLN15},PlotStyle->{Blue,{Blue,Dashed}},PlotLegends->{"VaR, θ = 0.15","CVaR, θ = 0.15"},AxesLabel->{"α"}]]

Negative binomial

Exponencialni

Exponencialni, h = 0.4, p = 0.8

Exit[]

valuesExp = {λ->0.02, h->0.4,p->0.8,α->0.98};
initialValueNB= {f0->(p^h)};

(* Exponential distribution *)
gExp[x_] = λ (E^(-λ x))/.valuesExp;
gDiscreteExp = DiscretizeDistribution[gExp,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GExp[z_] = GenFunc[gDiscreteExp,z];

(* Negative binomial is already discrete, we define just the list of probabilities *)
NBExp = Table[ Binomial[n+h-1,n] (p^h) (((1-p))^n)/.valuesExp,{n,0,20}]//Chop;
(* and define generating function*)
PNBExp[z_]=GenFunc[NBExp,z];

FNBExp[z_]=PNBExp[GExp[z]]; (* Panjer formula *)
fsNBExp=ExtractCoefficients[FNBExp]; (* get the coefficients of generating function F *)
FsNBExp=Accumulate[fsNBExp];

ListLinePlot[ FsNBExp,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBExp],1}}]}]

QsNBExp = FindQuantile[FsNBExp];

ListLinePlot[QsNBExp,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsNBExp] (* this should be reliable interval on which we can interpolate *)

varNBExp = VaR[QsNBExp,α/.valuesExp]

cvarNBExp=cVaR[fsNBExp,QsNBExp,α/.valuesExp]

alphas =Range[p0+0.001,p1-0.001,((p1-p0)/30)];
grafVarExpNB=Transpose[{alphas,VaR[QsNBExp,#]&/@alphas}];
grafCvarExpNB=Transpose[{alphas,cVaR[fsNBExp,QsNBExp,#]&/@alphas}];

ListLinePlot[{grafVarExpNB,grafCvarExpNB},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Exponencialni, h = 0.2, p = 0.8

Exit[]

valuesExp05 = {λ->0.02, h->0.2,p->0.8,α->0.98};
initialValueNB= {f0->(p^h)};

(* Exponential distribution *)
gExp[x_] = λ (E^(-λ x))/.valuesExp05;
gDiscreteExp = DiscretizeDistribution[gExp,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GExp[z_] = GenFunc[gDiscreteExp,z];

(* Negative binomial is already discrete, we define just the list of probabilities *)
NBExp05 = Table[ Binomial[n+h-1,n] (p^h) (((1-p))^n)/.valuesExp05,{n,0,20}]//Chop;
(* and define generating function*)
PNBExp05[z_]=GenFunc[NBExp05,z];

FNBExp05[z_]=PNBExp05[GExp[z]]; (* Panjer formula *)
fsNBExp05=ExtractCoefficients[FNBExp05]; (* get the coefficients of generating function F *)
FsNBExp05=Accumulate[fsNBExp05];

ListLinePlot[ FsNBExp05,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBExp05],1}}]}]

QsNBExp05 = FindQuantile[FsNBExp05];

ListLinePlot[QsNBExp05,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsNBExp05] (* this should be reliable interval on which we can interpolate *)

varNBExp05 = VaR[QsNBExp05,α/.valuesExp05]

cvarNBExp05=cVaR[fsNBExp05,QsNBExp05,α/.valuesExp05]

alphas =Range[p0+0.001,p1-0.001,((p1-p0)/30)];
grafVarExpNB05=Transpose[{alphas,VaR[QsNBExp05,#]&/@alphas}];
grafCvarExpNB05=Transpose[{alphas,cVaR[fsNBExp05,QsNBExp05,#]&/@alphas}];

ListLinePlot[{grafVarExpNB05,grafCvarExpNB05},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Exponencialni, h = 0.6, p = 0.8

Exit[]

valuesExp15 = {λ->0.02, h->0.6,p->0.8,α->0.98};
initialValueNB= {f0->(p^h)};

(* Exponential distribution *)
gExp[x_] = λ (E^(-λ x))/.valuesExp15;
gDiscreteExp = DiscretizeDistribution[gExp,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GExp[z_] = GenFunc[gDiscreteExp,z];

(* Negative binomial is already discrete, we define just the list of probabilities *)
NBExp15 = Table[ Binomial[n+h-1,n] (p^h) (((1-p))^n)/.valuesExp15,{n,0,20}]//Chop;
(* and define generating function*)
PNBExp15[z_]=GenFunc[NBExp15,z];

FNBExp15[z_]=PNBExp15[GExp[z]]; (* Panjer formula *)
fsNBExp15=ExtractCoefficients[FNBExp15]; (* get the coefficients of generating function F *)
FsNBExp15=Accumulate[fsNBExp15];

ListLinePlot[ FsNBExp15,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBExp15],1}}]}]

QsNBExp15 = FindQuantile[FsNBExp15];

ListLinePlot[QsNBExp15,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsNBExp15] (* this should be reliable interval on which we can interpolate *)

varNBExp15 = VaR[QsNBExp15,α/.valuesExp15]

cvarNBExp15=cVaR[fsNBExp15,QsNBExp15,α/.valuesExp15]

alphas =Range[p0+0.001,p1-0.001,((p1-p0)/30)];
grafVarExpNB15=Transpose[{alphas,VaR[QsNBExp15,#]&/@alphas}];
grafCvarExpNB15=Transpose[{alphas,cVaR[fsNBExp15,QsNBExp15,#]&/@alphas}];

ListLinePlot[{grafVarExpNB15,grafCvarExpNB15},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Dohromady

Show[ListLinePlot[ FsNBExp15,PlotRange->Full,PlotStyle->Blue,PlotLegends->{"(Subscript[F, S])(n), θ = 0.15"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBExp15],1}}]}],ListLinePlot[ FsNBExp,PlotRange->Full,PlotStyle->Red,PlotLegends->{"(Subscript[F, S])(n), θ = 0.1"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBExp],1}}]}],ListLinePlot[ FsNBExp05,PlotRange->Full,PlotStyle->Green,PlotLegends->{"(Subscript[F, S])(n), θ = 0.05"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBExp05],1}}]}]]

Show[ListLinePlot[{grafVarExpNB05,grafCvarExpNB05},PlotRange->{{0.96,0.99},{0,1200}},PlotStyle->{Green,{Green,Dashed}},PlotLegends->{"VaR, θ = 0.05","CVaR, θ = 0.05"},AxesLabel->{"α"}],ListLinePlot[{grafVarExpNB,grafCvarExpNB},PlotStyle->{Red,{Red,Dashed}},PlotLegends->{"VaR, θ = 0.1","CVaR, θ = 0.1"},AxesLabel->{"α"}],ListLinePlot[{grafVarExpNB15,grafCvarExpNB15},PlotStyle->{Blue,{Blue,Dashed}},PlotLegends->{"VaR, θ = 0.15","CVaR, θ = 0.15"},AxesLabel->{"α"}]]

Gama

Gama, h = 0.4, p = 0.8

Exit[]

valuesGam = {p->10,λ->1, r->0.8,h->0.4,α->0.98};
initialValueNB = {f0->(r^h)};

(* Gamma distribution *)
gGam[x_] =  ((λ^p)/(Gamma[p]))(x^(p-1)) (E^(-λ x ))/.valuesGam;
gDiscreteGam = DiscretizeDistribution[gGam,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GGam[z_] = GenFunc[gDiscreteGam,z];

(* Poisson is already discrete, we define just the list of probabilities *)
NBGam = Table[ Binomial[n+h-1,n] r^h (1-r)^n/.valuesGam,{n,0,20}]//Chop;
(* and define generating function*)
PNBGam[z_]=GenFunc[NBGam,z];

FNBGam[z_]=PNBGam[GGam[z]]; (* Panjer formula *)
fsNBGam=ExtractCoefficients[FNBGam]; (* get the coefficients of generating function F *)
FsNBGam=Accumulate[fsNBGam];

ListLinePlot[ FsNBGam,PlotRange->{0.9,1},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBGam],1}}]}]

QsNBGam = FindQuantile[FsNBGam];

ListLinePlot[QsNBGam,PlotRange->{{0.9,1.001},Full},AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsNBGam] (* this should be reliable interval on which we can interpolate *)

pomocneQsNBGam=Drop[QsNBGam,35];

varNBGam = VaR[pomocneQsNBGam,α/.valuesGam] (*at the beginning of the interval, the interpolation fails - it is need to be cut off*)

cvarNBGam=cVaR[fsNBGam,pomocneQsNBGam,α/.valuesGam]

alphas =Range[p0+0.01,p1-0.01,((p1-p0)/30)];
grafVarNBGam=Transpose[{alphas,VaR[pomocneQsNBGam,#]&/@alphas}];
grafCvarNBGam=Transpose[{alphas,cVaR[fsNBGam,pomocneQsNBGam,#]&/@alphas}];

ListLinePlot[{grafVarNBGam,grafCvarNBGam},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Gama, h = 0.2, p = 0.8

Exit[]

valuesGam05 = {p->10,λ->1, r->0.8,h->0.2,α->0.98};
initialValueNB = {f0->(r^h)};

(* Gamma distribution *)
gGam[x_] =  ((λ^p)/(Gamma[p]))(x^(p-1)) (E^(-λ x ))/.valuesGam05;
gDiscreteGam = DiscretizeDistribution[gGam,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GGam[z_] = GenFunc[gDiscreteGam,z];

(* Poisson is already discrete, we define just the list of probabilities *)
NBGam05 = Table[ Binomial[n+h-1,n] r^h (1-r)^n/.valuesGam05,{n,0,20}]//Chop;
(* and define generating function*)
PNBGam05[z_]=GenFunc[NBGam05,z];

FNBGam05[z_]=PNBGam05[GGam[z]]; (* Panjer formula *)
fsNBGam05=ExtractCoefficients[FNBGam05]; (* get the coefficients of generating function F *)
FsNBGam05=Accumulate[fsNBGam05];

ListLinePlot[ FsNBGam05,PlotRange->{0.95,1},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBGam05],1}}]}]

QsNBGam05 = FindQuantile[FsNBGam05];

ListLinePlot[QsNBGam05,PlotRange->{{0.95,1.001},Full},AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsNBGam05] (* this should be reliable interval on which we can interpolate *)

pomocneQsNBGam05=Drop[QsNBGam05,35];

varNBGam05 = VaR[pomocneQsNBGam05,α/.valuesGam05] (*at the beginning of the interval, the interpolation fails - it is need to be cut off*)

cvarNBGam05=cVaR[fsNBGam05,pomocneQsNBGam05,α/.valuesGam05]

alphas =Range[p0+0.01,p1-0.01,((p1-p0)/30)];
grafVarNBGam05=Transpose[{alphas,VaR[pomocneQsNBGam05,#]&/@alphas}];
grafCvarNBGam05=Transpose[{alphas,cVaR[fsNBGam05,pomocneQsNBGam05,#]&/@alphas}];

ListLinePlot[{grafVarNBGam05,grafCvarNBGam05},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Gama, h = 0.6, p = 0.8

Exit[]

valuesGam15 = {p->10,λ->1, r->0.8,h->0.6,α->0.98};
initialValueNB = {f0->(r^h)};

(* Gamma distribution *)
gGam[x_] =  ((λ^p)/(Gamma[p]))(x^(p-1)) (E^(-λ x ))/.valuesGam15;
gDiscreteGam = DiscretizeDistribution[gGam,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GGam[z_] = GenFunc[gDiscreteGam,z];

(* Poisson is already discrete, we define just the list of probabilities *)
NBGam15 = Table[ Binomial[n+h-1,n] r^h (1-r)^n/.valuesGam15,{n,0,20}]//Chop;
(* and define generating function*)
PNBGam15[z_]=GenFunc[NBGam15,z];

FNBGam15[z_]=PNBGam15[GGam[z]]; (* Panjer formula *)
fsNBGam15=ExtractCoefficients[FNBGam15]; (* get the coefficients of generating function F *)
FsNBGam15=Accumulate[fsNBGam15];

ListLinePlot[ FsNBGam15,PlotRange->{0.9,1},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBGam15],1}}]}]

QsNBGam15 = FindQuantile[FsNBGam15];

ListLinePlot[QsNBGam15,PlotRange->{{0.9,1.001},Full},AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsNBGam15] (* this should be reliable interval on which we can interpolate *)

pomocneQsNBGam15=Drop[QsNBGam15,35];

varNBGam15 = VaR[pomocneQsNBGam15,α/.valuesGam15] (*at the beginning of the interval, the interpolation fails - it is need to be cut off*)

cvarNBGam15=cVaR[fsNBGam15,pomocneQsNBGam15,α/.valuesGam15]

alphas =Range[p0+0.01,p1-0.01,((p1-p0)/30)];
grafVarNBGam15=Transpose[{alphas,VaR[pomocneQsNBGam15,#]&/@alphas}];
grafCvarNBGam15=Transpose[{alphas,cVaR[fsNBGam15,pomocneQsNBGam15,#]&/@alphas}];

ListLinePlot[{grafVarNBGam15,grafCvarNBGam15},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Dohromady

Show[ListLinePlot[ FsNBGam15,PlotRange->Full,PlotStyle->Blue,PlotLegends->{"(Subscript[F, S])(n), θ = 0.15"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBGam15],1}}]}],ListLinePlot[ FsNBGam,PlotRange->Full,PlotStyle->Red,PlotLegends->{"(Subscript[F, S])(n), θ = 0.1"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBGam],1}}]}],ListLinePlot[ FsNBGam05,PlotRange->Full,PlotStyle->Green,PlotLegends->{"(Subscript[F, S])(n), θ = 0.05"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBGam05],1}}]}]]

Show[ListLinePlot[{grafVarNBGam05,grafCvarNBGam05},PlotRange->{{0.969,0.98},{40,150}},PlotStyle->{Green,{Green,Dashed}},PlotLegends->{"VaR, θ = 0.05","CVaR, θ = 0.05"},AxesLabel->{"α"}],ListLinePlot[{grafVarNBGam,grafCvarNBGam},PlotStyle->{Red,{Red,Dashed}},PlotLegends->{"VaR, θ = 0.1","CVaR, θ = 0.1"},AxesLabel->{"α"}],ListLinePlot[{grafVarNBGam15,grafCvarNBGam15},PlotStyle->{Blue,{Blue,Dashed}},PlotLegends->{"VaR, θ = 0.15","CVaR, θ = 0.15"},AxesLabel->{"α"}]]

Pareto

Pareto, h = 0.4, p = 0.8

Exit[]

valuesPar = {λ->4,a->200, p->0.8,h->0.4,α->0.98};
initialValueNB= {f0->(p^h)};

(* Exponential distribution *)
gPar[x_] =  λ (a^λ)(((x+a))^(-(λ+1)))/.valuesPar;
gDiscretePar = DiscretizeDistribution[gPar,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GPar[z_] = GenFunc[gDiscretePar,z];

(* Poisson is already discrete, we define just the list of probabilities *)
NBPar = Table[Binomial[n+h-1,n] (p^h) (((1-p))^n)/.valuesPar,{n,0,20}]//Chop;
(* and define generating function*)
PNBPar[z_]=GenFunc[NBPar,z];

FNBPar[z_]=PNBPar[GPar[z]]; (* Panjer formula *)
fsNBPar=ExtractCoefficients[FNBPar]; (* get the coefficients of generating function F *)
FsNBPar=Accumulate[fsNBPar];

ListLinePlot[ FsNBPar,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBPar],1}}]}]

QsNBPar = FindQuantile[FsNBPar];

ListLinePlot[QsNBPar,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsNBPar] (* this should be reliable interval on which we can interpolate *)

varNBPar = VaR[QsNBPar,α/.valuesPar]

cvarNBPar=cVaR[fsNBPar,QsNBPar,α/.valuesPar]

alphas =Range[p0+0.01,p1-0.01,((p1-p0)/30)];
grafVarNBPar=Transpose[{alphas,VaR[QsNBPar,#]&/@alphas}];
grafCvarNBPar=Transpose[{alphas,cVaR[fsNBPar,QsNBPar,#]&/@alphas}];

ListLinePlot[{grafVarNBPar,grafCvarNBPar},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Pareto, h = 0.2, p = 0.8

Exit[]

valuesPar05 = {λ->4,a->200, p->0.8,h->0.2,α->0.98};
initialValueNB= {f0->(p^h)};

(* Exponential distribution *)
gPar[x_] =  λ (a^λ)(((x+a))^(-(λ+1)))/.valuesPar05;
gDiscretePar = DiscretizeDistribution[gPar,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GPar[z_] = GenFunc[gDiscretePar,z];

(* Poisson is already discrete, we define just the list of probabilities *)
NBPar05 = Table[Binomial[n+h-1,n] (p^h) (((1-p))^n)/.valuesPar05,{n,0,20}]//Chop;
(* and define generating function*)
PNBPar05[z_]=GenFunc[NBPar05,z];

FNBPar05[z_]=PNBPar05[GPar[z]]; (* Panjer formula *)
fsNBPar05=ExtractCoefficients[FNBPar05]; (* get the coefficients of generating function F *)
FsNBPar05=Accumulate[fsNBPar05];

ListLinePlot[ FsNBPar05,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBPar05],1}}]}]

QsNBPar05 = FindQuantile[FsNBPar05];

ListLinePlot[QsNBPar05,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsNBPar05] (* this should be reliable interval on which we can interpolate *)

varNBPar05 = VaR[QsNBPar05,α/.valuesPar05]

cvarNBPar05=cVaR[fsNBPar05,QsNBPar05,α/.valuesPar05]

alphas =Range[p0+0.01,p1-0.01,((p1-p0)/30)];
grafVarNBPar05=Transpose[{alphas,VaR[QsNBPar05,#]&/@alphas}];
grafCvarNBPar05=Transpose[{alphas,cVaR[fsNBPar05,QsNBPar05,#]&/@alphas}];

ListLinePlot[{grafVarNBPar05,grafCvarNBPar05},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Pareto, h = 0.6, p = 0.8

Exit[]

valuesPar15 = {λ->4,a->200, p->0.8,h->0.6,α->0.98};
initialValueNB= {f0->(p^h)};

(* Exponential distribution *)
gPar[x_] =  λ (a^λ)(((x+a))^(-(λ+1)))/.valuesPar15;
gDiscretePar = DiscretizeDistribution[gPar,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GPar[z_] = GenFunc[gDiscretePar,z];

(* Poisson is already discrete, we define just the list of probabilities *)
NBPar15 = Table[Binomial[n+h-1,n] (p^h) (((1-p))^n)/.valuesPar15,{n,0,20}]//Chop;
(* and define generating function*)
PNBPar15[z_]=GenFunc[NBPar15,z];

FNBPar15[z_]=PNBPar15[GPar[z]]; (* Panjer formula *)
fsNBPar15=ExtractCoefficients[FNBPar15]; (* get the coefficients of generating function F *)
FsNBPar15=Accumulate[fsNBPar15];

ListLinePlot[ FsNBPar15,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBPar15],1}}]}]

QsNBPar15 = FindQuantile[FsNBPar15];

ListLinePlot[QsNBPar15,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsNBPar15] (* this should be reliable interval on which we can interpolate *)

varNBPar15 = VaR[QsNBPar15,α/.valuesPar15]

cvarNBPar15=cVaR[fsNBPar15,QsNBPar15,α/.valuesPar15]

alphas =Range[p0+0.01,p1-0.01,((p1-p0)/30)];
grafVarNBPar15=Transpose[{alphas,VaR[QsNBPar15,#]&/@alphas}];
grafCvarNBPar15=Transpose[{alphas,cVaR[fsNBPar15,QsNBPar15,#]&/@alphas}];

ListLinePlot[{grafVarNBPar15,grafCvarNBPar15},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Dohromady

Show[ListLinePlot[ FsNBPar15,PlotRange->Full,PlotStyle->Blue,PlotLegends->{"(Subscript[F, S])(n), θ = 0.15"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBPar15],1}}]}],ListLinePlot[ FsNBPar,PlotRange->Full,PlotStyle->Red,PlotLegends->{"(Subscript[F, S])(n), θ = 0.1"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBPar],1}}]}],ListLinePlot[ FsNBPar05,PlotRange->Full,PlotStyle->Green,PlotLegends->{"(Subscript[F, S])(n), θ = 0.05"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBPar05],1}}]}]]

Show[ListLinePlot[{grafVarNBPar05,grafCvarNBPar05},PlotRange->{{0.969,0.978},{120,1020}},PlotStyle->{Green,{Green,Dashed}},PlotLegends->{"VaR, θ = 0.05","CVaR, θ = 0.05"},AxesLabel->{"α"}],ListLinePlot[{grafVarNBPar,grafCvarNBPar},PlotStyle->{Red,{Red,Dashed}},PlotLegends->{"VaR, θ = 0.1","CVaR, θ = 0.1"},AxesLabel->{"α"}],ListLinePlot[{grafVarNBPar15,grafCvarNBPar15},PlotStyle->{Blue,{Blue,Dashed}},PlotLegends->{"VaR, θ = 0.15","CVaR, θ = 0.15"},AxesLabel->{"α"}]]

Logaritmicko - normalni

Logaritmicko-normalni, h = 0.4, p = 0.8

Exit[]

valuesLN= {μ->3,rozptyl->2, p->0.8,h->0.4,α->0.98};
initialValueNB = {f0->(p^h)};

(* Gamma distribution *)
gLN[x_] = (1/((Sqrt[2π rozptyl])x)) (E^(((-(((Log[x]-μ))^2))/(2 rozptyl)) ))/.valuesLN;
gDiscreteLN= DiscretizeDistribution[gLN,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GLN[z_] = GenFunc[gDiscreteLN,z];

(* Poisson is already discrete, we define just the list of probabilities *)
NBLN = Table[ Binomial[n+h-1,n] (p^h) (((1-p))^n)/.valuesLN,{n,0,20}]//Chop;
(* and define generating function*)
PNBLN[z_]=GenFunc[NBLN,z];

FNBLN[z_]=PNBLN[GLN[z]]; (* Panjer formula *)
fsNBLN=ExtractCoefficients[FNBLN]; (* get the coefficients of generating function F *)
FsNBLN=Accumulate[fsNBLN];

ListLinePlot[ FsNBLN,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBLN],1}}]}]

QsNBLN = FindQuantile[FsNBLN];

ListLinePlot[QsNBLN,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsNBLN] (* this should be reliable interval on which we can interpolate *)

varNBLN = VaR[QsNBLN,α/.valuesLN] (*at the beginning of the interval, the interpolation fails - it is need to be cut off*)

cvarNBLN=cVaR[fsNBLN,QsNBLN,α/.valuesLN]

alphas =Range[p0+0.01,p1-0.01,((p1-p0)/30)];
grafVarNBLN=Transpose[{alphas,VaR[QsNBLN,#]&/@alphas}];
grafCvarNBLN=Transpose[{alphas,cVaR[fsNBLN,QsNBLN,#]&/@alphas}];

ListLinePlot[{grafVarNBLN,grafCvarNBLN},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Logaritmicko-normalni, h = 0.2, p = 0.8

Exit[]

valuesLN05= {μ->3,rozptyl->2, p->0.8,h->0.2,α->0.98};
initialValueNB = {f0->(p^h)};

(* Gamma distribution *)
gLN[x_] = (1/((Sqrt[2π rozptyl])x)) (E^(((-(((Log[x]-μ))^2))/(2 rozptyl)) ))/.valuesLN05;
gDiscreteLN= DiscretizeDistribution[gLN,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GLN[z_] = GenFunc[gDiscreteLN,z];

(* Poisson is already discrete, we define just the list of probabilities *)
NBLN05 = Table[ Binomial[n+h-1,n] (p^h) (((1-p))^n)/.valuesLN05,{n,0,20}]//Chop;
(* and define generating function*)
PNBLN05[z_]=GenFunc[NBLN05,z];

FNBLN05[z_]=PNBLN05[GLN[z]]; (* Panjer formula *)
fsNBLN05=ExtractCoefficients[FNBLN05]; (* get the coefficients of generating function F *)
FsNBLN05=Accumulate[fsNBLN05];

ListLinePlot[ FsNBLN05,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBLN05],1}}]}]

QsNBLN05 = FindQuantile[FsNBLN05];

ListLinePlot[QsNBLN05,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsNBLN05] (* this should be reliable interval on which we can interpolate *)

varNBLN05 = VaR[QsNBLN05,α/.valuesLN05] (*at the beginning of the interval, the interpolation fails - it is need to be cut off*)

cvarNBLN05=cVaR[fsNBLN05,QsNBLN05,α/.valuesLN05]

alphas =Range[p0+0.01,p1-0.01,((p1-p0)/30)];
grafVarNBLN05=Transpose[{alphas,VaR[QsNBLN05,#]&/@alphas}];
grafCvarNBLN05=Transpose[{alphas,cVaR[fsNBLN05,QsNBLN05,#]&/@alphas}];

ListLinePlot[{grafVarNBLN05,grafCvarNBLN05},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Logaritmicko-normalni, h = 0.6, p = 0.8

Exit[]

valuesLN15= {μ->3,rozptyl->2, p->0.8,h->0.6,α->0.98};
initialValueNB = {f0->(p^h)};

(* Gamma distribution *)
gLN[x_] = (1/((Sqrt[2π rozptyl])x)) (E^(((-(((Log[x]-μ))^2))/(2 rozptyl)) ))/.valuesLN15;
gDiscreteLN= DiscretizeDistribution[gLN,1/6,0,300]; (* discretize on interval (0,100) with the step h=1/6 *)

(* generating function of discretized distribution *)
GLN[z_] = GenFunc[gDiscreteLN,z];

(* Poisson is already discrete, we define just the list of probabilities *)
NBLN15= Table[ Binomial[n+h-1,n] (p^h) (((1-p))^n)/.valuesLN15,{n,0,20}]//Chop;
(* and define generating function*)
PNBLN15[z_]=GenFunc[NBLN15,z];

FNBLN15[z_]=PNBLN15[GLN[z]]; (* Panjer formula *)
fsNBLN15=ExtractCoefficients[FNBLN15]; (* get the coefficients of generating function F *)
FsNBLN15=Accumulate[fsNBLN15];

ListLinePlot[ FsNBLN15,PlotRange->Full,AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBLN15],1}}]}]

QsNBLN15 = FindQuantile[FsNBLN15];

ListLinePlot[QsNBLN15,PlotRange->Full,AxesLabel->{"p","Q(p)"}]

{p0,p1}=GetRange[QsNBLN15] (* this should be reliable interval on which we can interpolate *)

varNBLN15 = VaR[QsNBLN15,α/.valuesLN15] (*at the beginning of the interval, the interpolation fails - it is need to be cut off*)

cvarNBLN15=cVaR[fsNBLN15,QsNBLN15,α/.valuesLN15]

alphas =Range[p0+0.01,p1-0.01,((p1-p0)/30)];
grafVarNBLN15=Transpose[{alphas,VaR[QsNBLN15,#]&/@alphas}];
grafCvarNBLN15=Transpose[{alphas,cVaR[fsNBLN15,QsNBLN15,#]&/@alphas}];

ListLinePlot[{grafVarNBLN15,grafCvarNBLN15},PlotLegends->{"VaR","CVaR"},AxesLabel->{"α"}]

Dohromady

Show[ListLinePlot[ FsNBLN15,PlotRange->Full,PlotStyle->Blue,PlotLegends->{"(Subscript[F, S])(n), θ = 0.15"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBLN15],1}}]}],ListLinePlot[ FsNBLN,PlotRange->Full,PlotStyle->Red,PlotLegends->{"(Subscript[F, S])(n), θ = 0.1"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBLN],1}}]}],ListLinePlot[ FsNBLN05,PlotRange->Full,PlotStyle->Green,PlotLegends->{"(Subscript[F, S])(n), θ = 0.05"},AxesLabel->{"n","(Subscript[F, S])(n)"} , Epilog->{ Dashed, Black, Line[{{0,1},{Length[FsNBLN05],1}}]}]]

Show[ListLinePlot[{grafVarNBLN05,grafCvarNBLN05},PlotRange->{{0.9685,0.978},{40,850}},PlotStyle->{Green,{Green,Dashed}},PlotLegends->{"VaR, θ = 0.05","CVaR, θ = 0.05"},AxesLabel->{"α"}],ListLinePlot[{grafVarNBLN,grafCvarNBLN},PlotStyle->{Red,{Red,Dashed}},PlotLegends->{"VaR, θ = 0.1","CVaR, θ = 0.1"},AxesLabel->{"α"}],ListLinePlot[{grafVarNBLN15,grafCvarNBLN15},PlotStyle->{Blue,{Blue,Dashed}},PlotLegends->{"VaR, θ = 0.15","CVaR, θ = 0.15"},AxesLabel->{"α"}]]

Momenty Paretova rozdeleni

g[α_,a_,x_] = α (a^(α ))(((x+a))^(-(α+1)));

mean=Assuming[Re[a]>0&&Re[α]>1&&2 Arg[(1/a)]≤π,Integrate[y g[α,a,y],{y,0,Infinity}]]

pomocnyvypocet=Assuming[Re[a]>0&&Re[α]>2&&3 Arg[(1/a)]≤π,Integrate[y^2 g[α,a,y],{y,0,Infinity}]]

variance=Simplify[pomocnyvypocet-(mean)^2]

pomocnyvypocet2=Assuming[Re[a]>0&&Re[α]>3&&4 Arg[(1/a)]≤π,Integrate[y^3 g[α,a,y],{y,0,Infinity}]]

skewness=FullSimplify[(pomocnyvypocet2-3 pomocnyvypocet mean+2 (mean)^3)/(variance)^(3/2)]