RQuantLib (version 0.4.7)

FloatingRateBond: Floating rate bond pricing

Description

The FloatingRateBond function evaluates a floating 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 test-suite. test-suite/bond.cpp

Usage

# S3 method for default
FloatingRateBond(bond, gearings, spreads,
                                   caps, floors, index, 
                                   curve, dateparams )

Arguments

bond

bond parameters, a named list whose elements are:

issueDate a Date, the bond's issue date
maturityDate a Date, the bond's maturity date
faceAmount (Optional) a double, face amount of the bond.
Default value is 100.
redemption (Optional) a double, percentage of the initial
face amount that will be returned at maturity
date. Default value is 100.
effectiveDate (Optinal) a Date, the bond's effective date. Default value is issueDate
gearings

(Optional) a numeric vector, bond's gearings. See quantlib's doc on FloatingRateBond for more detail. Default value is an empty vector c().

spreads

(Optional) a numeric vector, bond's spreads. See quantlib's doc on FloatingRateBond for more detail.Default value is an empty vector c()

caps

(Optional) a numeric vector, bond's caps. See quantlib's doc on FloatingRateBond for more detail. Default value is an empty vector c()

floors

(Optional) a numeric vector, bond's floors. See quantlib's doc on FloatingRateBond for more detail. Default value is an empty vector c()

curve

Can be one of the following:

a DiscountCurve a object of DiscountCurve class
For more detail, see example or
the discountCurve function
A 2 items list specifies a flat curve in two
values "todayDate" and "rate"
A 3 items list specifies three values to construct a
DiscountCurve object, "params" ,
"tsQuotes", "times".
For more detail, see example or
the discountCurve function
index

a named list whose elements are parameters of an IborIndex term structure.

type a string, currently support only "USDLibor"
length an integer, length of the index
inTermOf a string, period unit, currently support only 'Month'
term a DiscountCurve object, the term structure of the index
dateparams

(Optional) a named list, QuantLib's date parameters of the bond.

settlementDays (Optional) a double, settlement days.
Default value is 1.
calendar (Optional) a string, either 'us' or 'uk'
corresponding to US Goverment Bond
calendar and UK Exchange calendar.
Default value is 'us'.
dayCounter (Optional) a number or string,
day counter convention.
See Enum. Default value is 'Thirty360'
period (Optional) a number or string,
interest compounding interval. See Enum.
Default value is 'Semiannual'.
businessDayConvention (Optional) a number or string,
business day convention.
See Enum. Default value is 'Following'.
terminationDateConvention (Optional) a number or string,
termination day convention.
See Enum. Default value is 'Following'.
endOfMonth (Optional) a numeric with value 1 or 0.
End of Month rule. Default value is 0.
dateGeneration (Optional) a numeric, date generation method.
See Enum. Default value is 'Backward'

See example below.

Value

The FloatingRateBond function returns an object of class FloatingRateBond (which inherits from class Bond). It contains a list with the following components:

NPV

net present value of the bond

cleanPrice

clean price of the bond

dirtyPrice

dirty price of the bond

accruedAmount

accrued amount of the bond

yield

yield of the bond

cashFlows

cash flows 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
# NOT RUN {
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="UnitedStates/GovernmentBond",
                   dayCounter = 'ActualActual', period=2, 
                   businessDayConvention = 1, terminationDateConvention=1,
                   dateGeneration=0, endOfMonth=0, fixingDays = 1)

gearings <- spreads <- caps <- floors <- vector()

params <- list(tradeDate=as.Date('2002-2-15'),
               settleDate=as.Date('2002-2-19'),
               dt=.25,
               interpWhat="discount",
               interpHow="loglinear")
setEvaluationDate(as.Date("2004-11-22"))

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)
tsQuotes <- list("flat" = 0.02)		## While discount curve code is buggy

## when both discount and libor curves are flat.

discountCurve.flat <- DiscountCurve(params, list(flat=0.05))
termstructure <- DiscountCurve(params, list(flat=0.03))
iborIndex.params <- list(type="USDLibor", length=6, 
                  inTermOf="Month", term=termstructure)                      
FloatingRateBond(bond, gearings, spreads, caps, floors, 
                 iborIndex.params, discountCurve.flat, dateparams)


## discount curve is constructed from market quotes
## and a flat libor curve
discountCurve <- DiscountCurve(params, tsQuotes)
termstructure <- DiscountCurve(params, list(flat=0.03))
iborIndex.params <- list(type="USDLibor", length=6, 
                  inTermOf="Month", term = termstructure)                      
FloatingRateBond(bond, gearings, spreads, caps, floors, 
                 iborIndex.params, discountCurve, dateparams)

#example using default values
FloatingRateBond(bond=bond, index=iborIndex.params, curve=discountCurve)

# }

Run the code above in your browser using DataCamp Workspace