Learn R Programming

RQuantLib (version 0.3.6)

FixedRateBond: Fixed-Rate bond pricing

Description

The FixedRateBond function evaluates a fixed rate bond using discount curve. More specificly, the calculation is done by DiscountingBondEngine from QuantLib. The NPV, clean price, dirty price, accrued interest, yield and cash flows of the bond is returned. For more detail, see the source codes in QuantLib's file test-suite/bond.cpp.

The FixedRateBondPriceByYield function calculates the theoretical price of a fixed rate bond from its yield.

The FixedRateBondYield function calculates the theoretical yield of a fixed rate bond from its price.

Usage

## S3 method for class 'default':
FixedRateBond(bond, rates, discountCurve, dateparams )

## S3 method for class 'default': FixedRateBondPriceByYield( settlementDays=1, yield, faceAmount, effectiveDate, maturityDate, period, calendar="us", rates, dayCounter=2, businessDayConvention=0, compound = 0, redemption=100, issueDate)

## S3 method for class 'default': FixedRateBondYield( settlementDays=1, price, faceAmount, effectiveDate, maturityDate, period, calendar="us", rates, dayCounter=2, businessDayConvention=0, compound = 0, redemption=100, issueDate)

Arguments

bond
bond parameters, a named list whose elements are: ll{ issueDate a Date, the bond's issue date maturityDate a Date, the bond's maturity date faceAmount (Optional) a double, face am
rates
a numeric vector, bond's coupon rates
discountCurve
Can be one of the following: ll{ a DiscountCurve a object of DiscountCurve class For more detail, see example or the discountCurve function A 2 ite
dateparams
(Optional) a named list, QuantLib's date parameters of the bond. ll{ settlementDays (Optional) a double, settlement days. Default value is 1. calendar (Optional) a string, either
settlementDays
an integer, 1 for T+1, 2 for T+2, etc...
yield
yield of the bond
price
price of the bond
effectiveDate
bond's effective date
maturityDate
bond's maturity date
period
frequency of events,0=NoFrequency, 1=Once, 2=Annual, 3=Semiannual, 4=EveryFourthMonth, 5=Quarterly, 6=Bimonthly ,7=Monthly ,8=EveryFourthWeely,9=Biweekly, 10=Weekly, 11=Daily. For more information, see QuantLib's Frequency class
calendar
Business Calendar. Either us or uk
faceAmount
face amount of the bond
businessDayConvention
convention used to adjust a date in case it is not a valid business day. See quantlib for more detail. 0 = Following, 1 = ModifiedFollowing, 2 = Preceding, 3 = ModifiedPreceding, other = Unadjusted
dayCounter
day count convention. 0 = Actual360(), 1 = Actual365Fixed(), 2 = ActualActual(), 3 = Business252(), 4 = OneDayCounter(), 5 = SimpleDayCounter(), all other = Thirty360(). For more information, see QuantLib's DayCounter class
compound
compounding type. 0=Simple, 1=Compounded, 2=Continuous, all other=SimpleThenCompounded. See QuantLib's Compound class
redemption
redemption when the bond expires
issueDate
date the bond is issued

Value

  • The FixedRateBond function returns an object of class FixedRateBond (which inherits from class Bond). It contains a list with the following components:
  • NPVnet present value of the bond
  • cleanPriceclean price of the bond
  • dirtyPricedirty price of the bond
  • accruedAmountaccrued amount of the bond
  • yieldyield of the bond
  • cashFlowscash flows of the bond
  • The FixedRateBondPriceByYield function returns an object of class FixedRateBondPriceByYield (which inherits from class Bond). It contains a list with the following components:
  • priceprice of the bond
  • The FixedRateBondYield function returns an object of class FixedRateBondYield (which inherits from class Bond). It contains a list with the following components:
  • yieldyield of the bond

Details

A discount curve is built to calculate the bond value.

Please see any decent Finance textbook for background reading, and the QuantLib documentation for details on the QuantLib implementation.

References

http://quantlib.org for details on QuantLib.

Examples

Run this code
#Simple call with a flat curve
bond <- list(faceAmount=100,
             issueDate=as.Date("2004-11-30"),
             maturityDate=as.Date("2008-11-30"),
             redemption=100, 
             effectiveDate=as.Date("2004-11-30"))
dateparams <- list(settlementDays=1,
                   calendar="us", dayCounter = 'Thirty360', period=2, 
                   businessDayConvention = 4, terminationDateConvention=4,
                   dateGeneration=1, endOfMonth=1)
coupon.rate <- c(0.02875)
                       
params <- list(tradeDate=as.Date('2002-2-15'),
               settleDate=as.Date('2002-2-19'),
               dt=.25,
               interpWhat="discount",
               interpHow="loglinear")

discountCurve.flat <- DiscountCurve(params, list(flat=0.05))
FixedRateBond(bond, coupon.rate, discountCurve.flat, dateparams)


#Same bond with a discount curve constructed from market quotes
tsQuotes <- list(d1w  =0.0382,
                 d1m  =0.0372,
                 fut1=96.2875,
                 fut2=96.7875,
                 fut3=96.9875,
                 fut4=96.6875,
                 fut5=96.4875,
                 fut6=96.3875,
                 fut7=96.2875,
                 fut8=96.0875,
                 s3y  =0.0398,
                 s5y  =0.0443,
                 s10y =0.05165,
                 s15y =0.055175)

discountCurve <- DiscountCurve(params, tsQuotes)
FixedRateBond(bond, coupon.rate, discountCurve, dateparams)


#example with default dateparams
FixedRateBond(bond, coupon.rate, discountCurve)

##exampe with defaul bond parameter and dateparams
bond <- list(issueDate=as.Date("2004-11-30"),
             maturityDate=as.Date("2008-11-30"))
dateparams <- list(calendar="us",
                   dayCounter = "ActualActual", 
                   period="Annual")
FixedRateBond(bond, coupon.rate, discountCurve, dateparams)


FixedRateBondPriceByYield(,0.0307, 100000, as.Date("2004-11-30"), as.Date("2008-11-30"), 3, , c(0.02875), , , , ,as.Date("2004-11-30"))

FixedRateBondYield(,90, 100000, as.Date("2004-11-30"), as.Date("2008-11-30"), 3, , c(0.02875), , , , ,as.Date("2004-11-30"))

Run the code above in your browser using DataLab