yield calculation failing when resulting yield should be less than -54.4%

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

yield calculation failing when resulting yield should be less than -54.4%

ltorjul
Hi,

I have a problem it seems that BondFunctions::Yield(...) is failing when the yield should be -54.4% or less (more negative). The yield function throws the exception: "unable to bracket root in 100 function evaluations(last bracket attempt: f[-2.29538e+025,5.968e+025] -> [-1.#END, 51.1682])".

I have adjusted the price gradually and it seams that the most negative resulting yield I can compute without getting this error is -54,40688%.

I have tested this with various types of bonds, both fixed rate and floating rate. And look to be that the error occurs at a prices that gives yields exactly this yield or less (more negative).

Now, it may seem like a minor problem, when will prices be high enough to give such a negative yield?

1. What causes this error, and why at this point, logically yield should be able to anywhere from -100% to infinite positive)?

2. My scenario is that I want to compute duration and convexity for floating rate bonds. The street convention is to compute these with yield to next coupon date. Since I have not found any way to calculate yield to other dates than maturity, I fix this by creating a second floating rate bonds object with maturity equal to next coupon date for the first. Then using this to calculate yield to next coupon. In this situation the yield is often quite a bit negative, so this problem do occur quite often.

Could somebody please look into this?
Perhaps I can omit the entire problem by calculating yield to next coupon differently, but I cannot see how.

Thanks in advance.

Regards Lauritz



Reply | Threaded
Open this post in threaded view
|

Re: yield calculation failing when resulting yield should be less than -54.4%

Peter Caspers-4
Hi,

I did not reproduce your case, but I know that in extreme situations
the yield bracketing fails to work, although a sensible solution
exists (e.g. if you have a cashflow -100 in a few days and +0.1 in 10
years, -69% continously compounded yield is a solution, but the
bracketing gives +147398 because then all discount factors are
numerically zero).

So my question is if the problem disappears if you replace line 968 in
cashflows.cpp from

        return solver.solve(objFunction, accuracy, guess, guess/10.0);

to (for example)

        return solver.solve(objFunction, accuracy, guess, -10.0 , 10.0);

This is not meant as a solution, only to understand your problem
better before suggesting anything.

Best regards
Peter


On 1 October 2014 16:26, ltorjul <[hidden email]> wrote:

> Hi,
>
> I have a problem it seems that BondFunctions::Yield(...) is failing when the
> yield should be -54.4% or less (more negative). The yield function throws
> the exception: "unable to bracket root in 100 function evaluations(last
> bracket attempt: f[-2.29538e+025,5.968e+025] -> [-1.#END, 51.1682])".
>
> I have adjusted the price gradually and it seams that the most negative
> resulting yield I can compute without getting this error is -54,40688%.
>
> I have tested this with various types of bonds, both fixed rate and floating
> rate. And look to be that the error occurs at a prices that gives yields
> exactly this yield or less (more negative).
>
> Now, it may seem like a minor problem, when will prices be high enough to
> give such a negative yield?
>
> 1. What causes this error, and why at this point, logically yield should be
> able to anywhere from -100% to infinite positive)?
>
> 2. My scenario is that I want to compute duration and convexity for floating
> rate bonds. The street convention is to compute these with yield to next
> coupon date. Since I have not found any way to calculate yield to other
> dates than maturity, I fix this by creating a second floating rate bonds
> object with maturity equal to next coupon date for the first. Then using
> this to calculate yield to next coupon. In this situation the yield is often
> quite a bit negative, so this problem do occur quite often.
>
> Could somebody please look into this?
> Perhaps I can omit the entire problem by calculating yield to next coupon
> differently, but I cannot see how.
>
> Thanks in advance.
>
> Regards Lauritz
>
>
>
>
>
>
>
> --
> View this message in context: http://quantlib.10058.n7.nabble.com/yield-calculation-failing-when-resulting-yield-should-be-less-than-54-4-tp15932.html
> Sent from the quantlib-dev mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Slashdot TV.  Videos for Nerds.  Stuff that Matters.
> http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev

------------------------------------------------------------------------------
Slashdot TV.  Videos for Nerds.  Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: yield calculation failing when resulting yield should be less than -54.4%

ltorjul
Hi,

Thanks for your answer!

I tested your suggestion and changed line 968 in the cashflows.cpp file to:
return solver.solve(objFunction, accuracy, guess, -10.0 , 10.0);

This causes the error:
root not bracketed: f[-10,10] -> [-1.#IND00e+000,5.999990e+004]

I guess the reason is that a root of -10 cannot exist. If you look at the question from a financial perspective, you can off course loose you entire investment (Which would give a yield of -100%), but you could never get in the situation where you owe money (i.e. yield cannot be < -100%). Not sure if this makes any sense to you.

Anyway I tested with:
return solver.solve(objFunction, accuracy, guess, -1.0 , 10.0);
and this seems to work. I'm able to calculate yield in those extreme cases where yield is less than -54.4%.

I have also tested the unmodified yield function with a difference initial guess, e.g.
yield(frb, cleanPrice, dayCounter, QuantLib::Compounded, coupCompfrequency, settlementDate, 1e-8, 100, -0.80)

and it seems that using an initial guess of -.8 (-80%) "moves" the limit where the problem occures to about -91%. This however this causes the solver to work about 15% slower :-(

Anyway I like the solution where you sets the upper and lower limits better.

I'm good with this solution. But if you have other ideas or remarks I would be very grateful.

Regards Laurtiz
Reply | Threaded
Open this post in threaded view
|

Re: yield calculation failing when resulting yield should be less than -54.4%

Peter Caspers-4
Hi,
this was only for diagnostic purposes, not a final solution we should
put in the code. I'd have to check your specific case, but in general
I would think that a yield could be in the range from -inf to +inf: If
you have -1 today (pay 1 unit) and receive a > 0 at t=1, the
continuous yield would be -ln(1/a) which goes to -inf if a goes to
zero and to +inf if a goes to +inf. No ?
best regards
Peter


On 8 October 2014 17:41, ltorjul <[hidden email]> wrote:

> Hi,
>
> Thanks for your answer!
>
> I tested your suggestion and changed line 968 in the cashflows.cpp file to:
> return solver.solve(objFunction, accuracy, guess, -10.0 , 10.0);
>
> This causes the error:
> root not bracketed: f[-10,10] -> [-1.#IND00e+000,5.999990e+004]
>
> I guess the reason is that a root of -10 cannot exist. If you look at the
> question from a financial perspective, you can off course loose you entire
> investment (Which would give a yield of -100%), but you could never get in
> the situation where you owe money (i.e. yield cannot be < -100%). Not sure
> if this makes any sense to you.
>
> Anyway I tested with:
> return solver.solve(objFunction, accuracy, guess, -1.0 , 10.0);
> and this seems to work. I'm able to calculate yield in those extreme cases
> where yield is less than -54.4%.
>
> I have also tested the unmodified yield function with a difference initial
> guess, e.g.
> yield(frb, cleanPrice, dayCounter, QuantLib::Compounded, coupCompfrequency,
> settlementDate, 1e-8, 100, *-0.80*)
>
> and it seems that using an initial guess of -.8 (-80%) "moves" the limit
> where the problem occures to about -91%. This however this causes the solver
> to work about 15% slower :-(
>
> Anyway I like the solution where you sets the upper and lower limits better.
>
> I'm good with this solution. But if you have other ideas or remarks I would
> be very grateful.
>
> Regards Laurtiz
>
>
>
>
> --
> View this message in context: http://quantlib.10058.n7.nabble.com/yield-calculation-failing-when-resulting-yield-should-be-less-than-54-4-tp15932p15952.html
> Sent from the quantlib-dev mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://p.sf.net/sfu/Zoho
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: yield calculation failing when resulting yield should be less than -54.4%

Peter Caspers-4
... and a yearly compounded yield y is between -1 and +inf since these
two are linked by c = ln ( 1 + y ), so you have to adjust the lower
bound in this case, yes.
Peter

On 10 October 2014 21:31, Peter Caspers <[hidden email]> wrote:

> Hi,
> this was only for diagnostic purposes, not a final solution we should
> put in the code. I'd have to check your specific case, but in general
> I would think that a yield could be in the range from -inf to +inf: If
> you have -1 today (pay 1 unit) and receive a > 0 at t=1, the
> continuous yield would be -ln(1/a) which goes to -inf if a goes to
> zero and to +inf if a goes to +inf. No ?
> best regards
> Peter
>
>
> On 8 October 2014 17:41, ltorjul <[hidden email]> wrote:
>> Hi,
>>
>> Thanks for your answer!
>>
>> I tested your suggestion and changed line 968 in the cashflows.cpp file to:
>> return solver.solve(objFunction, accuracy, guess, -10.0 , 10.0);
>>
>> This causes the error:
>> root not bracketed: f[-10,10] -> [-1.#IND00e+000,5.999990e+004]
>>
>> I guess the reason is that a root of -10 cannot exist. If you look at the
>> question from a financial perspective, you can off course loose you entire
>> investment (Which would give a yield of -100%), but you could never get in
>> the situation where you owe money (i.e. yield cannot be < -100%). Not sure
>> if this makes any sense to you.
>>
>> Anyway I tested with:
>> return solver.solve(objFunction, accuracy, guess, -1.0 , 10.0);
>> and this seems to work. I'm able to calculate yield in those extreme cases
>> where yield is less than -54.4%.
>>
>> I have also tested the unmodified yield function with a difference initial
>> guess, e.g.
>> yield(frb, cleanPrice, dayCounter, QuantLib::Compounded, coupCompfrequency,
>> settlementDate, 1e-8, 100, *-0.80*)
>>
>> and it seems that using an initial guess of -.8 (-80%) "moves" the limit
>> where the problem occures to about -91%. This however this causes the solver
>> to work about 15% slower :-(
>>
>> Anyway I like the solution where you sets the upper and lower limits better.
>>
>> I'm good with this solution. But if you have other ideas or remarks I would
>> be very grateful.
>>
>> Regards Laurtiz
>>
>>
>>
>>
>> --
>> View this message in context: http://quantlib.10058.n7.nabble.com/yield-calculation-failing-when-resulting-yield-should-be-less-than-54-4-tp15932p15952.html
>> Sent from the quantlib-dev mailing list archive at Nabble.com.
>>
>> ------------------------------------------------------------------------------
>> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
>> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
>> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
>> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
>> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
>> _______________________________________________
>> QuantLib-dev mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/quantlib-dev

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://p.sf.net/sfu/Zoho
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: yield calculation failing when resulting yield should be less than -54.4%

ltorjul
In reply to this post by Peter Caspers-4
Hi Peter,

That fact that this was only for diagnostics was indeed my understanding as well.
If you are able to find the reason why the automatic bracketing do not work, it would be great.

I can provide you with code if you like.

Regards Lauritz