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{:});
回答(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!