2016年9月19日月曜日

S&P 500 model from 1992-01-01 to 2016-04-01




Red line shows actual, black one for the forecast. The graph starts from 1992-01-01 and ends at 2016-04-01 on a quarterly basis.


start_date <- "1992-01-01"
end_date <-  "2016-04-01"
(summary(lm(to.quarterly(SP5[paste(start_date,end_date,sep='::')])[,4] ~
              to.quarterly(PAYEMS[paste(start_date,end_date,sep='::')])[,4] *
                   to.quarterly(UNDCONTSA[paste(start_date,end_date,sep='::')])[,4] *
                    GDPC96[paste(start_date,end_date,sep='::')])))



Below shows how to draw the graph.

plot(to.quarterly(SP5[paste(start_date,end_date,sep='::')])[,4],col=2,ylim=c(0,2500))
par(new=T)
plot(seq(as.Date(start_date),as.Date(end_date),by="quarter"),predict(lm(to.quarterly(SP5[paste(start_date,end_date,sep='::')])[,4] ~
       to.quarterly(PAYEMS[paste(start_date,end_date,sep='::')])[,4] *    
           to.quarterly(UNDCONTSA[paste(start_date,end_date,sep='::')])[,4] *
GDPC96[paste(start_date,end_date,sep='::')])),ylim=c(0,2500),ylab="",type='l')


0 件のコメント: