我遇到的问题与2014年类似问题中已经指出的问题相同。当我使用FixedRateBond()时,它只能在正利率下工作。对于负利率,例如下面的代码示例,我收到以下错误消息:
Error in FixedRateWithRebuiltCurve(bond, rates, schedule, calc, c(discountCurve$table$date), :
invalid value (-0.00382448) at index 0
我已经在参数列表(“ interpHow”)中尝试了不同的插值方法,并且结果相同。关于这个问题有新的发展吗?
谢谢大家的帮助。
问候,
罗马
RQuantLib版本0.4.5
RStudio 1.1.456
Windows 10企业版
library(RQuantLib)
##### FUNCTION #####
getLoanPV <- function(evalDate, rates, faceAmount, scheduleStart, scheduleEnd, period, quotes){
bond_settlementDays <- 1
bond_issueDate <- scheduleStart
bond_dayCount <- 'Actual360' # 'Actual360' or 'Thirty360' or 'ActualActual.ISMA'
bond_paymentConvention <- 'Unadjusted'
bond_redemption <- 100 # redemption in percent of face amount
schedule_endOfMonth <- 1 # end of month rule for schedule (0 or 1)
schedule_calendar <- 'TARGET' # 'UnitedStates/GovernmentBond' or 'TARGET'
schedule_businessDayConvention <- 'Following' # day convention e.g. 'Unadjusted' or 'Following
schedule_terminationDateConvention <- 'Following' # day convention for the terminal date
schedule_dateGeneration <- 'Forward' # or 'Backward'
params_dt <- .25
params_tradeDate <- scheduleStart
params_settleDate <- scheduleStart
params_interpWhat <- "discount" # 'discount', 'forward' or 'zero'
params_interpHow <- "linear" # 'linear', 'loglinear' or 'spline'
calc_freq <- 'Annual'
calc_dayCounter <- 'Actual360'
calc_compounding <- 'Compounded'
calc_durationType <- 'Simple' # type of duration to be calculated either 'Modified' or 'Simple'
bond <- list(settlementDays=bond_settlementDays,
issueDate=bond_issueDate,
faceAmount=faceAmount,
redemption=bond_redemption,
accrualDayCounter=bond_dayCount,
paymentConvention=bond_paymentConvention)
schedule <- list(effectiveDate=scheduleStart,
maturityDate=scheduleEnd,
period=period,
calendar=schedule_calendar,
businessDayConvention=schedule_businessDayConvention,
terminationDateConvention=schedule_terminationDateConvention,
dateGeneration=schedule_dateGeneration,
endOfMonth=schedule_endOfMonth)
calc <- list(dayCounter=calc_dayCounter,
compounding=calc_compounding,
freq=calc_freq,
durationType=calc_durationType)
params <- list(tradeDate=params_tradeDate,
settleDate=params_settleDate,
dt=params_dt,
interpWhat=params_interpWhat,
interpHow=params_interpHow)
discountCurve <- DiscountCurve(params, tsQuotes=quotes)
setEvaluationDate(evalDate)
fixedBond <- FixedRateBond(bond, rates, schedule, calc, discountCurve)
return(fixedBond)
}
##### MARKET DATA #####
quotesUSD <- list(d1w = -0.00377,
d1m = -0.0037,
d3m = -0.00319,
d6m = -0.00266,
d1y = -0.001647142,
s2y = -0.00156734,
s3y = -0.000270082,
s4y = 0.001146253,
s5y = 0.002525317,
s7y = 0.005082692,
s10y = 0.008162651,
s20y = 0.01208969)
##### FUNCTION CALL #####
loan01 <- getLoanPV(evalDate = as.Date("2018-08-22"),
rates = c(0.0407025),
faceAmount = 10000000,
scheduleStart = as.Date("2018-07-09"),
scheduleEnd = as.Date("2018-12-11"),
period = 'Annual',
quotes = quotesUSD)
loan02 <- getLoanPV(evalDate = as.Date("2018-08-22"),
rates = c(0.02, 0.025, 0.03, 0.035, 0.04, 0.045, 0.05, 0.055, 0.06),
faceAmount = 5000000,
scheduleStart = as.Date("2018-07-09"),
scheduleEnd = as.Date("2020-12-11"),
period = 'Quarterly',
quotes = quotesUSD)