[R-SIG-Finance] RquantLib : FittedBondCurve function
Khanh Nguyen
knguyen at cs.umb.edu
Thu Nov 5 17:14:16 CET 2009
Hi Oliver,
I implemented RQuantLib's FittedBondCurve. I put your data through
FittedBondCurve.cpp (QuantLib/Examples/FittedBondCurve.cpp) and the
result follows that of RQuantLib. I don't know all the detail about
how quantlib does its curve fitting, so perhaps you will get better
explanation from QuantLib's mailing list.
knguyen at knguyen-laptop:~/Desktop/FittedBondCurve$ g++ -o newbond
FittedBondCurve2.cpp -lQuantLib -lm && ./newbond
Today's date: November 5th, 2009
Calculating fit for 15 bonds.....
(a) exponential splines
reference date : November 5th, 2009
number of iterations : 7264
Value for ts1 on November 5th, 2011
2.554127 % Simple continuous compounding
Value for ts1 on November 4th, 2014
2.659071 % Simple continuous compounding
Enclosed is the source code.
-k
On Thu, Nov 5, 2009 at 10:36 PM, Allen Kuo <allen_kuo at yahoo.com> wrote:
> Olivier:
>
> I've never used Rquantlib but the key to note for the underlying QuantLib code is that it is based on a multidimensional optimization problem- the mathematical solutions you get (and there may be multiple solutions to the problem- nonuniqueness here) may very well depend on where you inititalize your search (guessSolution_ in the code below).
>
> http://quantlib.svn.sourceforge.net/viewvc/quantlib/trunk/QuantLib/ql/termstructures/yield/fittedbonddiscountcurve.cpp?revision=16281&view=markup
>
> There are also iteration numbers and lamda parameters to play with in the original code. You can even change the optimization method if you have the time.
>
> Generally, that two year point will get you a kink in the curve since it is more out of line with the other coupons. Since you are minimizing pricing errors subject to a duration adjustment (gives you approximately yield), my guess is a single outlier is probably never going to be fit well with this generic methodology. To pull the curve down closer to this point, you may have to artificially add other points close to this bond, with a similar coupon. Then the optimization will weight this part of the curve more (but now, to the possible detriment of other points on the curve....).
>
> Generally, best fitting from 2 to 30 years accurately will not be easy- this is a global best fit, which may lead to local issues. May also consider just fitting 0-10 years separately from the longer tenors (10-30 years). For fair value pricing purposes, this may be a better bet.
>
> Finally, note also you're comparing zero rates to the coupons (I think). This may not be the best comparison. Par rates should come closer to the coupons.
>
> Best,
> Allen
>
>
> --- On Wed, 11/4/09, Olivier Schmitt <olivier.schmitt at gmail.com> wrote:
>
>
> From: Olivier Schmitt <olivier.schmitt at gmail.com>
> Subject: [R-SIG-Finance] RquantLib : FittedBondCurve function
> To: r-sig-finance at stat.math.ethz.ch
> Date: Wednesday, November 4, 2009, 6:33 PM
>
>
> Hi,
>
> I am trying to run an example based on the one provided in the
> documentation for FittedBondCurve, from RQuantLib but using current
> data.
>
>
>> library(RQuantLib)
> Loading required package: Rcpp
>> lengths <- c(2,5,7,10,30)
>> coupons<- c(0.0090,0.024,0.03,0.035,0.043)
>> dateparams <- list(settlementDays=0, period="Annual", dayCounter="SimpleDayCounter", businessDayConvention ="Unadjusted")
>> curveparams <- list(method="ExponentialSplinesFitting", origDate = Sys.Date())
>> curve <- FittedBondCurve(curveparams, lengths, coupons, dateparams)
>>
>> curve$table[2*365,]
> date zeroRates discount
> 730 2011-11-03 0.02553986 0.9502694
>> curve$table[5*365,]
> date zeroRates discount
> 1825 2014-11-02 0.02658928 0.8756396
>
> So, it seems the output curve does not fit the short end data very
> well. Are there further parameters that I could adjust to improve
> this?
>
> Thanks!
>
> Olivier
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>
>
>
>
> [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>
More information about the R-SIG-Finance
mailing list