I want to use a Matlab script to calculate Heston Nandi GARCH prices. I found an appropriate script online and it asks for the "unconditional variance" as an input. How do I calculate the appropriate unconditional volatility? I found this formula online: $$\sigma^2 = s^2 = \frac{1}{n-1} * \sum_{t=1}^n [r^2_t] $$
Is this the appropriate one to use? Do I take the variance according to this formula for all asset returns up to the point in time of the option I am trying to value?
Full Script: `function OptionPrice=HestonNandi(S_0,X,Sig_,T,r)
%%%%%%%%%%%%% % this function calculates the price of Call option based on the GARCH % option pricing formula of Heston and Nandi(2000). The input to the % function are: current price of the underlying asset, strike price, % unconditional variance of the underlying asset, time to maturity in days, % and daily risk free interest rate. %%%%%%%%%%%
% Author: Ali Boloorforoosh % email: [email protected] % Date: Nov. 1,08
%%%%% sample inputs %%%%%
% S_0=100; stock price at time t
% X=100; strike prices
% Sig_=.04/252; unconditional variances per day
% T=30; option maturity
% r=.05/365; daily risk free rate
OptionPrice=.5*S_0+(exp(-r*T)/pi)quad(@Integrand1,eps,100)-Xexp(-rT)(.5+(1/pi)*quad(@Integrand2,eps,100));
% function Integrand1 and Integrand2 return the values inside the
% first and the second integrals
function f1=Integrand1(phi)
f1=real((X.^(-i*phi).*charac_fun(i*phi+1))./(i*phi));
end
function f2=Integrand2(phi)
f2=real((X.^(-i*phi).*charac_fun(i*phi))./(i*phi));
end
% function that returns the value for the characteristic function
function f=charac_fun(phi)
phi=phi'; % the input has to be a row vector
% GARCH parameters
lam=2;
lam_=-.5; % risk neutral version of lambda
a=.000005;
b=.85;
g=150; % gamma coefficient
g_=g+lam+.5; % risk neutral version of gamma
w=Sig_*(1-b-a*g^2)-a; % GARCH intercept
% recursion for calculating A(t,T,Phi)=A_ and B(t,T,Phi)=B_
A(:,T-1)=phi.*r;
B(:,T-1)=lam_.*phi+.5*phi.^2;
for i=2:T-1
A(:,T-i)=A(:,T-i+1)+phi.*r+B(:,T-i+1).*w-.5*log(1-2*a.*B(:,T-i+1));
B(:,T-i)=phi.*(lam_+g_)-.5*g_^2+b.*B(:,T-i+1)+.5.*(phi-g_).^2./(1-2.*a.*B(:,T-i+1));
end
A_=A(:,1)+phi.*r+B(:,1).*w-.5*log(1-2.*a.*B(:,1)); % A(t;T,phi)
B_=phi.*(lam_+g_)-.5*g_^2+b.*B(:,1)+.5*(phi-g_).^2./(1-2.*a.*B(:,1)); % B(t;T,phi)
f=S_0.^phi.*exp(A_+B_.*Sig_);
f=f'; % the output is a row vector
end
end
`