# set the periods of calculation
kg <- "1992-01-01:: 2018-03-31"
kikan <- "1992-01-01:: 2018-03-31"
k2k <- "2000-01-01:: 2018-03-31" #GPUC model is based data only from 2000 because of cs index availability
# prepare parameters.
l <- 48 # # of months to predict
r <- 1.05 # pesumed GDP growth rate
i <- seq ( 2, l/3,1) # seq of quarters to predict
d <- as . Date( as. yearqtr ( seq ( Sys. Date( ), as. Date( "2100-12-31"), by="quarters") [i ])) # pick up the first day of each quarters .
# for the case the current time is more than 6 months away from the last GDP data, the below is to adjust # of months for GDP forecast.
# get data from FRED and storeselfregression data
getSymbols ( "GDP", src ="FRED")
G <- GDP
m_GDP <- as.xts(as.vector(last(GDP)) * r**(i/4),d)
getSymbols ( "PAYEMS", src ="FRED")
PA <- PAYEMS
m_PA <- (as.xts(forecast(auto.arima(PA),h=l)$mean[1:l],as.Date(as.yearmon(seq(mondate(index(last(PA)))+1,by=1,length.out=l))))[(3-month(index(last(PA))) %% 3) + seq(1,l-3,3)])[d]
getSymbols ( "UNDCONTSA", src ="FRED")
# UC <- UNDCONTSA
# comment out here until UNDCONTSA update is resumed in FRED.
m_UC <- (as.xts(forecast(auto.arima(UC),h=l)$mean[1:l],as.Date(as.yearmon(seq(mondate(index(last(UC)))+1,by=1,length.out=l))))[(3-month(index(last(UC))) %% 3) + seq(1,l-3,3)])[d]
getSymbols ( 'SPCS10RSA', src ='FRED')
CS <- SPCS10RSA
m_CS <-
(as.xts(forecast(auto.arima(CS),h=l)$mean[1:l],as.Date(as.yearmon(seq(mondate(index(last(CS)))+1,by=1,length.out=l))))[(3-month(index(last(CS))) %% 3) + seq(1,l-3,3)])[d]
# download data from yahoofinace before this.
SP5 <- as. xts ( read. zoo( read.csv( "~/SP5.csv")))
### caution still in debug
if ( floor( MonthsBetween ( mondate ( last( index( G))), mondate ( Sys. Date( )))) > 5) { i <- i+1}
### caution ends
# predict next 9qtrs . by GPU model
my_sp5(kikan,m_GDP[1:9],m_PA_backup[1:9],m_UC[1:9])
# by GPUCmodel borrow index from PA for case shiller index .
# use "as. xts ( )", not "xts ( )"
# this assumes caseshiller index of the next qtr is 223 and it will add 2 pts. each qtr .
my_sp5cs(k2k,m_GDP[1:9],m_PA[1:9],m_UC[1:9],as.xts(seq(223,223+2*8,2),index(m_PA[1:9])))
# or use m_CS[ 1:9]
k2k <- "2000-01-01:
# prepare parameters.
# for the case the current time is more than 6 months away from the last GDP data, the below is to adjust # of months for GDP forecast.
# get data from FRED and store
G <- GDP
m_GDP <- as.xts(as.vector(last(GDP)) * r**(i/4),d)
PA <- PAYEMS
m_PA <- (as.xts(forecast(auto.arima(PA),h=l)$mean[1:l],as.Date(as.yearmon(seq(mondate(index(last(PA)))+1,by=1,length.out=l))))[(3-month(index(last(PA))) %% 3) + seq(1,l-3,3)])[d]
# UC <- UNDCONTSA
# comment out here until UNDCONTSA update is resumed in FRED.
m_UC <- (as.xts(forecast(auto.arima(UC),h=l)$mean[1:l],as.Date(as.yearmon(seq(mondate(index(last(UC)))+1,by=1,length.out=l))))[(3-month(index(last(UC))) %% 3) + seq(1,l-3,3)])[d]
CS <- SPCS10RSA
m_CS
(as.xts(forecast(auto.arima(CS),h=l)$mean[1:l],as.Date(as.yearmon(seq(mondate(index(last(CS)))+1,by=1,length.out=l))))[(3-month(index(last(CS))) %% 3) + seq(1,l-3,3)])[d]
# download data from yahoo
SP5 <- as
### caution still in debug
### caution ends
# predict next 9
my_sp5(kikan,m_GDP[1:9],m_PA_backup[1:9],m_UC[1:9])
# by GPUC
# use "as
# this assumes case
my_sp5cs(k2k,m_GDP[1:9],m_PA[1:9],m_UC[1:9],as.xts(seq(223,223+2*8,2),index(m_PA[1:9])))
# or use m_CS
0 件のコメント:
コメントを投稿