public
Created

what if 10 year goes to 0

  • Download Gist
what if go to 0.r
R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
require(quantmod)
require(PerformanceAnalytics)
require(RQuantLib)
require(latticeExtra)
 
 
getSymbols("DGS10",src="FRED")
GS10 <- to.monthly(DGS10)[,4]
 
 
getSymbols("GS10",src="FRED")
#Fed monthly series of yields is the monthly average of daily yields
#set index to yyyy-mm-dd format rather than to.monthly mmm yyy for better merging later
index(GS10)<-as.Date(index(GS10))
#add next month as 0%
GS10 <- rbind(GS10,as.xts(0,order.by=as.Date("2012-10-01")))
GS10pricereturn<-GS10
 
GS10pricereturn[1,1]<-0
colnames(GS10pricereturn)<-"PriceReturn-monthly avg GS10"
#use quantlib to price the GS10 and BAA bonds from monthly yields
#GS10 and BAA series are 20-30 year bonds so will advance date by 25 years
for (i in 1:(NROW(GS10)-1)) {
GS10pricereturn[i+1,1]<-FixedRateBondPriceByYield(yield=GS10[i+1,1]/100,issueDate=Sys.Date(),
maturityDate= advance("UnitedStates/GovernmentBond", Sys.Date(), 10, 3),
rates=GS10[i,1]/100,period=2)[1]/100-1
}
 
#total return will be the price return + yield/12 for one month
GS10totalreturn<-GS10pricereturn+lag(GS10,k=1)/12/100
colnames(GS10totalreturn)<-"TotalReturn-monthly avg GS10"
GS10totalreturn[1,1] <- 0
 
GS10cumul <- cumprod(GS10totalreturn+1)
asTheEconomist(xyplot(GS10cumul,scales=list(y=list(rot=0)),
main="US 10 Year Cumulative Growth since 1954"))
asTheEconomist(xyplot(log(GS10cumul),
scales=list(y=list(rot=0)),
main="US 10 Year Cumulative Growth (log scale) since 1954"))
asTheEconomist(xyplot(ROC(GS10cumul,12, type = "discrete"),
scales=list(y=list(rot=0)),
main="US 10 Year 12 Month Total Return since 1954"))
roc <- ROC(GS10,12,type="discrete")
asTheEconomist(xyplot(roc["::2012-09-01"],
scales=list(y=list(rot=0)),
main="US 10 Year 12 Month % Change in Yield since 1954"))
roc["2012-10-01"] <- -1
asTheEconomist(xyplot(roc,
scales=list(y=list(rot=0)),
main="US 10 Year 12 Month % Change in Yield (with 0% for October 2012) since 1954"))
 
plot.zoo(GS10)
asTheEconomist(xyplot(diff(GS10,6),
scales=list(y=list(rot=0)),
main="US 10 Year 6 Month Change in Yield since 1954"))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.