Fixed bond - Empty Handle cannot be dereferenced

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

Fixed bond - Empty Handle cannot be dereferenced

gbogaert

Hello Everyone,

 

I am trying to calculate the NPV of a straight bond. I instantiated the yield curve and I relinked it to discountingTermStructure. But when I call fixedRateBond.NPV(), I got this message “empty Handle cannot be dereferenced”. Here is the code:

 

boost::shared_ptr<YieldTermStructure> depoSwapTermStructure(

                                                                new PiecewiseYieldCurve<Discount,LogLinear>(

                                                                                                settlementDate, depoSwapInstruments,

                                                                                                termStructureDayCounter,

                                                                                                std::vector<Handle<Quote> >(),

                                                                                                std::vector<Date>(),

                                                                                                tolerance));

RelinkableHandle<YieldTermStructure> discountingTermStructure;

boost::shared_ptr<PricingEngine> bondEngine(

                                                                new DiscountingBondEngine(discountingTermStructure));

fixedRateBond.setPricingEngine(bondEngine);

std::cout << fixedRateBond.NPV() << std::endl;

 

Someone would be so kind to give me some hints?

 

Thank you in advance for your help.

 

Gilles

The information in this e-mail is confidential and may be legally privileged. It is intended
solely for the addressee. Access to this e-mail by anyone else is unauthorized. If you have 
received this communication in error, please address with the subject heading "Received in 
error," send back to the sender, then delete the e-mail and destroy any copies of it. If you 
are not the intended recipient, any disclosure, copying, distribution or any action taken or 
omitted to be taken in reliance on it, is prohibited and may be unlawful. Any opinions or 
advice contained in this e-mail are subject to the terms and conditions expressed in the 
governing KPMG client engagement letter. Opinions, conclusions and other information in this 
e-mail and any attachments that do not relate to the official business of the firm are 
neither given nor endorsed by it. KPMG cannot guarantee that e-mail communications are secure 
or error-free, as information could be intercepted, corrupted, amended, lost, destroyed, 
arrive late or incomplete, or contain viruses.
 
KPMG is the Luxembourg member firm of KPMG international. KPMG International is a Swiss 
cooperative that serves as a coordinating entity for a network of independent firms operating 
under the KPMG name. KPMG International provides no services to clients. Each member firm of 
KPMG International is a legally distinct and separate entity and each describes itself as 
such. Information about the structure and jurisdiction of your local KPMG member firm can be 
obtained from your KPMG representative.

This footnote also confirms that this e-mail message has been swept by AntiVirus software for 
the presence of computer viruses. However, the ultimate responsibility for virus checking 
lies with the recipient of this e-mail.


------------------------------------------------------------------------------

_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Fixed bond - Empty Handle cannot be dereferenced

Luigi Ballabio
On Mon, 2009-07-06 at 12:22 +0200, Bogaert, Gilles wrote:

> I am trying to calculate the NPV of a straight bond. I instantiated
> the yield curve and I relinked it to discountingTermStructure. But
> when I call fixedRateBond.NPV(), I got this message “empty Handle
> cannot be dereferenced”. Here is the code:
>
>  
>
> boost::shared_ptr<YieldTermStructure> depoSwapTermStructure(
>
>                                                                 new
> PiecewiseYieldCurve<Discount,LogLinear>(
>
>
> settlementDate, depoSwapInstruments,
>
>
> termStructureDayCounter,
>
>
> std::vector<Handle<Quote> >(),
>
>
> std::vector<Date>(),
>
>
> tolerance));
>
> RelinkableHandle<YieldTermStructure> discountingTermStructure;
>
> boost::shared_ptr<PricingEngine> bondEngine(
>
>                                                                 new
> DiscountingBondEngine(discountingTermStructure));
>
> fixedRateBond.setPricingEngine(bondEngine);
>
> std::cout << fixedRateBond.NPV() << std::endl;

You're not linking the depo-swap curve to the handle in the above code.

Luigi


--

The nice thing about standards is that there are so many of them to
choose from.
-- Andrew S. Tanenbaum



------------------------------------------------------------------------------
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Spread Curve

gbogaert
Dear All,

I got a question concerning the spread curve. I built at first a zero
curve. Then I wanted to add a spread to this curve. My aim was to add a
flat spread curve to pull up the previous zero curve. To do so, I built
a spread vector with a value of 0.01684 and a date vector with the same
dates than my bond schedule.
I checked the rates [depoSwapTermStructureSpreaded->zeroRate(sch.at(i))]
for the same dates than the schedule dates. I compared these spreads to
the risk free curve and I deducted a spread of 0.0175-0.0176. Should I
not receive a spread of 0.01684? What did I do wrong?

Thank you in advance for your help.

Best regards,

Gilles

----------
Here it is the code:
        Rate MySpreadQuote = 0.01684;
        boost::shared_ptr<Quote> MySpreadRate (new SimpleQuote
(MySpreadQuote));

        boost::shared_ptr<YieldTermStructure> depoSwapTermStructure(
                        new PiecewiseYieldCurve<Discount,LogLinear>(
                                        settlementDate,
depoSwapInstruments,
                                        termStructureDayCounter,
                                        std::vector<Handle<Quote> >(),
                                        std::vector<Date>(),
                                        tolerance));

        RelinkableHandle<YieldTermStructure> discountingTermStructure;
        discountingTermStructure.linkTo(depoSwapTermStructure);
        RelinkableHandle<YieldTermStructure> MyHandle;
        MyHandle.linkTo(depoSwapTermStructure);

        std::vector<Handle<Quote> > MySpreadRateVector(sch.size());
        std::vector<Date> mydates(sch.size());

        /* (...) I fed my dates vector and spreads vector (...) */
        for (int i=0; i < sch.size(); i++)
        {
                MySpreadRateVector[i] = Handle<Quote>(MySpreadRate);
                mydates[i]=sch.at(i);
        }

        boost::shared_ptr<YieldTermStructure>
depoSwapTermStructureSpreaded(
                                                new
PiecewiseZeroSpreadedTermStructure(
       
MyHandle,MySpreadRateVector,mydates));
--------
The information in this e-mail is confidential and may be legally privileged. It is intended
solely for the addressee. Access to this e-mail by anyone else is unauthorized. If you have
received this communication in error, please address with the subject heading "Received in
error," send back to the sender, then delete the e-mail and destroy any copies of it. If you
are not the intended recipient, any disclosure, copying, distribution or any action taken or
omitted to be taken in reliance on it, is prohibited and may be unlawful. Any opinions or
advice contained in this e-mail are subject to the terms and conditions expressed in the
governing KPMG client engagement letter. Opinions, conclusions and other information in this
e-mail and any attachments that do not relate to the official business of the firm are
neither given nor endorsed by it. KPMG cannot guarantee that e-mail communications are secure
or error-free, as information could be intercepted, corrupted, amended, lost, destroyed,
arrive late or incomplete, or contain viruses.
 
KPMG is the Luxembourg member firm of KPMG international. KPMG International is a Swiss
cooperative that serves as a coordinating entity for a network of independent firms operating
under the KPMG name. KPMG International provides no services to clients. Each member firm of
KPMG International is a legally distinct and separate entity and each describes itself as
such. Information about the structure and jurisdiction of your local KPMG member firm can be
obtained from your KPMG representative.

This footnote also confirms that this e-mail message has been swept by AntiVirus software for
the presence of computer viruses. However, the ultimate responsibility for virus checking
lies with the recipient of this e-mail.


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/blackberry
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Spread Curve

Khanh Nguyen
I am not sure whether this could help you, but you can check this out.

http://quantlib.org/reference/class_quant_lib_1_1_forward_spreaded_term_structure.html

-k

On Tue, Jul 7, 2009 at 8:39 AM, Bogaert, Gilles<[hidden email]> wrote:

> Dear All,
>
> I got a question concerning the spread curve. I built at first a zero
> curve. Then I wanted to add a spread to this curve. My aim was to add a
> flat spread curve to pull up the previous zero curve. To do so, I built
> a spread vector with a value of 0.01684 and a date vector with the same
> dates than my bond schedule.
> I checked the rates [depoSwapTermStructureSpreaded->zeroRate(sch.at(i))]
> for the same dates than the schedule dates. I compared these spreads to
> the risk free curve and I deducted a spread of 0.0175-0.0176. Should I
> not receive a spread of 0.01684? What did I do wrong?
>
> Thank you in advance for your help.
>
> Best regards,
>
> Gilles
>
> ----------
> Here it is the code:
>        Rate MySpreadQuote = 0.01684;
>        boost::shared_ptr<Quote> MySpreadRate (new SimpleQuote
> (MySpreadQuote));
>
>        boost::shared_ptr<YieldTermStructure> depoSwapTermStructure(
>                        new PiecewiseYieldCurve<Discount,LogLinear>(
>                                        settlementDate,
> depoSwapInstruments,
>                                        termStructureDayCounter,
>                                        std::vector<Handle<Quote> >(),
>                                        std::vector<Date>(),
>                                        tolerance));
>
>        RelinkableHandle<YieldTermStructure> discountingTermStructure;
>        discountingTermStructure.linkTo(depoSwapTermStructure);
>        RelinkableHandle<YieldTermStructure> MyHandle;
>        MyHandle.linkTo(depoSwapTermStructure);
>
>        std::vector<Handle<Quote> > MySpreadRateVector(sch.size());
>        std::vector<Date> mydates(sch.size());
>
>        /* (...) I fed my dates vector and spreads vector (...) */
>        for (int i=0; i < sch.size(); i++)
>        {
>                MySpreadRateVector[i] = Handle<Quote>(MySpreadRate);
>                mydates[i]=sch.at(i);
>        }
>
>        boost::shared_ptr<YieldTermStructure>
> depoSwapTermStructureSpreaded(
>                                                new
> PiecewiseZeroSpreadedTermStructure(
>
> MyHandle,MySpreadRateVector,mydates));
> --------
> The information in this e-mail is confidential and may be legally privileged. It is intended
> solely for the addressee. Access to this e-mail by anyone else is unauthorized. If you have
> received this communication in error, please address with the subject heading "Received in
> error," send back to the sender, then delete the e-mail and destroy any copies of it. If you
> are not the intended recipient, any disclosure, copying, distribution or any action taken or
> omitted to be taken in reliance on it, is prohibited and may be unlawful. Any opinions or
> advice contained in this e-mail are subject to the terms and conditions expressed in the
> governing KPMG client engagement letter. Opinions, conclusions and other information in this
> e-mail and any attachments that do not relate to the official business of the firm are
> neither given nor endorsed by it. KPMG cannot guarantee that e-mail communications are secure
> or error-free, as information could be intercepted, corrupted, amended, lost, destroyed,
> arrive late or incomplete, or contain viruses.
>
> KPMG is the Luxembourg member firm of KPMG international. KPMG International is a Swiss
> cooperative that serves as a coordinating entity for a network of independent firms operating
> under the KPMG name. KPMG International provides no services to clients. Each member firm of
> KPMG International is a legally distinct and separate entity and each describes itself as
> such. Information about the structure and jurisdiction of your local KPMG member firm can be
> obtained from your KPMG representative.
>
> This footnote also confirms that this e-mail message has been swept by AntiVirus software for
> the presence of computer viruses. However, the ultimate responsibility for virus checking
> lies with the recipient of this e-mail.
>
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at: http://p.sf.net/sfu/blackberry
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time,
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize
details at: http://p.sf.net/sfu/blackberry
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Spread Curve

Luigi Ballabio
In reply to this post by gbogaert
On Tue, 2009-07-07 at 14:39 +0200, Bogaert, Gilles wrote:
> I got a question concerning the spread curve. I built at first a zero
> curve. Then I wanted to add a spread to this curve. My aim was to add a
> flat spread curve to pull up the previous zero curve. To do so, I built
> a spread vector with a value of 0.01684 and a date vector with the same
> dates than my bond schedule.

You might try adding the settlement date as the first date in the vector
and removing earlier dates.  I don't remember how the piecewise-spreaded
curve works exactly, but if your first date is before the settlement, it
might start integrating there and get an additional spread.

Luigi


--

There is no such thing as public opinion. There is only published
opinion.
-- Winston Churchill



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Spread Curve

gbogaert
Thanks Luigi for your help. I will check as soon as possible.

Regards,

Gilles

-----Original Message-----
From: Luigi Ballabio [mailto:[hidden email]]
Sent: mardi, 28 juillet 2009 10:13
To: Bogaert, Gilles
Cc: [hidden email]
Subject: Re: [Quantlib-users] Spread Curve

On Tue, 2009-07-07 at 14:39 +0200, Bogaert, Gilles wrote:
> I got a question concerning the spread curve. I built at first a zero
> curve. Then I wanted to add a spread to this curve. My aim was to add
a
> flat spread curve to pull up the previous zero curve. To do so, I
built
> a spread vector with a value of 0.01684 and a date vector with the
same
> dates than my bond schedule.

You might try adding the settlement date as the first date in the vector
and removing earlier dates.  I don't remember how the piecewise-spreaded
curve works exactly, but if your first date is before the settlement, it
might start integrating there and get an additional spread.

Luigi


--

There is no such thing as public opinion. There is only published
opinion.
-- Winston Churchill


The information in this e-mail is confidential and may be legally privileged. It is intended
solely for the addressee. Access to this e-mail by anyone else is unauthorized. If you have
received this communication in error, please address with the subject heading "Received in
error," send back to the sender, then delete the e-mail and destroy any copies of it. If you
are not the intended recipient, any disclosure, copying, distribution or any action taken or
omitted to be taken in reliance on it, is prohibited and may be unlawful. Any opinions or
advice contained in this e-mail are subject to the terms and conditions expressed in the
governing KPMG client engagement letter. Opinions, conclusions and other information in this
e-mail and any attachments that do not relate to the official business of the firm are
neither given nor endorsed by it. KPMG cannot guarantee that e-mail communications are secure
or error-free, as information could be intercepted, corrupted, amended, lost, destroyed,
arrive late or incomplete, or contain viruses.
 
KPMG is the Luxembourg member firm of KPMG international. KPMG International is a Swiss
cooperative that serves as a coordinating entity for a network of independent firms operating
under the KPMG name. KPMG International provides no services to clients. Each member firm of
KPMG International is a legally distinct and separate entity and each describes itself as
such. Information about the structure and jurisdiction of your local KPMG member firm can be
obtained from your KPMG representative.

This footnote also confirms that this e-mail message has been swept by AntiVirus software for
the presence of computer viruses. However, the ultimate responsibility for virus checking
lies with the recipient of this e-mail.


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users