2019年10月8日火曜日

MOV and VIX on each months.



# 各月のCOVを計算して棒グラフにする。
# COVのデータを遡って、12で割り切れる最長のデータ長を計算する。
# データ長に基づいて、配列を作成し、それを数=12の行列に代入する。(行数=12でなくてはならない。注意!)
# apply(行列,1,mean)を実行して、月ごとの平均を計算する。
# 最終COVの月を計算して、データの並びを変える。最終月が10月なら、3,4,5,6,7,8,9,10,11,12,1,2となるように並べる。



df <- data.frame(cov=apply(matrix(last(COV,floor(length(COV)/12)*12),nrow=12),1,mean)[c(last(seq(1,12,1),month(last(index(COV)))),seq(1,(12 - month(last(index(COV)))),1))],
month=factor(seq(1,12,1)))
p <- ggplot(df,aes(x=month,fill=month))
p <- p + geom_bar(aes(y=cov),stat='identity')
p <- p + scale_x_discrete(label=c("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"))  #x-axis label
p <- p + theme(legend.position = 'none')  # erase legend
plot(p)





df <- data.frame(cov=apply(matrix(last(VIX[,4],floor(length(VIX[,4])/12)*12),nrowncol=12),12,mean)[c(last(seq(1,12,1),month(last(index(VIX[,4])))),seq(1,(12 - month(last(index(VIX[,4])))),1))],
month=factor(seq(1,12,1)))
p <- ggplot(df,aes(x=month,fill=month))
p <- p + geom_bar(aes(y=cov),stat='identity')
p <- p + scale_x_discrete(label=c("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"))  #x-axis label
p <- p + theme(legend.position = 'none')  # erase legend
plot(p)



0 件のコメント: