• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

How can I write Matlab code for NGARCH Model?

Joined
10/29/09
Messages
2
Points
11
I tried to write a code to estimate the variables for NGARCH model:
\(\sigma(t+1)^2=\omega+\alpha*(Return(t)-\theta*\sigma(t))^2+\beta*\sigma(t)^2\) where \(\omega=\sigma*(1-\alpha*(1+\theta^2)-\beta)\)
I wrote a function as

Code:
function f=osllh(x)
r=xlsread('HW_3_Data','old vix','j4:j1257');
ovix=xlsread('HW_3_Data','old vix','f4:f1257');
sigma=var(r);
omega=sigma*(1-x(1)*(1+x(3)^2)-x(2));
llh=zeros(1254,1);
for n=1:1254
    opsigma=ones(1254,1);
    opsigma(1,1)=sigma;
    for t=1:1253
        opsigma(t+1,1)=omega+x(1)*(r(t,1)-x(3)*opsigma(t,1)^0.5)^2+x(2)*opsigma(t,1)+x(4)*ovix(t,1)^2/252;
    end
    ollh(n,1)=-0.5*log(2*3.1415926)-0.5*log(opsigma(n,1))-0.5*(r(n,1)^2/opsigma(n,1));   
end
    f=-sum(ollh);
end
then use fmincon to call it. But seems that it doesn't converge. The matlab just keep searching and searching and never stops.

Anyone can give me some advice?

Thank you
 
First, the code in your .m file is not correct. You need to use ollh consistently throughout the function. I assume osllh, llh are typos and should be ollh. If they are other function calls, you need to post the function body.
Second, you need to attach the HW_3_data.xls for people to be able to test this ollh function. Without it, there isn't much people can help.
 
Sorry. I'll just repost the code with the data file attached.

[x,fval]=fmincon(@ollh,x0,[],[],[],[],[],[],@mycon)

Code:
function f=ollh(x)
r=xlsread('HW_3_Data','old vix','j4:j1257');
ovix=xlsread('HW_3_Data','old vix','f4:f1257');
sigma=var(r);
omega=sigma*(1-x(1)*(1+x(3)^2)-x(2));
llh=zeros(1254,1);
for n=1:1254
    opsigma=ones(1254,1);
    opsigma(1,1)=sigma;
    for t=1:1253
        opsigma(t+1,1)=omega+x(1)*(r(t,1)-x(3)*opsigma(t,1)^0.5)^2+x(2)*opsigma(t,1)+x(4)*ovix(t,1)^2/252;
    end
    ollh(n,1)=-0.5*log(2*3.1415926)-0.5*log(opsigma(n,1))-0.5*(r(n,1)^2/opsigma(n,1));   
end
    f=-sum(ollh);
end


About the constraint function:

Code:
function [c,ceq]=mycon(x)
c(1)=x(1)*(1+x(3)^2)+x(2)-1;
ceq=[]
end


Thank you!
 

Attachments

Back
Top