我写了几个函数我贴在下面
NasdaqPdf与Sp500Pdf函数是变量的概率密度函数
相应的NasdaqCdf与Sp500Cdf是对应的累计概率函数
这几个函数应该没有问题,已经用几个值验证过。
最后一个函数是Copula函数,返回的值应该是一个实数,但是却返回一个复数,虽然虚部是零,但是在计算中却是一个问题,因为这个函数在后续研究中还要用。这个函数在运行中没有报错。
谁能帮我解释一下啊?感激不尽
——————————————————————————————————————————————————————————
function [ fnasdaq ] = NasdaqPdf( x )
%NASDAQPDF Summary of this function goes here
% Detailed explanation goes here
load nasdaq1261.txt
N=1261;
t=0;
for i=1:1261
t=t+exp(-0.5*((x-nasdaq1261(i))/0.0025).^2);
end
fnasdaq=1/(sqrt(2*pi)*N*0.0025)*t;
end
————————————————————————————————————————————————————————
function [ fsp500 ] = Sp500Pdf( x )
%SP500PDF Summary of this function goes here
% Detailed explanation goes here
load sp5001261.txt;
N=1261;
t=0;
for i=1:1261
t=t+exp(-0.5*((x-sp5001261(i))/0.0025).^2);
end
fsp500=1/(sqrt(2*pi)*N*0.0025)*t;
end
————————————————————————————————————————————————————
function [ y ] = NasdaqCdf( x )
%NASDAQCDF Summary of this function goes here
% Detailed explanation goes here
y=quadgk(@(u) NasdaqPdf(u),-inf,x);
end
——————————————————————————————————————————————————————
function [ y ] = Sp500Cdf( x )
%SP500CDF Summary of this function goes here
% Detailed explanation goes here
y=quadgk(@(u) Sp500Pdf(u),-inf,x);
end
————————————————————————————————————-————————————
function [ f ] = GumbleCopulaFunction( x , y )
%GUMBLECOPULAFUNCTION Summary of this function goes here
% Detailed explanation goes here
a=3.6443;
f=exp(-((-log(NasdaqCdf(x))).^a+(-log(Sp500Cdf(y))).^a).^(1/a));
end