Momentos

Clear[c1,λ1,c2,λ2,Δt]

μ0=Integrate[(x-y) PDF[GammaDistribution[Δt c1,1/λ1],x]PDF[GammaDistribution[Δt c2,1/λ2],y],{x,0,Infinity},{y,0,Infinity},Assumptions->(Re[Δt c1]>0&&Re[Δt c2]>0&&Re[λ2]>0&&Re[λ1]>0&&Re[Δt]>0)]

μ2=Integrate[((x-y)-μ0)^2 PDF[GammaDistribution[Δt c1,1/λ1],x]PDF[GammaDistribution[Δt c2,1/λ2],y],{x,0,Infinity},{y,0,Infinity},Assumptions->(Re[Δt c1]>0&&Re[Δt c2]>0&&Re[λ2]>0&&Re[λ1]>0&&Re[Δt]>0)]

μ3=Integrate[((x-y)-μ0)^3 PDF[GammaDistribution[Δt c1,1/λ1],x]PDF[GammaDistribution[Δt c2,1/λ2],y],{x,0,Infinity},{y,0,Infinity},Assumptions->(Re[Δt c1]>0&&Re[Δt c2]>0&&Re[λ2]>0&&Re[λ1]>0&&Re[Δt]>0)]

μ4=Integrate[((x-y)-μ0)^4 PDF[GammaDistribution[Δt c1,1/λ1],x]PDF[GammaDistribution[Δt c2,1/λ2],y],{x,0,Infinity},{y,0,Infinity},Assumptions->(Re[Δt c1]>0&&Re[Δt c2]>0&&Re[λ2]>0&&Re[λ1]>0&&Re[Δt]>0)]

Estimação por GMM

Needs["Histograms`"]

base=Import["d:\data\data_stock.csv"]*100;
T=Dimensions[base][[1]];n=Dimensions[base][[2]];Δt=1;

Do[
X=Transpose[{Select[base[[All,j]],NumericQ]}];
μ0=Mean[X][[1]];μ2=Variance[X][[1]];μ3=CentralMoment[X,3][[1]];μ4=CentralMoment[X,4][[1]];
Do[x[t]=X[[t]],{t,1,T}];q=Floor[4(T/100)^(2/9)];
k=4;Do[z[t]={x[t]-μ0,(x[t]-μ0)^2-μ2,(x[t]-μ0)^3-μ3,(x[t]-μ0)^4-μ4},{t,1,T}];
S=(1/(T-k))(Sum[z[t].Transpose[z[t]],{t,1,T}]+Sum[(1-ν/(q+1))(z[t].Transpose[z[t-ν]]+z[t-ν].Transpose[z[t]]),{ν,1,q},{t,ν+1,T}]);
g=Transpose[{{μ-μ0 ,σ^2-μ2,0- μ3,3σ^4-μ4}}];
sol[j]=Minimize[{(Transpose[g].PseudoInverse[S].g)[[1,1]],σ>0},{μ,σ}],{j,1,n}];{sol[1],sol[2]}//MatrixForm
m1=sol[1][[2,1,2]];m2=sol[2][[2,1,2]];
s1=sol[1][[2,2,2]];s2=sol[2][[2,2,2]];
Show[GraphicsArray[{Show[Histogram[Flatten[base[[All,1]]],HistogramScale ->1],Plot[PDF[NormalDistribution[m1,s1],x],{x,-5,5},PlotRange->All]],Show[Histogram[Flatten[base[[All,1]]],HistogramScale ->1],Plot[PDF[NormalDistribution[m2,s2],x],{x,-5,5},PlotRange->All]]}]]

Do[
X=Transpose[{Select[base[[All,j]],NumericQ]}];
μ0=Mean[X][[1]];μ2=Variance[X][[1]];μ3=CentralMoment[X,3][[1]];μ4=CentralMoment[X,4][[1]];
Do[x[t]=X[[t]],{t,1,T}];q=Floor[4(T/100)^(2/9)];
k=4;Do[f[t]={x[t]-μ0,(x[t]-μ0)^2-μ2,(x[t]-μ0)^3-μ3,(x[t]-μ0)^4-μ4},{t,1,T}];
S=(1/(T-k))(Sum[f[t].Transpose[f[t]],{t,1,T}]+Sum[(1-ν/(q+1))(f[t].Transpose[f[t-ν]]+Transpose[f[t].Transpose[f[t-ν]]]),{ν,1,q},{t,ν+1,T}]);
g=Transpose[{{(c1 Δt)/λ1-(c2 Δt)/λ2-μ0 ,(c1 Δt)/λ1^2+(c2 Δt)/λ2^2-μ2,(2 c1 Δt)/λ1^3-(2 c2 Δt)/λ2^3- μ3,3 Δt ((c1 (2+c1 Δt))/λ1^4+(c2 (2+c2 Δt))/λ2^4+(2 c1 c2 Δt)/(λ1^2 λ2^2))-μ4}}];
sol[j]=Minimize[{(Transpose[g].PseudoInverse[S].g)[[1,1]],c1>0,λ1> 0,λ2==λ1,c2>0},{c1,c2,λ1,λ2}],{j,1,n}];{sol[1],sol[2]}//MatrixForm
a11=sol[1][[2,1,2]];a21=sol[2][[2,1,2]];
a12=sol[1][[2,2,2]];a22=sol[2][[2,2,2]];
b11=sol[1][[2,3,2]];b21=sol[2][[2,3,2]];
b12=sol[1][[2,4,2]];b22=sol[2][[2,4,2]];
Show[GraphicsArray[{Show[Histogram[Flatten[base[[All,1]]],HistogramScale ->1],ParametricPlot[{x-y,PDF[GammaDistribution[a11 Δt,1/b11],x]PDF[GammaDistribution[a12 Δt,1/b12],y]},{x,0,10},{y,0,10},PlotRange->{{-5,5},{0,1}}]],Show[Histogram[Flatten[base[[All,2]]],HistogramScale -> 1],ParametricPlot[{x-y,PDF[GammaDistribution[a21 Δt,1/b21],x]PDF[GammaDistribution[a22 Δt,1/b22],y]},{x,0,10},{y,0,10},PlotRange->{{-5,5},{0,1}}]]}]]

Mudança de Medida

Clear[c1,λ1,c2,λ2,Δt]

Integrate[Exp[θ(x-y)]PDF[GammaDistribution[Δt c1,1/λ1],x]PDF[GammaDistribution[Δt c2,1/λ2],y],{x,0,Infinity},{y,0,Infinity},Assumptions->{ λ1>0 && c1>0 && λ2==λ1 && c2>0 &&Δt>0&&θ<λ1}]

Integrate[Exp[(θ+1)(x-y)]PDF[GammaDistribution[Δt c1,1/λ1],x]PDF[GammaDistribution[Δt c2,1/λ2],y],{x,0,Infinity},{y,0,Infinity},Assumptions->{ λ1>0 && c1>0 && λ2>0 && c2>0 &&Δt>0&&θ+1<λ1}]

FindRoot[((b11-θ)/(b11-θ-1))^a11((b12+θ)/(b12+θ+1))^a12 == 1,{θ,-0.1}]//N
FindRoot[((b21-θ)/(b21-θ-1))^a21((b22+θ)/(b22+θ+1))^a22 == 1,{θ,-0.1}]//N
Show[GraphicsArray[{Plot[((b11-θ-1)/(b11-θ))^a11((b12+θ+1)/(b12+θ))^a12-1,{θ,-20,20},PlotRange->{-1,1}],Plot[((b21-θ-1)/(b21-θ))^a21((b22+θ+1)/(b22+θ))^a22-1,{θ,-20,20},PlotRange->{-1,1}]}]]