mle for a custom distribution fit error
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Financial Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!