見出し画像

NFCI vs. VIX  cut scale palette

概要

  • NFCI vs vix 週間平均値

  • 両者の回帰分析を示す

  • 入手可能な直近NFCI値を垂線で表す

ソースコード


TERM <- "2011::2023-01"
FC <- NFCI

w <- merge((apply.weekly(FC,mean))[TERM],as.vector((apply.weekly(VIX[,4],mean,na.rm=T))[TERM]))

colnames(w)<- c("FC","vix")
w <- merge(w,spx=as.vector(weeklyReturn(GSPC)[TERM]))
# w <- data.frame(w,s=cut(w$spx,breaks=c(min(w$spx),-0.025,0,0.025,max(w$spx)),labels=c('d','c','b','a'),include.lowest = T))
w <- data.frame(w,s=cut(w$spx,breaks=c(max(w$spx),0.02,0.01,0,-0.01,-0.02,min(w$spx)),labels=c('a','b','c','d','e','f'),include.lowest = T))
# w$s <- factor(w$s,levels=c('a','b','c','d'))
w$s <- factor(w$s,levels=c('f','e','d','c','b','a')) # this is critical. never remove nor comment out.

df <- w
p <- ggplot(df, aes(x=FC,y=vix,color=s))
p <- p + geom_point(alpha=0.9,size=2)
# p <- p + guide_legend(reverse = TRUE)
# p <- p + scale_color_gradient(low = "green", high = "blue",name = "vix")
# p  <- p + scale_color_gradient2( low = "#FF0000",mid="#FFFF00" , high = "#0000FF",midpoint=0)
# p <- p + scale_color_discrete(name='spx daily return',label=c('less than -0.025','between -0.025 and 0','between 0 and 0.025','more than 0.025'))
# p <- p + scale_color_discrete(name='spx weekly return',label=c('more than 0.02','more than 0.01','between 0.01 and 0','between 0 and -0.01','less than -0.01','less than -0.02'))

p <- p + scale_color_brewer(name='spx weekly return',label=c('more than 0.02','more than 0.01','between 0.01 and 0','between 0 and -0.01','less than -0.01','less than -0.02'),palette='Spectral')
p <- p + theme_dark(base_family = "HiraKakuPro-W3")
p <- p + stat_smooth(method = lm, formula = y ~ x,se=F,size=0.5,color='white')
p <- p + geom_vline(xintercept=((apply.weekly(FC,mean)) %>% last()), colour="white",size=0.4,alpha=0.5)
p <- p + geom_hline(yintercept=((apply.weekly(VIX[,4],mean,na.rm=T)) %>% last()), colour="white",size=0.4,alpha=0.5)
p <- p + xlab("Financial Condition") + ylab("VIX")   
plot(p)

サンプル出力

この記事が気に入ったらサポートをしてみませんか?