|
From: <fre...@sw...> - 2023-10-17 12:16:12
|
If I understand correctly, accuracy parameter moved some time ago from initialization of curve to bootstrap. However, I am struggling a bit how to specify it since the curve depends on bootstrap, which depends on curve…
Here is a minimal example:
void test()
{
auto eonia = ext::make_shared<Eonia>();
auto referenceDate = Date(17, Oct, 2023);
auto tenor = 1 * Months;
auto simple_quote = ext::make_shared<SimpleQuote>(0.01);
auto quote = Handle<Quote>(simple_quote);
auto instrument = ext::make_shared<OISRateHelper>(2, tenor, quote, eonia);
std::vector<ext::shared_ptr<RateHelper>> instruments = { instrument };
typedef PiecewiseYieldCurve<Discount, Cubic, IterativeBootstrap> this_curve;
// Here I initilize the PiecewiseYieldCurve without specifying bootstrap. This works
//auto termstructure1 = this_curve(referenceDate, instruments, Actual365Fixed());
// First we make a bootstrap object with a PieceWiseYieldCurve as template parameter
// We pass the IterativeBootstrap object to the PieceWiseYieldCurce constructor
Real accuracy = 0.0001;
auto myIterativeBootstrap = IterativeBootstrap<this_curve>(accuracy);
auto termstructure3 = this_curve(referenceDate, instruments, Actual365Fixed(), myIterativeBootstrap);
return;
}
However, this does not work but give me an error (at least using Clang on Visual Studio).
field has incomplete type 'IterativeBootstrap<QuantLib::PiecewiseYieldCurve<QuantLib::Discount, QuantLib::Cubic, QuantLib::IterativeBootstrap>::this_curve>' (aka 'IterativeBootstrap<PiecewiseYieldCurve<QuantLib::Discount, QuantLib::Cubic, QuantLib::IterativeBootstrap>>')
Oddly enough, If I uncomment the definition of termstructure1, it compiles.
I can make an even more minimal example:
// minimal example for clang/gcc incomplete class error:
void test2()
{
Real accuracy = 0.0001;
auto bootstrap_ex = IterativeBootstrap<PiecewiseYieldCurve<Discount, LogLinear>>(accuracy);
}
I strongly suspect I have misunderstood something here. How are you supposed to set the accuracy parameter for a curve?
BR
//Fredrik
From: Marcin Rybacki <mry...@gm...>
Sent: den 7 september 2023 17:56
To: Jonathan George <Jon...@ni...>
Cc: qua...@li...
Subject: Re: [Quantlib-users] Bootstrapped Yield Curve extrapolation help
External email. Do not click on links or attachments unless you recognize the sender.
Hi Jonathan,
I think that, at the moment, the library only offers flat forward extrapolation.
However, you could use the following workaround:
1) Build the curve, based on the original input rates, using linear log-discount interpolation without enabling the extrapolation
2) Retrieve the nodes of the curve, which I assume will be (in Python) a list of tuples with dates and discount factors
2) From this curve calculate a zero rate for the last node: last_zero_rate = crv.zeroRate(crv.maxTime(), ql.Continuous).rate()
3) Calculate a discount factor for the very last QuantLib date: max_dt = ql.Date.maxDate() By taking the exponent of the year fraction from the reference date to max date, times last zero rate and times -1. And append the nodes with this last tuple (date and discount factor)
4) Reconstruct the curve using ql.DiscountCurve(dates, discounts, day_counter) and enable extrapolation.
I think this should give the outcome you're looking for.
Please note that the above approach will only work for linear schemes. Applying it with e.g. cubic splines will lead to a different solution of the tridiagonal system, and the resulting curves will be slightly different.
Another downside is that bumping quote handles to obtain sensitivities will yield incorrect outcomes in the extrapolation region - so instead you would have to rebuild the curve to get the deltas.
Hope this helps.
Kind regards,
Marcin
On Thu, 24 Aug 2023 at 15:32, Jonathan George <Jon...@ni...<mailto:Jon...@ni...>> wrote:
Hi All,
I am hoping that I might be able to get some help from this forum.
Context:
I am trying to bootstrap a yield curve using piecewise flat forward interpolation between market obtained rates. Here is my output:
I am using python and my curve construction is quite straight forward with extrapolation enabled(I understand I am committing the cardinal sin by not posting my code, but hoping that this is theoretical enough a question for a straight forward answer)
Question:
Is it possible to fix the final zero rate post maturity of the last bond? It seems that enableExtrapolation is fixing the final forward rate making the zero rate decay over time. I am trying to avoid creating a custom function to return zero and forward rates post maturity of the final bond.
I have tried create two curves (a linear flat forward curve and a regular flat forward curve) and combining using CompositeZeroYieldStructure however I’m not sure which binary function to pass into the function.
Any help would be appreciated.
Regards
Jonathan George
Quantitative Developer
T:
+27 21 901 1363<tel:+27%2021%20901%201363>
36 Hans Strijdom Avenue
Foreshore, Cape Town, 8001
www.ninetyone.com |<http://ninetyone.com/>
<https://www.linkedin.com/company/ninetyone/>
Follow us<https://www.linkedin.com/company/ninetyone>
<https://ninetyone.com/>
_______________________________________________
QuantLib-users mailing list
Qua...@li...<mailto:Qua...@li...>
https://lists.sourceforge.net/lists/listinfo/quantlib-users
|