mle for a custom distribution fit error
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi all, I am trying to use a code I found on-line which should work, but I am getting an error.
It is trying to estimate parameters from a Variance Gamma model. I have a custom probability density function called VGdensity:
function fx = VGdensity(x,theta,nu,sigma,mu,T)
v1 = 2*exp((theta*(x-mu))/sigma^2)/((nu^(T/nu))*sqrt(2*pi)*sigma*gamma(T/nu));
M2 = (2*sigma^2)/nu+theta^2;
v3 = abs(x-mu)./sqrt(M2);
v4 = v3.^(T/nu-0.5);
v6 = (abs(x-mu).*sqrt(M2))./sigma^2;
K = besselk(T/nu-0.5,v6);
fx = v1.*v4.*K;
Ok now I have a MLE function to estimate 4 parameters as below:
data = price2ret(prices)
dt = 1;
M = mean(data);
V = std(data);
S = skewness(data);
K = kurtosis(data);
sigma = sqrt(V/dt);
nu = (K/3-1)*dt ;
theta = (S*sigma*sqrt(dt))/(3*nu);
mu = (M/dt)-theta;
% VG MLE
pdf_VG = @(data,theta,nu,sigma,mu) VGdensity(data,theta,nu,sigma,mu,dt);
start = [theta,nu,sigma,mu];
lb = [-intmax 0 0 -intmax];
ub = [intmax intmax intmax intmax];
options = statset('MaxIter',10000,'MaxFunEvals',10000);
params = mle(data,'pdf',pdf_VG ,'start',start,'lower',lb,'upper',ub,'options',options);
However when I try to run this I get the following error:
Error using mlecustom>llf_pdfcdf (line 437) The PDF function returned NaN or infinite values.
Error in fminsearch (line 347) x(:) = xcc; fxcc = funfcn(x,varargin{:});
Error in mlecustom (line 183) [phat,nll,err,output] = ...
Error in mle (line 226) phat = mlecustom(data,varargin{:});
댓글 수: 3
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Financial Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!