eddelbuettel / rquantlib

R interface to the QuantLib library
119 stars 50 forks source link

FixedRateBond() not working with some Maturity Dates #90

Closed aalvero closed 7 years ago

aalvero commented 7 years ago

The function FixedRateBond() does not work for certain parameters.

For instance, the following parameters will yield a message error. I tried to change all the parameters, even change the maturityDate a little bit, but nothing works. However, the example in the pdf manual work. I could not find the source of the problem.

Here is the code:

price <- 100
bond <- list(settlementDays=3, issueDate=as.Date("1989-10-24"),
             faceAmount=100, accrualDayCounter='Thirty360',
             paymentConvention='Following')
schedule <- list(effectiveDate=as.Date("1989-10-24"),
                 maturityDate=as.Date("2001-11-01"),
                 period='Semiannual',
                 calendar='UnitedStates/GovernmentBond',
                 businessDayConvention='Unadjusted',
                 terminationDateConvention='Unadjusted',
                 dateGeneration='Forward',
                 endOfMonth=1)
calc=list(dayCounter='Thirty360', compounding='Continuous',
          freq='Semiannual', durationType='Modified')

rates <- c(0.0945)

FixedRateBond(bond, rates, schedule, calc, price=price)

The error message:

Error in FixedRateWithPrice(bond, rates, schedule, calc, price) : 
  non tradable at July 11th, 2017 (maturity being November 1st, 2001)

As information, here are the details of the R Session (R version 3.4.1, and RQuantLib_0.4.3) :

R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RQuantLib_0.4.3   jrvFinance_1.03   zoo_1.8-0         bizdays_1.0.3     lubridate_1.6.0  
[6] data.table_1.10.4 RJDBC_0.2-5       DBI_0.7           rJava_0.9-8      

loaded via a namespace (and not attached):
[1] compiler_3.4.1  magrittr_1.5    tools_3.4.1     Rcpp_0.12.11    stringi_1.1.5   grid_3.4.1     
[7] stringr_1.2.0   lattice_0.20-35
tleitch commented 7 years ago

It's trying to value a bond today that matured over a decade ago. Either use live bond or change the valuation date to correspond with the life ofthe bond.

On Jul 6, 2017, at 11:00 PM, aalvero notifications@github.com wrote:

The function FixedRateBond() does not work for certain parameters.

For instance, the following parameters will yield a message error. I tried to change all the parameters, even change the maturityDate a little bit, but nothing works. However, the example in the pdf manual work. I could not find the source of the problem.

Here is the code:

price <- 100 bond <- list(settlementDays=3, issueDate=as.Date("1989-10-24"), faceAmount=100, accrualDayCounter='Thirty360', paymentConvention='Following') schedule <- list(effectiveDate=as.Date("1989-10-24"), maturityDate=as.Date("2001-11-01"), period='Semiannual', calendar='UnitedStates/GovernmentBond', businessDayConvention='Unadjusted', terminationDateConvention='Unadjusted', dateGeneration='Forward', endOfMonth=1) calc=list(dayCounter='Thirty360', compounding='Continuous', freq='Semiannual', durationType='Modified')

rates <- c(0.0945)

FixedRateBond(bond, rates, schedule, calc, price=price)

The error message:

Error in FixedRateWithPrice(bond, rates, schedule, calc, price) : non tradable at July 11th, 2017 (maturity being November 1st, 2001) — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

aalvero commented 7 years ago

Thanks! So I should change setEvaluationDate(). However, I need to compute the yield on a lot of historical bonds within a data.table, And I will not be able to reset the valuation date for each bond. Is there a way to enter the trade date as a parameter instead ?

tleitch commented 7 years ago

You’ll need to reset the evaluation date if they’re different. And you’ll need to regenerate your discount curve as well.

On Jul 6, 2017, at 11:15 PM, aalvero notifications@github.com wrote:

Thanks! So I should change setEvaluationDate(). However, I need to compute the yield on a lot of historical bonds within a data.table, And I will not be able to reset the valuation date for each bond. Is there a way to enter the trade date as a parameter instead ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eddelbuettel/rquantlib/issues/90#issuecomment-313576404, or mute the thread https://github.com/notifications/unsubscribe-auth/AHBCovfoXeO85y19PuvWyXufHCGlApoEks5sLaLYgaJpZM4OQbky.