Learn R Programming

RQuantLib (version 0.4.24)

DiscountCurve: Returns the discount curve (with zero rates and forwards) given times

Description

DiscountCurve constructs the spot term structure of interest rates based on input market data including the settlement date, deposit rates, futures prices, FRA rates, or swap rates, in various combinations. It returns the corresponding discount factors, zero rates, and forward rates for a vector of times that is specified as input.

Usage

DiscountCurve(params, tsQuotes, times, legparams)

Value

DiscountCurve returns a list containing:

times

Vector of input times

discounts

Corresponding discount factors

forwards

Corresponding forward rates with time span dt

zerorates

Corresponding zero coupon rates

flatQuotes

True if a flat quote was used, False otherwise

params

The input parameter list

Arguments

params

A list specifying the tradeDate (month/day/year), settleDate, forward rate time span dt, and two curve construction options: interpWhat (with possible values discount, forward, and zero) and interpHow (with possible values linear, loglinear, and spline). spline here means cubic spline interpolation of the interpWhat value.

tsQuotes

Market quotes used to construct the spot term structure of interest rates. Must be a list of name/value pairs, where the currently recognized names are:

flatrate for a flat yield curve
d1w1-week deposit rate
d1m1-month deposit rate
d3m3-month deposit rate
d6m6-month deposit rate
d9m9-month deposit rate
d1y1-year deposit rate
s2y2-year swap rate
s3y3-year swap rate
s4y4-year swap rate
s5y5-year swap rate
s6y6-year swap rate
s7y7-year swap rate
s8y8-year swap rate
s9y9-year swap rate
s10y10-year swap rate
s12y12-year swap rate
s15y15-year swap rate
s20y20-year swap rate
s25y25-year swap rate
s30y30-year swap rate
s40y40-year swap rate
s50y50-year swap rate
s60y60-year swap rate
s70y70-year swap rate
s80y80-year swap rate
s90y90-year swap rate
s100y100-year swap rate
fut1--fut83-month futures contracts
fra3x63x6 FRA
fra6x96x9 FRA
fra6x126x12 FRA

Here rates are expected as fractions (so 5% means .05). If flat is specified it must be the first and only item in the list. The eight futures correspond to the first eight IMM dates. The maturity dates of the instruments specified need not be ordered, but they must be distinct.

times

A vector of times at which to return the discount factors, forward rates, and zero rates. Times must be specified such that the largest time plus dt does not exceed the longest maturity of the instruments used for calibration (no extrapolation).

legparams

A list specifying the dayCounter the day count convention for the fixed leg (default is Thirty360), and fixFreq, fixed coupon frequecny (defualt is Annual), floatFreq, floating leg reset frequency (default is Semiannual).

Author

Dominick Samperi

Details

This function is based on QuantLib Version 0.3.10. It introduces support for fixed-income instruments in RQuantLib.

Forward rates and zero rates are computed assuming continuous compounding, so the forward rate \(f\) over the period from \(t_1\) to \(t_2\) is determined by the relation $$d_1/d_2 = e^{f (t_2 - t_1)},$$ where \(d_1\) and \(d_2\) are discount factors corresponding to the two times. In the case of the zero rate \(t_1\) is the current time (the spot date).

Curve construction can be a delicate problem and the algorithms may fail for some input data sets and/or some combinations of the values for interpWhat and interpHow. Fortunately, the C++ exception mechanism seems to work well with the R interface, and QuantLib exceptions are propagated back to the R user, usually with a message that indicates what went wrong. (The first part of the message contains technical information about the precise location of the problem in the QuantLib code. Scroll to the end to find information that is meaningful to the R user.)

References

Brigo, D. and Mercurio, F. (2001) Interest Rate Models: Theory and Practice, Springer-Verlag, New York.

For information about QuantLib see https://www.quantlib.org/.

For information about RQuantLib see http://dirk.eddelbuettel.com/code/rquantlib.html.

See Also

BermudanSwaption

Examples

Run this code
if (FALSE) {
savepar <- par(mfrow=c(3,3), mar=c(4,4,2,0.5))

## This data is taken from sample code shipped with QuantLib 0.9.7
## from the file Examples/Swap/swapvaluation
params <- list(tradeDate=as.Date('2004-09-20'),
               settleDate=as.Date('2004-09-22'),
               dt=.25,
               interpWhat="discount",
               interpHow="loglinear")
setEvaluationDate(as.Date("2004-09-20"))

## We get numerical issue for the spline interpolation if we add
## any on of these three extra futures -- the original example
## creates different curves based on different deposit, fra, futures
## and swap data
## Removing s2y helps, as kindly pointed out by Luigi Ballabio
tsQuotes <- list(d1w = 0.0382,
                 d1m = 0.0372,
                 d3m = 0.0363,
                 d6m = 0.0353,
                 d9m = 0.0348,
                 d1y = 0.0345,
                 fut1=96.2875,
                 fut2=96.7875,
                 fut3=96.9875,
                 fut4=96.6875,
                 fut5=96.4875,
                 fut6=96.3875,
                 fut7=96.2875,
                 fut8=96.0875,
#                 s2y = 0.037125,
                 s3y = 0.0398,
                 s5y = 0.0443,
                 s10y = 0.05165,
                 s15y = 0.055175)

times <- seq(0,10,.1)

# Loglinear interpolation of discount factors
curves <- DiscountCurve(params, tsQuotes, times)
plot(curves,setpar=FALSE)

# Linear interpolation of discount factors
params$interpHow="linear"
curves <- DiscountCurve(params, tsQuotes, times)
plot(curves,setpar=FALSE)

# Spline interpolation of discount factors
params$interpHow="spline"
curves <- DiscountCurve(params, tsQuotes, times)
plot(curves,setpar=FALSE)

par(savepar)
}

Run the code above in your browser using DataLab