MATLAB Answers

mle for a custom distribution fit error

9 views (last 30 days)
Mate 2u
Mate 2u on 31 Aug 2014
Commented: Mate 2u on 5 Sep 2014
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 Comments

the cyclist
the cyclist on 31 Aug 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
Mate 2u on 31 Aug 2014
The parameter "prices" is a time series of 1000x1 of prices.
Sample data:
102.960000000000
103.220000000000
101.810000000000
101.560000000000
101.310000000000
102.240000000000
100.890000000000
99.0300000000000
98.6900000000000
100.700000000000
100.610000000000
100.320000000000
98.1500000000000
99.4700000000000
98.8400000000000
99.2300000000000
99.7600000000000

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!