Skip to content

Instantly share code, notes, and snippets.

@mbusigin
Last active December 21, 2015 04:39
Show Gist options
  • Save mbusigin/6250782 to your computer and use it in GitHub Desktop.
Save mbusigin/6250782 to your computer and use it in GitHub Desktop.
30s, 20s and LTGOVTBD don't have a contiguous series. This piece of code merges the three in that order of preference. Potential improvement - estimate term premium to have consistent constant maturity of 30y.
mergeLongEnd = function()
{
if ( exists("DGS20") == FALSE ) { getSymbols("DGS20", src="FRED") }
if ( exists("DGS30") == FALSE ) { getSymbols("DGS30", src="FRED") }
if ( exists("LTGOVTBD") == FALSE ) { getSymbols("LTGOVTBD", src="FRED") }
a = merge(DGS30, LTGOVTBD, DGS20)
a$s = a$DGS30
a$s[is.na(a$s)] = a$DGS20[is.na(a$s)]
a$s[is.na(a$s)] = a$LTGOVTBD[is.na(a$s)]
return(a$s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment