为了使GARCH模型的对数似然函数最大化,我使用MATLAB中的fminsearch来最小化负对数似然函数,这个问题有两个约束条件。我试图使用fmin或minimize函数(来自scipy),但我认为转换约束的方式是不正确的。在
下面是我在Python3.6中的尝试:def computeNegLLH(parameters):
sigma2 = np.zeros(len(returns));
omega = parameters[0];
alpha = parameters[1];
beta = parameters[2];
sigma2[1] = parameters[3];
# parameters restrictions: omega>0; alpha,beta>=0; alpha + beta >= 1
if (omega<=0 or min(alpha,beta)<0 or alpha + beta >= 1 or sigma2[0]<=0):
negLLH = sys.maxsize;
sys.exit();
# calculate squared returns
returns2 = returns**2;
for t in range(1,len(returns)):
sigma2[t]= omega + alpha*returns2[t-1] + beta*sigma2[t-1];
# calculate (-1)xLogLikelihood for a GARCH(1,1) process with parameters
negLLH = 0.5*sum(log(sigma2) + returns2/sigma2);
return negLLH
result = minimize(fun = computeNegLLH, x0 = startingValues, method = 'Nelder-
Mead', options = {'xtol': 1e-8})
我的MATLAB代码:
^{pr2}$