Page 1 of 1

Time-Varying Beta

Posted: Sat Aug 08, 2009 8:17 pm
by Kausikch
I am trying to use the beta.prg. However, I would like to forecast time-varying beta (in-sample and out-of-sample) along with forecasting evaluation criteria. How can I do it?

' BETA.PRG (3/7/2007)
' Time varying beta
' demonstrates several ways
' to obtain beta between assets
' 1) constant beta
' 2) rolling beta by regression/moving cov/var
' 3) using state space
' 4) using multivariate ARCH
' Checked 3/20/2007

'change path to program path
%path = @runpath
cd %path

' load workfile
load fx.wf1

' dependent variables of series must be continuous
smpl @all
series y1 = @pch(index)
series y2 = @pch(jy)

'------------------------------------------------------------------------
' calculate the constant beta using OLS
'------------------------------------------------------------------------
smpl 1990 @last
equation constant_beta.ls y2 c y1
series beta_const=c(2)

'------------------------------------------------------------------------
' calculating time varying beta with rolling regression
' for a bi-variate case can use moving cov/var instead
' of OLS regression
'------------------------------------------------------------------------
!ssize = 200
series beta_roll=@movcov(y1,y2,!ssize)/@movvar(y1,!ssize)

' code for running a rolling regression:
' commented out right now

'!length = @obs(y1)
'equation roll_beta.ls y2 c y1
'show roll_beta

'for !i = 1 to !length-!ssize+1
' smpl @first+!i-1 @first+!i+!ssize-2
' equation roll_beta.ls y2 c y1
' smpl @first+!i+!ssize-2 @first+!i+!ssize-2
' beta_roll = roll_beta.@coefs(2)
'next

'------------------------------------------------------------------------
' calculate beta with State Space
' via a time-varying coefficient for Y1
'------------------------------------------------------------------------
smpl 1990 @last
sspace ssbeta
ssbeta.append y2=c(1)+sv1*y1+[var=exp(c(2))]
ssbeta.append @state sv1 = sv1(-1)
ssbeta.ml
ssbeta.makestates beta_*
rename beta_sv1 beta_ss

'------------------------------------------------------------------------
' calculate beta with system ARCH
' by estimating the covariance and variance of
' the two series using Multivariate ARCH
'------------------------------------------------------------------------
system arbeta
arbeta.append y1 = c(1)
arbeta.append y2 = c(2)

arbeta.arch @Diagvech c(indef) arch(1,indef) garch(1,indef)

arbeta.makegarch(name=arch)

series beta_arch = arch01_02/arch01

'------------------------------------------------------------------------
' display the different betas
'------------------------------------------------------------------------
group betas_ls_roll beta_const beta_roll
group betas_roll_ss_arch beta_roll beta_ss beta_arch

show betas_ls_roll.line
show betas_roll_ss_arch.line