2017年7月31日月曜日

S&P500,GDP,PAYEMS,UNDCONTSA

# --------------------------------------- starts here
l <- 120  # # of months to predict
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.
r <- 1.05 # pesumed GDP growth rate
last(PA);last(UC);last(GDP)
m_GDP <- as.xts(as.vector(last(GDP)) * r**(i/4),d)
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]
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]
my_sp5(m_GDP,m_PA,m_UC)
# --------------------------------------- ends here

> my_sp5(m_GDP,m_PA,m_UC)
[1] "m_m params! apply.quarter - UC w/ nominal GDP"
               [,1]
2017-10-01 2584.017
2018-01-01 2677.548
2018-04-01 2767.463
2018-07-01 2855.281
2018-10-01 2942.127
2019-01-01 3028.843
2019-04-01 3116.057
2019-07-01 3204.248
2019-10-01 3293.780
2020-01-01 3384.937
2020-04-01 3477.938
2020-07-01 3572.961
2020-10-01 3670.150
2021-01-01 3769.625
2021-04-01 3871.485

2017年7月30日日曜日

2017Q2GDP and other economic data vs. S&P500


--------------------------------------------- starts here
last(GDP,n=3)
getSymbols("GDP",src="FRED");last(GDP,n=3)  # gdp
G <- GDP
last(PA)
getSymbols("PAYEMS",src="FRED");last(PAYEMS,n=3)  # non farm payroll
PA <- PAYEMS
last(UC)
getSymbols("UNDCONTSA",src="FRED");last(UNDCONTSA,n=3) # private housing under construction
UC <- UNDCONTSA
kikan <-  "1992-01-01::2017-04-30"
summary(lm(apply.quarterly(SP5[kikan],mean)[,1] ~ apply.quarterly(PA[kikan],mean) * apply.quarterly(UC[kikan],mean) * G[kikan] - apply.quarterly(UC[kikan],mean) ))
--------------------------------------------- ends here

Residual standard error: 104 on 95 degrees of freedom
Multiple R-squared:  0.9566, Adjusted R-squared:  0.9539
F-statistic:   349 on 6 and 95 DF,  p-value: < 2.2e-16