|
From: <mat...@gm...> - 2020-12-16 20:51:16
|
Hello “Random User”,
Your example made me try out the QuantLib R extension which I never used before. Put your code into a file if someone else wants to try – I believe the attachment may survive distribution in this list.
Anyway this will not be the answer you hoped for, but let me share an anecdotal (attempt of) advice.
Some while ago I tried to essentially do the same: Fit a curve based on government bonds. My dataset also included several bonds at the same tenor, so the first approach to simply pass the bonds to a function like this (Python code)…
ql.PiecewiseLogCubicDiscount(settle_days, calendar, bond_helpers, day_count)
…required to filter the dataset to avoid such “collisions”.
With that, I got a somewhat bumpy curve with quite some oscillations on the short tenors. So, in order to smoothen that curve, I used the same class you also used, but chose cubic splines instead of exponential, because some paper suggested so. Do not remember which, but not the ones mentioned in the C++ documentation of the regarding class. Well, I did not read them, but I am pretty sure the one I had was way more recent.
ql.FittedBondDiscountCurve(settle_days,
calendar,
bond_helpers,
day_count,
ql.CubicBSplinesFitting(knots, True),
tolerance,
iterations)
That said, I also tried Nelson-Siegel and indeed the exponential splines, but both methods would give me the linear curve you got as well. So I quickly discarded them without much thinking about as to why this kind of “deformation” may have happened.
Speaking of deformation: I had to do some uneducated tweaking for the control knots vector to get suitable results where “suitable results” means: pricing of some benchmark corporate bonds yielded reasonable results.
Not sure if there a good universal way to choose those knots, looking again at the C++ code docs:
\warning "The results are extremely sensitive to the number
and location of the knot points, and there is no
optimal way of selecting them." James, J. and
N. Webber, "Interest Rate Modelling" John Wiley,
2000, pp. 440.
So, all in all not very scientific and more of a fun exercise. But all the same I am, too, interested in more details about this function. Suppose that more data cleansing could help, but I am pretty sure not to have included anything but plain bonds.
Regards,
Matthias
From: Random User <qld...@gm...>
Sent: Wednesday, 2 December 2020 08:59
To: qua...@li...
Subject: [Quantlib-users] FittedBondCurve in R
Hello all -
I'm trying to build a fitted US Treasury curve using FittedBondCurve(). However, my results are odd for two reasons. (1) the shape of the curve is a straight line and not concave as one might expect (2) the yields of the modeled term structure are within a very tight range for the entire curve and well below even the lowest yields in the yield dataset that is being fit (yields being fit are shown in the dataframe below).
The only possible issues I can suspect are day count issues in my dateparams (unclear why) or the function being able to fit multiple data points for a single maturity. On this second point, for example, I'm trying to model all outstanding Treasuries, so there are several bonds that sit at the same maturity point (eg. at the 1Y point there could be an originally issued 2Y bond that has aged 1 year along with an originally issued 30Y bond that has aged 29 years etc.).
I've included the relatively short code along with the dataset being fit to hopefully ease replication. This is very close to the QuantLib example for the function with the major difference that I'm trying to fit actual bond prices (the df that is referenced is shown in full below). Please let me know if you need more information. Thanks for any help!
[[ REMOVED ]]
|