2017年8月6日日曜日

S&P500 vs. GDP and other macroecnomic data and PAYEMS moving average


1.S&P500 vs macroenomics

kikan <- "1992-01-01::2017-06-30"
x <- seq(min(as.Date(index(to.quarterly(SP5[kikan])[,1]))),as.Date(max(index(to.quarterly(SP5[kikan])[,1]))),"quarters")
plot(predict(lm(to.quarterly(SP5[kikan])[,1] ~ apply.quarterly(PA[kikan],mean) * apply.quarterly(UC[kikan],mean) * GDP[kikan] - apply.quarterly(UC[kikan],mean) )),type='l',col=2,axes=F,ylim=c(0,2500),ylab="")
par(new=T)
plot(x,to.quarterly(SP5[kikan])[,1],type='l',ylim=c(0,2500))
par(new=T)
plot(x,rep(2000,length(x)),type='l',col=4,ylim=c(0,2500)) # draw the line at 2000 level
axis(side=2, pos=as.Date("2017-01-01"),labels=F)  # draw aux axis at 2017-01-01
par(new=T)
plot(x,rep(2250,length(x)),type='l',col=4,ylim=c(0,2500)) # draw the line at 2250 level

2.PAYEMS

----------- updated
l <- 300  # length of sample period
a <- 6     # base for moving average
print(strsplit(kikan,"::")[[1]][1])
x <- last(seq(as.Date(strsplit(kikan,"::")[[1]][1]),as.Date(last(index(PA))),by="months"),n=(l-a))
plot(x,na.trim(filter(diff(last(PA,n=l)),rep(1,a))/a),type='h',ylim=c(-800,300))
axis(side=2, pos=as.Date("2017-07-01"),labels=F)
par(new=T)
plot(x,rep(last(na.trim(filter(diff(last(PA,n=l)),rep(1,a))/a)),length(x)),typ='l',col=2,ylim=c(-800,300))
paste(head(x)[1],last(x),sep="::")  
par(new=T)
plot(SP5[paste(head(x)[1],last(x),sep="::")],axes=F,col=3)  # add spx.
------------- ends here

l <- 300  # length of sample period
a <- 6     # base for moving average
x <- last(seq(as.Date("1992-01-01"),as.Date(last(index(PA))),by="months"),n=(l-a))
plot(x,na.trim(filter(diff(last(PA,n=l)),rep(1,a))/a),type='h',ylim=c(-800,300))
axis(side=2, pos=as.Date("2017-07-01"),labels=F)
par(new=T)
plot(x,rep(173,length(x)),typ='l',col=2,ylim=c(-800,300))


3.GDP

x <- seq(as.Date(strsplit(kikan,'::')[[1]][1]),as.Date(strsplit(kikan,'::')[[1]][2]),"quarters")
plot(x,G[kikan],type='h')
axis(side=2, pos=as.Date("2008-07-01"),labels=F,col=2)
axis(side=1, pos=15000,labels=F,col=3)




0 件のコメント: