I was wondering if someone familiar with the RQuantLib library can have a look and let me know if this makes sense.

I am trying to get total return of a 5 year constant maturity treasury bond. Does the below make sense?

### Bonds
# Calculate total returns from the yield of 5 year constant matury bond    
getSymbols("DGS5", src="FRED") #load US Treasury 5y yields from FRED
data <-DGS5
for (i in 1:(nrow(data)-1)) {
temp <- FixedRateBondPriceByYield(yield=data[i+1,1]/100, issueDate=Sys.Date(), maturityDate=advance("UnitedStates/GovernmentBond", Sys.Date(), 10, 3),  rates=data[i,1]/100,period=2)[1]/100-1                         

#total return will be the price return + yield/360
tret <- ret + lag(data,k=1)/360/100


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.