\HeaderA{DiscountCurve}{Returns the discount curve (with zero rates and forwards) given times}{DiscountCurve}
\methaliasA{DiscountCurve.default}{DiscountCurve}{DiscountCurve.default}
\aliasA{plot.DiscountCurve}{DiscountCurve}{plot.DiscountCurve}
\keyword{models}{DiscountCurve}
\begin{Description}\relax
\code{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.
\end{Description}
\begin{Usage}
\begin{verbatim}
DiscountCurve(params, tsQuotes, times)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{params}] A list specifying the \code{tradeDate} (month/day/year),
\code{settleDate}, forward rate
time span \code{dt}, and two curve
construction options: \code{interpWhat} (with possible values
\code{discount}, \code{forward}, and \code{zero}) and
\code{interpHow} (with possible values \code{linear},
\code{loglinear}, and \code{spline}). \code{spline} here means cubic spline
interpolation of the \code{interpWhat} value.

\item[\code{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:
\Tabular{ll}{
\code{flat} & rate for a flat yield curve\\
\code{d1w}  & 1-week deposit rate\\
\code{d1m}  & 1-month deposit rate\\
\code{d3m}  & 3-month deposit rate\\
\code{d6m}  & 6-month deposit rate\\
\code{d9m}  & 9-month deposit rate\\
\code{d1y}  & 1-year deposit rate\\
\code{s2y}  & 2-year swap rate\\
\code{s3y}  & 3-year swap rate\\
\code{s5y}  & 5-year swap rate\\
\code{s10y} & 10-year swap rate\\
\code{s15y} & 15-year swap rate\\
\code{s20y} & 20-year swap rate\\
\code{s30y} & 30-year swap rate\\
\code{fut1}--\code{fut8} & 3-month futures contracts\\
\code{fra3x6} & 3x6 FRA\\
\code{fra6x9} & 6x9 FRA\\
\code{fra6x12}& 6x12 FRA
}
Here rates are expected as fractions (so 5\% means .05).
If \code{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.

\item[\code{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 \code{dt} does not exceed the longest
maturity of the instruments used for calibration (no extrapolation).

\end{ldescription}
\end{Arguments}
\begin{Details}\relax
This function is based on \code{QuantLib} Version 0.3.10. It
introduces support for fixed-income instruments in \code{RQuantLib}.

Forward rates and zero rates are computed assuming continuous
compounding, so the forward rate \eqn{f}{} over the
period from \eqn{t_1}{t1} to \eqn{t_2}{t2} is determined by the
relation
\deqn{d_1/d_2 = e^{f (t_2 - t_1)},}{d1/d2 = exp(f(t2 - t1)),}
where \eqn{d_1}{d1} and \eqn{d_2}{d2} are discount factors
corresponding to the two times. In the case of the zero rate
\eqn{t_1}{t1} 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 \code{interpWhat} and \code{interpHow}.
Fortunately, the C++ exception mechanism seems to work well with the R
interface, and \code{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 \code{QuantLib} code. Scroll to
the end to find information that is meaningful to the R user.)
\end{Details}
\begin{Value}
\code{DiscountCurve} returns a list containing:
\begin{ldescription}
\item[\code{times}] Vector of input times
\item[\code{discounts}] Corresponding discount factors
\item[\code{forwards}] Corresponding forward rates with time span \code{dt}
\item[\code{zerorates}] Corresponding zero coupon rates
\item[\code{params}] The input parameter list
\end{ldescription}
\end{Value}
\begin{Author}\relax
Dominick Samperi
\end{Author}
\begin{References}\relax
Brigo, D. and Mercurio, F. (2001) \emph{Interest Rate Models: Theory and
Practice}, Springer-Verlag, New York.

For information about \code{QuantLib} see \url{http://quantlib.org}.

For information about \code{RQuantLib} see
\url{http://dirk.eddelbuettel.com/code/rquantlib.html}.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{BermudanSwaption}{BermudanSwaption}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}

savepar <- par(mfrow=c(3,3))

# This data is taken from sample code shipped with QuantLib 0.3.10.
params <- list(tradeDate=as.Date('2002-2-15'),
               settleDate=as.Date('2002-2-19'),
               dt=.25,
               interpWhat="discount",
               interpHow="loglinear")

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)

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)

\end{ExampleCode}
\end{Examples}

