Hi all,
Can someone help point out what I am doing wrong? I am getting convergence errors when trying to bootstrap a yield curve using cubic spline. I have narrowed it down to a test case which is just a flat yield curve with 3 instruments (1w and 1m cash and 2y swap) all at 6%. The main code is: depoFRASwapInstruments.push_back(d1w); depoFRASwapInstruments.push_back(d1m); depoFRASwapInstruments.push_back(s2y); boost::shared_ptr<YieldTermStructure> depoFRASwapTermStructure(new PiecewiseYieldCurve<ZeroYield, Cubic>(settlementDate, depoFRASwapInstruments, termStructureDayCounter, tolerance, Cubic(CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative, 0.0, CubicInterpolation::SecondDerivative, 0.0))); // get 1 month discfact std::cout << "1-month discount factor: " << std::setprecision(8) << depoFRASwapTermStructure->discount(1 / 12.0, false); the error it returns is "convergence not reached after 99 iterations". I think the code is fine as sometimes it does work (ie. if I use flat 5% it works). But I often get convergence errors making things unstable. Am i missing something? Does it just not converge? Have attached the entire code. Thanks, Jon ------------------------------------------------------------------------------ Want excitement? Manually upgrade your production database. When you want reliability, choose Perforce Perforce version control. Predictably reliable. http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users swap.cpp (16K) Download Attachment |
Hi Jon,
your tolerance (1E-15) is very tight, try to relax that (in your example 1E-14 already works, but the standard value 1E-12 should be sufficient, too ?). Peter On 12 September 2014 20:22, Jon Lee <[hidden email]> wrote: > Hi all, > Can someone help point out what I am doing wrong? I am getting convergence > errors when trying to bootstrap a yield curve using cubic spline. I have > narrowed it down to a test case which is just a flat yield curve with 3 > instruments (1w and 1m cash and 2y swap) all at 6%. > > The main code is: > > depoFRASwapInstruments.push_back(d1w); > depoFRASwapInstruments.push_back(d1m); > depoFRASwapInstruments.push_back(s2y); > > boost::shared_ptr<YieldTermStructure> depoFRASwapTermStructure(new > PiecewiseYieldCurve<ZeroYield, Cubic>(settlementDate, > depoFRASwapInstruments, termStructureDayCounter, tolerance, > Cubic(CubicInterpolation::Spline, false, > CubicInterpolation::SecondDerivative, 0.0, > CubicInterpolation::SecondDerivative, 0.0))); > > // get 1 month discfact > std::cout << "1-month discount factor: " << std::setprecision(8) << > depoFRASwapTermStructure->discount(1 / 12.0, false); > > the error it returns is "convergence not reached after 99 iterations". > > I think the code is fine as sometimes it does work (ie. if I use flat 5% it > works). But I often get convergence errors making things unstable. Am i > missing something? Does it just not converge? > > Have attached the entire code. > > Thanks, > Jon > > ------------------------------------------------------------------------------ > Want excitement? > Manually upgrade your production database. > When you want reliability, choose Perforce > Perforce version control. Predictably reliable. > http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk > _______________________________________________ > QuantLib-users mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-users > ------------------------------------------------------------------------------ Want excitement? Manually upgrade your production database. When you want reliability, choose Perforce Perforce version control. Predictably reliable. http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hi Peter,
Thank you for spotting this. Most of the code was copied for the demo swap valuation. Out of the office this week but will give this a try when I get back. Thanks, Jon > On 13 Sep 2014, at 12:39, Peter Caspers <[hidden email]> wrote: > > Hi Jon, > your tolerance (1E-15) is very tight, try to relax that (in your > example 1E-14 already works, but the standard value 1E-12 should be > sufficient, too ?). > Peter > > >> On 12 September 2014 20:22, Jon Lee <[hidden email]> wrote: >> Hi all, >> Can someone help point out what I am doing wrong? I am getting convergence >> errors when trying to bootstrap a yield curve using cubic spline. I have >> narrowed it down to a test case which is just a flat yield curve with 3 >> instruments (1w and 1m cash and 2y swap) all at 6%. >> The main code is: >> >> depoFRASwapInstruments.push_back(d1w); >> depoFRASwapInstruments.push_back(d1m); >> depoFRASwapInstruments.push_back(s2y); >> >> boost::shared_ptr<YieldTermStructure> depoFRASwapTermStructure(new >> PiecewiseYieldCurve<ZeroYield, Cubic>(settlementDate, >> depoFRASwapInstruments, termStructureDayCounter, tolerance, >> Cubic(CubicInterpolation::Spline, false, >> CubicInterpolation::SecondDerivative, 0.0, >> CubicInterpolation::SecondDerivative, 0.0))); >> >> // get 1 month discfact >> std::cout << "1-month discount factor: " << std::setprecision(8) << >> depoFRASwapTermStructure->discount(1 / 12.0, false); >> >> the error it returns is "convergence not reached after 99 iterations". >> >> I think the code is fine as sometimes it does work (ie. if I use flat 5% it >> works). But I often get convergence errors making things unstable. Am i >> missing something? Does it just not converge? >> >> Have attached the entire code. >> >> Thanks, >> Jon >> >> ------------------------------------------------------------------------------ >> Want excitement? >> Manually upgrade your production database. >> When you want reliability, choose Perforce >> Perforce version control. Predictably reliable. >> http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk >> _______________________________________________ >> QuantLib-users mailing list >> [hidden email] >> https://lists.sourceforge.net/lists/listinfo/quantlib-users >> ------------------------------------------------------------------------------ Want excitement? Manually upgrade your production database. When you want reliability, choose Perforce. Perforce version control. Predictably reliable. http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by jlee
Hi, Thanks for the reply and highlighting about the compounding issue. Yes I agree the 6 month depo is not 6% if the the 3m and 3x3 FRA are 6% because of the compounding. In the code I might have created the quote but in the curve construction I only pass in 3 instruments (1w, 1m and 2y). This was just a test scenario so not real data but was getting errors. I think Peter's suggestion about the tolerance levels helps so will try that out. Thanks for looking at it.
------------------------------------------------------------------------------ Want excitement? Manually upgrade your production database. When you want reliability, choose Perforce. Perforce version control. Predictably reliable. http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |