Exception in Bond::cleanPriceFromZSpread(...)

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

Exception in Bond::cleanPriceFromZSpread(...)

Luca Billi
Hi all,
the following code throws an exception when
bond.cleanPriceFromZSpread(...) is called.
The issue comes from the fact that, in this example, there's no
settlement adjustment, so the function
ZeroSpreadedTermStructure::zeroYieldImpl(Time t) needs to be evaluated
for t=0.

I got around this issue by adding the seemingly harmless

if(t==0.) return 1.;

at line 86 of file ql/termstructures/yield/zeroyieldstructure.hpp

Anyone has a better idea?

Luca


#include <ql/quantlib.hpp>
using namespace QuantLib;

int main(int, char* [])
{
  try {
    Calendar calendar = TARGET();
    Date todaysDate(30, Jun, 2008);
    Settings::instance().evaluationDate() = todaysDate;

    Schedule schedule = MakeSchedule(todaysDate, todaysDate + 10*Years,

Period(Annual), calendar, Unadjusted);
    std::vector<double> coupons(1, 0.07);

    FixedRateBond bond(0, 10000., schedule, coupons, Actual360(),
ModifiedFollowing);

    Handle<YieldTermStructure> tsCurve(boost::shared_ptr<FlatForward>(
                      new FlatForward(todaysDate, 0.05, Actual360(),
Compounded)));

    boost::shared_ptr<DiscountingBondEngine> engine(new
DiscountingBondEngine(tsCurve));
    bond.setPricingEngine(engine);

    bond.cleanPriceFromZSpread(0.0200, Actual360(), Compounded,
Annual);    // <- this throws
  }

  catch (std::exception& e) {
      std::cout << e.what() << std::endl;
  }
  return 1;
}

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Exception in Bond::cleanPriceFromZSpread(...)

Luigi Ballabio
On Tue, 2008-07-15 at 12:21 -0400, Luca Billi wrote:

> the following code throws an exception when
> bond.cleanPriceFromZSpread(...) is called.
> The issue comes from the fact that, in this example, there's no
> settlement adjustment, so the function
> ZeroSpreadedTermStructure::zeroYieldImpl(Time t) needs to be evaluated
> for t=0.
>
> I got around this issue by adding the seemingly harmless
>
> if(t==0.) return 1.;
>
> at line 86 of file ql/termstructures/yield/zeroyieldstructure.hpp
>
> Anyone has a better idea?

I'd rather fix ZeroSpreadedTermStructure::zeroYieldImpl so that it works
at t=0. Did you happen to investigate what goes wrong inside there?

Later,
        Luigi


--

Just remember what ol' Jack Burton does when the earth quakes, the
poison arrows fall from the sky, and the pillars of Heaven shake. Yeah,
Jack Burton just looks that big old storm right in the eye and says,
"Give me your best shot. I can take it."
-- Jack Burton, "Big trouble in Little China"



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Exception in Bond::cleanPriceFromZSpread(...)

Luca Billi
On Wed, Jul 16, 2008 at 11:01 AM, Luigi Ballabio
<[hidden email]> wrote:

> On Tue, 2008-07-15 at 12:21 -0400, Luca Billi wrote:
>> the following code throws an exception when
>> bond.cleanPriceFromZSpread(...) is called.
>> The issue comes from the fact that, in this example, there's no
>> settlement adjustment, so the function
>> ZeroSpreadedTermStructure::zeroYieldImpl(Time t) needs to be evaluated
>> for t=0.
>>
>> I got around this issue by adding the seemingly harmless
>>
>> if(t==0.) return 1.;
>>
>> at line 86 of file ql/termstructures/yield/zeroyieldstructure.hpp
>>
>> Anyone has a better idea?
>
> I'd rather fix ZeroSpreadedTermStructure::zeroYieldImpl so that it works
> at t=0. Did you happen to investigate what goes wrong inside there?
>
> Later,
>        Luigi
>
>

The exception is thrown by InterestRate::equivalentRate(), which, I
think, is called to convert the yield+spread to continuous
compounding.

I think the exception is legitimate: interest rates on zero intervals
are meaningless, whereas discount factors are not:

exp(-r*t) = 1 for t=0, regardless of r.

That's why I think that, when t=0, it's ok to avoid calling
ZeroSpreadedTermStructure::zeroYieldImpl(), which operates in the
yield space and is not required when t=0, and return immediatly 1.

Luca

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Exception in Bond::cleanPriceFromZSpread(...)

Luigi Ballabio
On Wed, 2008-07-16 at 12:08 -0400, Luca Billi wrote:
> I think the exception is legitimate: interest rates on zero intervals
> are meaningless, whereas discount factors are not:
>
> exp(-r*t) = 1 for t=0, regardless of r.
>
> That's why I think that, when t=0, it's ok to avoid calling
> ZeroSpreadedTermStructure::zeroYieldImpl(), which operates in the
> yield space and is not required when t=0, and return immediatly 1.

Ok, I've put the t=0 check in.  I'd still like to have zeroYieldImpl()
succeed at t=0 (the rate can be defined as the limit for t->0, after
all) but that's for another day...

Thanks for the heads-up,
        Luigi


--

I have yet to see any problem, however complicated, which, when you
looked at it in the right way, did not become still more complicated.
-- Poul Anderson



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev