2017年6月22日木曜日

Calculate weekly standard deviation


Calculate weekly standard deviation from the start of 2017.

> w<-c();for(i in seq(0,trunc(length(day_xts$inc["2017"])/7)-1 ,1)){w<-append(w,sd(day_xts$inc["2017"][i*7 + c(1,2,3,4,5,6,7)]))};print(w);plot(w)

 [1] 65.57148 15.34834 29.44486 12.59251 21.51522 17.22816 10.75042 31.44534 25.34054 27.51017 24.53375 28.72779 31.99702 28.58238 22.88168 28.34818 17.07546
[18] 21.53181 42.79352 32.35444 19.64446 25.16895 24.29580 16.39832

for the case of 2016. The year is already finished, then magic number 52-1 is in place. it is ugly but acceptable for me.

> w<-c();for(i in seq(0,51 ,1)){w<-append(w,sd(day_xts$inc["2016"][i*7 + c(1,2,3,4,5,6,7)]))};print(w)

 [1] 48.606780 25.084619 24.538599 11.443443 20.049938 12.266874 20.221394 14.648257 17.941705 17.201883 19.345234 13.740798 30.581663 15.650955 18.997494 35.491783
[17] 19.474036 24.333986 19.550910 28.180540 18.927179 16.340135 14.404034 21.351926 23.831752 20.868066 22.401105 23.999008 20.497387 27.022918 28.678846 22.003247
[33] 29.384965 25.602269 17.305380 25.746937 20.846377 27.993196 22.112268 26.525819 24.013885 29.664794 22.166040 33.642377 21.883893 36.787032 24.006943 26.567076
[49] 20.317715  7.653197 14.893271 21.084863

2017年6月19日月曜日

2017JUN19 S&P 500 forecast


> as.xts(forecast(auto.arima(UC),h=10)$mean[1:10],as.Date(as.yearmon(seq(mondate(index(last(UC)))+1,by=1,length.out=10))))[(3-month(index(last(UC))) %% 3) + c(1,4,7)]
               [,1]
2017-07-01 1059.379
2017-10-01 1048.111
2018-01-01 1039.441
> as.xts(forecast(auto.arima(PA),h=10)$mean[1:10],as.Date(as.yearmon(seq(mondate(index(last(PA)))+1,by=1,length.out=10))))[(3-month(index(last(UC))) %% 3) + c(1,4,7)]
               [,1]
2017-07-01 146412.5
2017-10-01 146817.7
2018-01-01 147213.0

> my_sp5(last(GDP) * 1.05**(2/4),146412.5,1059)
[1] "m_m params! apply.quarter - UC w/ nominal GDP"
               GDP
2017-07-01 2471.38
> my_sp5(last(GDP) * 1.05**(3/4),146817.7,1048)
[1] "m_m params! apply.quarter - UC w/ nominal GDP"
                GDP
2017-10-01 2567.719
> my_sp5(last(GDP) * 1.05**(4/4),147213.0,1039)
[1] "m_m params! apply.quarter - UC w/ nominal GDP"
                GDP
2018-01-01 2661.749
> forecast(auto.arima(UC),h=10)$mean[1:10]
 [1] 1063.840 1059.379 1055.291 1051.545 1048.111 1044.965 1042.082 1039.441 1037.020 1034.801
>

2017年6月9日金曜日

子曰、君子固窮。小人窮斯濫矣


子曰、君子固窮。小人窮斯濫矣。

2017年6月4日日曜日

2 graphs S&P500 theoretical vs. actual and PAYEMS moving average


when kg is as below
> kg
[1] "1992-01-01::2017-03-31"

kikan <- kg
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(to.quarterly(SP5[kikan])[,1],type='l',ylim=c(0,2500))





l <- 300  # length of sample period
a <- 6     # base for moving average
plot(last(seq(as.Date("1992-01-01"),as.Date("2017-05-01"),by="months"),n=(l-a)),na.trim(filter(diff(last(PA,n=l)),rep(1,a))/a),type='h',ylim=c(-800,300))




Below will overlay moving average upon actual. Don't forget to set 'l' and 'a'.

 plot(last(seq(as.Date("1992-01-01"),as.Date("2017-05-01"),by="months"),n=(l-a)),na.trim(filter(diff(last(PA,n=l)),rep(1,a))/a),type='l',ylim=c(-800,500))
 par(new=T)
 plot(last(diff(PA),n=(l-a)),ylim=c(-800,500),col=2,type='h')

2017年6月3日土曜日

2017JUN02 S&P 500 forecast


> my_sp5(last(GDP) * 1.05**(2/4),146412.5,1070)
[1] "m_m params! apply.quarter - UC w/ nominal GDP"
                GDP
2017-07-01 2449.318
> my_sp5(last(GDP) * 1.05**(3/4),146817.7,1067.531)
[1] "m_m params! apply.quarter - UC w/ nominal GDP"
                GDP
2017-10-01 2527.037
> my_sp5(last(GDP) * 1.05**(4/4),147213.0,1065.085)
[1] "m_m params! apply.quarter - UC w/ nominal GDP"
                GDP
2018-01-01 2605.349

> as.xts(forecast(auto.arima(PA),h=10)$mean[1:10],as.Date(as.yearmon(seq(mondate(index(last(PA)))+1,by=1,length.out=10))))[(3-month(index(last(PA))) %% 3) + c(1,4,7)]
               [,1]
2017-07-01 146412.5
2017-10-01 146817.7
2018-01-01 147213.0

> forecast(auto.arima(PA),h=10)$mean[1:10]
 [1] 146274.7 146412.5 146548.9 146683.9 146817.7 146950.4 147082.1 147213.0 147343.0 147472.4