convergence error for flat yield curve using cubic spline

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

convergence error for flat yield curve using cubic spline

jlee
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
Reply | Threaded
Open this post in threaded view
|

Re: convergence error for flat yield curve using cubic spline

Peter Caspers-4
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
Reply | Threaded
Open this post in threaded view
|

Re: convergence error for flat yield curve using cubic spline

jlee
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
Reply | Threaded
Open this post in threaded view
|

Re: convergence error for flat yield curve using cubic spline

jlee
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.

Jon
On 13 Sep 2014, at 19:49, BL BL <[hidden email]> wrote:

Hi,

i just had a quick look at your swap.cpp. Seems the deposit and the fras have some redundant quotes. Did you consider the compounding? I mean doing a 3M deposit and then a 3x3 FRA gives you a payment after 3 month. The 6 M deposit  does "compound" those two 3M Periods and pays only once at the end.

So flat 6% is not ok for the par quotes. Not all of them can have 6%. This holds only for the 6% cc yield cuve for example. But be aware of the discrete rates because of compounding.

2014-09-12 20:22 GMT+02:00 Jon Lee <[hidden email]>:
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