mle for a custom distribution fit error
Mostrar comentarios más antiguos
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 comentarios
the cyclist
el 31 de Ag. de 2014
Do you have a (small) sample of input data you can post, so that we can actually run the code rather than guessing? For a well-formed problem, errors like this often come when the interim solutions stray off into ranges of the inputs where the fitted function is poorly behaved (e.g. approaches infinity).
Mate 2u
el 5 de Sept. de 2014
Respuestas (0)
Categorías
Más información sobre Financial Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!