# NOT RUN {
#HAR of Corsi(2009)
#load data:
data("SP500RM")
SP500rv = SP500RM$RV
ForecastHAR = HARForecast(SP500rv, periods = c(1,5,22), nRoll =50,
nAhead = 50, type = "HAR")
#plot the forecasted series along with the actual realizations:
plot(ForecastHAR)
#Calculate the MSE:
mean(forecastRes(ForecastHAR)^2)
#Calculate the Q-like loss function:
mean(qlike(ForecastHAR))
#HARJ
#load data:
data("SP500RM")
SP500rv = SP500RM$RV
SP500bpv = SP500RM$BPV
ForecastHARJ = HARForecast(SP500rv, BPV = SP500bpv, periods = c(1,5,22),
periodsJ = c(1,5,22) ,nRoll = 50,
nAhead = 50, type = "HARJ")
#Show the model:
show(ForecastHARJ)
#Extract the forecasted series:
forc = getForc(ForecastHARJ)
#HARQ BPQ(2016)
#load data
data("SP500RM")
SP500rv = SP500RM$RV
SP500rq = SP500RM$RQ
ForecastHARQ = HARForecast(SP500rv, RQ= SP500rq, periods = c(1,5,22),
periodsRQ = c(1,5,22), nRoll = 50, nAhead = 50,
type = "HARQ")
#HARQ-J BPQ(2016) with weekly aggregation.
#load data
data("SP500RM")
SP500rv = SP500RM$RV
SP500rq = SP500RM$RQ
SP500bpv = SP500RM$BPV
ForecastHARQJ = HARForecast(SP500rv, RQ = SP500rq, BPV = SP500bpv,
periods = c(1,5,22), periodsJ = c(1,5,22),
periodsRQ = c(1,5,22), nRoll = 50,
nAhead = 1, type = "HARQ-J", h = 5)
# }
Run the code above in your browser using DataLab