* * GARCHBACKTEST.RPF * Example of rolling estimates for GARCH model * * RATS User's Guide, Example from Section 11.2. * all 6237 open data g10xrate.xls data(format=xls,org=columns) / usxjpn * * Convert to percent daily returns * set x = 100.0*log(usxjpn/usxjpn{1}) * * Tail probability to evaluate * compute alpha=.10 * * Period of back test (roughly the last two years of the data, excluding * the last period). * compute tstart=%allocend()-520 compute tend =%allocend()-1 * set trigger tstart tend = 0.0 infobox(action=define,lower=tstart,upper=tend,progress) \$ "GARCH Model Backtest" garch(p=1,q=1,resids=u,hseries=h,print) / x compute fullbeta=%beta,fullxx=%xx do end=tstart,tend garch(p=1,q=1,resids=u,hseries=h,noprint,\$ initial=fullbeta,hessian=fullxx,iters=400) * end x * * Compute the one-step forecast for the variance * compute hhat=%beta(2)+%beta(3)*u(end)^2+%beta(4)*h(end) * * Compute the model's prediction for the VaR * compute limit=%beta(1)+%invnormal(alpha)*sqrt(hhat) * compute trigger(end)=(x(end+1)>alphahat compute pof=2*%nobs*((1-alphahat)*log((1-alphahat)/(1-alpha))+\$ alphahat*log(alphahat/alpha)) disp "POF measure" pof * * Christofferson Markov measure * sstats tstart+1 tend .not.trigger.and..not.trigger{1}>>n1 \$ .not.trigger.and.trigger{1}>>n2 \$ trigger.and..not.trigger{1}>>n3 \$ trigger.and.trigger{1}>>n4 compute p00=n1/(n1+n3),p10=n2/(n2+n4),p0=(n1+n2)/(n1+n2+n3+n4) * compute markov=n1*log(p00)+n3*log(1-p00)+n2*log(p10)+\$ n4*log(1-p10)-((n1+n2)*log(p0)+(n3+n4)*log(1-p0)) disp "Markov test" markov