Skip to content

Instantly share code, notes, and snippets.

@mbusigin
Created June 11, 2013 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbusigin/5754073 to your computer and use it in GitHub Desktop.
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
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