Skip to content

Commit

Permalink
Update Using HARModel.R
Browse files Browse the repository at this point in the history
  • Loading branch information
emilsjoerup committed Aug 31, 2019
1 parent 0650dc5 commit 9705e8e
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions Using HARModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ SP500rq = SP500RM$RQ
SP500bpv = SP500RM$BPV

#######################Estimation#######################
FitHAR = HARestimate(as.vector(SP500rv), periods = c(1,5,22))
FitHAR = HAREstimate(as.vector(SP500rv), periods = c(1,5,22))

FitCHAR = HARestimate(SP500rv, BPV = SP500bpv, periods = c(1,5,22), type = "CHAR")
FitCHAR = HAREstimate(SP500rv, BPV = SP500bpv, periods = c(1,5,22), type = "CHAR")

FitCHARQ = HARestimate(SP500rv, BPV = SP500bpv, RQ = SP500rq, periods = c(1,5,22), periodsRQ = c(1), type = "CHARQ")
FitCHARQ = HAREstimate(SP500rv, BPV = SP500bpv, RQ = SP500rq, periods = c(1,5,22), periodsRQ = c(1), type = "CHARQ")

FitHARJ = HARestimate(RM = SP500rv, BPV = SP500bpv,
FitHARJ = HAREstimate(RM = SP500rv, BPV = SP500bpv,
periods = c(1,5,22), periodsJ = c(1), type = "HARJ" )


FitHARQ = HARestimate(RM = SP500rv, RQ = SP500rq, periods = c(1,5,22 ),
FitHARQ = HAREstimate(RM = SP500rv, RQ = SP500rq, periods = c(1,5,22 ),
periodsRQ = c(1), type = "HARQ")

FitFullHARQ = HARestimate(RM = SP500rv, RQ = SP500rq, periods = c(1,5,22 ),
FitFullHARQ = HAREstimate(RM = SP500rv, RQ = SP500rq, periods = c(1,5,22 ),
periodsRQ = c(1,5,22), type = "HARQ")

FitHARQJ = HARestimate(RM = SP500rv, BPV = SP500bpv,
FitHARQJ = HAREstimate(RM = SP500rv, BPV = SP500bpv,
RQ = SP500rq, periods = c(1,5,22),
periodsJ = c(1,5,22), periodsRQ = c(1), type = "HARQ-J")

FitFullHARQJ = HARestimate(RM = SP500rv, BPV = SP500bpv,
FitFullHARQJ = HAREstimate(RM = SP500rv, BPV = SP500bpv,
RQ = SP500rq, periods = c(1,5,22),
periodsJ = c(1,5,22), periodsRQ = c(1,5,22), type = "HARQ-J")

Expand All @@ -48,49 +48,49 @@ mean(qlike(FitHARQ))

#######################Forecasting#######################

ForcHAR = HARforecast(SP500rv, periods = c(1,5,22) ,iNRoll = 3096, iNAhead = 50, type = "HAR" )
ForcHARI = HARforecast(SP500rv, periods = c(1,5,22) ,iNRoll = 3096,
iNAhead = 1, type = "HAR", windowType = "increasing" )
ForcHAR = HARForecast(SP500rv, periods = c(1,5,22) ,nRoll = 3096, nAhead = 50, type = "HAR" )
ForcHARI = HARForecast(SP500rv, periods = c(1,5,22) ,nRoll = 3096,
nAhead = 1, type = "HAR", windowType = "increasing" )


ForcHARJ = HARforecast(SP500rv, BPV = SP500bpv, periods = c(1,5,22),
periodsJ = c(1) ,iNRoll = 3096,
iNAhead = 50, type = "HARJ" )
ForcHARJI = HARforecast(SP500rv, BPV = SP500bpv, periods = c(1,5,22),
periodsJ = c(1) ,iNRoll = 3096,
iNAhead = 1, type = "HARJ", windowType = "increasing" )
ForcHARJ = HARForecast(SP500rv, BPV = SP500bpv, periods = c(1,5,22),
periodsJ = c(1) ,nRoll = 3096,
nAhead = 50, type = "HARJ" )
ForcHARJI = HARForecast(SP500rv, BPV = SP500bpv, periods = c(1,5,22),
periodsJ = c(1) ,nRoll = 3096,
nAhead = 1, type = "HARJ", windowType = "increasing" )

ForcFULLHARJ = HARforecast(SP500rv, BPV = SP500bpv, periods = c(1,5,22),
periodsJ = c(1,5,22) ,iNRoll = 3096,
iNAhead = 1, type = "HARJ" )
ForcHARQ = HARforecast(as.vector(SP500rv), RQ = SP500rq, periods = c(1,5,22),
periodsRQ = c(1), iNRoll = 3096, iNAhead = 1,
ForcFULLHARJ = HARForecast(SP500rv, BPV = SP500bpv, periods = c(1,5,22),
periodsJ = c(1,5,22) ,nRoll = 3096,
nAhead = 1, type = "HARJ" )
ForcHARQ = HARForecast(as.vector(SP500rv), RQ = SP500rq, periods = c(1,5,22),
periodsRQ = c(1), nRoll = 3096, nAhead = 1,
type = "HARQ" )

ForcFULLHARQ = HARforecast(SP500rv, RQ= SP500rq, periods = c(1,5,22),
periodsRQ = c(1,5,22), iNRoll = 3096, iNAhead = 1,
ForcFULLHARQ = HARForecast(SP500rv, RQ= SP500rq, periods = c(1,5,22),
periodsRQ = c(1,5,22), nRoll = 3096, nAhead = 1,
type = "HARQ" )

ForcHARQJ = HARforecast(as.numeric(SP500rv), RQ = SP500rq, BPV = SP500bpv,
ForcHARQJ = HARForecast(as.numeric(SP500rv), RQ = SP500rq, BPV = SP500bpv,
periods = c(1,5,22), periodsJ = c(1),
periodsRQ = c(1), iNRoll = 3096,
iNAhead = 1, type = "HARQ-J" )
periodsRQ = c(1), nRoll = 3096,
nAhead = 1, type = "HARQ-J" )

ForcCHAR = HARforecast(as.numeric(SP500rv), RQ = SP500rq, BPV = SP500bpv,
ForcCHAR = HARForecast(as.numeric(SP500rv), RQ = SP500rq, BPV = SP500bpv,
periods = c(1,5,22), periodsJ = c(1),
periodsRQ = c(1), iNRoll = 3096,
iNAhead = 1, type = "CHAR" )
periodsRQ = c(1), nRoll = 3096,
nAhead = 1, type = "CHAR" )

ForcCHARQ = HARforecast(as.numeric(SP500rv), RQ = SP500rq, BPV = SP500bpv,
ForcCHARQ = HARForecast(as.numeric(SP500rv), RQ = SP500rq, BPV = SP500bpv,
periods = c(1,5,22), periodsJ = c(1),
periodsRQ = c(1), iNRoll = 3096,
iNAhead = 1, type = "CHARQ" )
periodsRQ = c(1), nRoll = 3096,
nAhead = 1, type = "CHARQ" )

##Select loss functions from updated table 4 of BPQ:

mean(forecastres(ForcHAR)^2)/mean(forecastres(ForcHAR)^2)
mean(forecastres(ForcHARJ)^2)/mean(forecastres(ForcHAR)^2)
mean(forecastres(ForcCHAR)^2)/mean(forecastres(ForcHAR)^2)
mean(forecastRes(ForcHAR)^2)/mean(forecastRes(ForcHAR)^2)
mean(forecastRes(ForcHARJ)^2)/mean(forecastRes(ForcHAR)^2)
mean(forecastRes(ForcCHAR)^2)/mean(forecastRes(ForcHAR)^2)


mean(qlike(ForcHAR))/mean(qlike(ForcHAR))
Expand All @@ -101,11 +101,11 @@ mean(qlike(ForcCHAR))/mean(qlike(ForcHAR))
#######################Simulation#######################

set.seed(123)
lSim = HARsimulate(iLength = 4.5e4, periods = c(1,5,22),
coef = c(0.1, 0.38, 0.28, 0.28), Sigma = 0.01)
lSim = HARSimulate(len = 4.5e4, periods = c(1,5,22),
coef = c(0.1, 0.38, 0.28, 0.28), errorTermSD = 0.01)

plot(lSim)

FitSim = HARestimate(lSim@Simulation, periods = c(1,5,22))
FitSim = HAREstimate(lSim@Simulation, periods = c(1,5,22))

plot(FitSim)

0 comments on commit 9705e8e

Please sign in to comment.