Created
June 11, 2013 02:13
-
-
Save mbusigin/5754073 to your computer and use it in GitHub Desktop.
Generate chart with 10y yield oscillator (10y yield minus 260d moving average), +/- 1 stdev dashed lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(quantmod) | |
recplot = function(var, maintitle="", ylab="", ylim=NULL) | |
{ | |
if ( exists("USRECD") == FALSE ) { getSymbols("USRECD", src="FRED", env=.GlobalEnv) } | |
a = na.locf(cbind(USRECD, var)) | |
a = a[ .index(a) %in% .index(var) ] | |
par(oma=c(0,0,0,0)) | |
par(xaxt="n", yaxt="n") | |
barplot(a$USRECD, border="grey", col="grey") | |
par(new=T, xaxt="s", yaxt="s") | |
plot(a[,2], main=maintitle, ylab=ylab, ylim=ylim) | |
} | |
getSymbols("DGS10", src="FRED") | |
recplot(DGS10 - SMA(na.omit(DGS10), n=260)) | |
dsd = sd(na.omit((DGS10 - SMA(na.omit(DGS10), n=260)))) | |
abline(h=dsd, lty=2) | |
abline(h=-dsd, lty=2) | |
legend("topright", c("10y minus its 1y mean", "+/- 1 stdev"), col="black", lty=c(1, 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment