Bond Credit Spread Calibration

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

Bond Credit Spread Calibration

John Orford
Hey Guys,

Long time no questions - looking forward to getting back into QL again! Spending too much time ensconced in Javascript.

In any case, I can't figure out what I am doing wrong.

I create a FixedRateBond object with all the requisite accoutrements.

Then call a zSpread function reusing everything from the FixedRateBond object.

For the NPV which'll be calibrated to, I take a quoted clean market price and add the accrued amount from the bond object.

For example, MV = 135, Accrued Amt = 9.99, and NPV ~= 145.

However, when I take the output of the zSpread function and create a new object, the NPV turns out to be ~144.

I tried increasing accuracy and iterations but to no avail.

Are there any common gotchas while using the zSpread function?

As I write this I realise, a code example would be very helpful. I will do that now.

John

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Bond Credit Spread Calibration

John Orford
I attached an example.

Suspect this isn't a stupid mistake, but a fundamental misunderstanding of mine, which is a little worrying.

Any help'll be appreciated.

John

On Fri Feb 06 2015 at 1:06:50 PM John Orford <[hidden email]> wrote:
Hey Guys,

Long time no questions - looking forward to getting back into QL again! Spending too much time ensconced in Javascript.

In any case, I can't figure out what I am doing wrong.

I create a FixedRateBond object with all the requisite accoutrements.

Then call a zSpread function reusing everything from the FixedRateBond object.

For the NPV which'll be calibrated to, I take a quoted clean market price and add the accrued amount from the bond object.

For example, MV = 135, Accrued Amt = 9.99, and NPV ~= 145.

However, when I take the output of the zSpread function and create a new object, the NPV turns out to be ~144.

I tried increasing accuracy and iterations but to no avail.

Are there any common gotchas while using the zSpread function?

As I write this I realise, a code example would be very helpful. I will do that now.

John

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

blog_bond_example_with_calibration_1.py (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Bond Credit Spread Calibration

John Orford
Previous file was wrong - this is the one to look at.

On Fri Feb 06 2015 at 6:23:46 PM John Orford <[hidden email]> wrote:
I attached an example.

Suspect this isn't a stupid mistake, but a fundamental misunderstanding of mine, which is a little worrying.

Any help'll be appreciated.

John


On Fri Feb 06 2015 at 1:06:50 PM John Orford <[hidden email]> wrote:
Hey Guys,

Long time no questions - looking forward to getting back into QL again! Spending too much time ensconced in Javascript.

In any case, I can't figure out what I am doing wrong.

I create a FixedRateBond object with all the requisite accoutrements.

Then call a zSpread function reusing everything from the FixedRateBond object.

For the NPV which'll be calibrated to, I take a quoted clean market price and add the accrued amount from the bond object.

For example, MV = 135, Accrued Amt = 9.99, and NPV ~= 145.

However, when I take the output of the zSpread function and create a new object, the NPV turns out to be ~144.

I tried increasing accuracy and iterations but to no avail.

Are there any common gotchas while using the zSpread function?

As I write this I realise, a code example would be very helpful. I will do that now.

John

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

blog_bond_example_with_calibration_1.py (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

答复: Bond Credit Spread Calibration

cheng li

Hi John,

 

Thank you for sharing your codes. There are some changes needed to be made to your codes to make the example work properly:

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ))

 

Should be amended as :

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ), compounding,  payment_frequency)

 

Z-Spread has its own compounding rule and frequency. And you should make it consistent with what you offer to the function when you call CashFlows.zSpread.

 

Line 153: print "NPV+AA\t" + str(fixed_rate_bond.NPV() + fixed_rate_bond.accruedAmount())

 

Should be:

 

Line 153: print "NPV-AA\t" + str(fixed_rate_bond.NPV() - fixed_rate_bond.accruedAmount())

 

Normally NPV of bond is it dirty price. So AA should be excluded to be compared with MV which supposed to be clean price.

 

Regards,

Cheng

 

发件人: John Orford [mailto:[hidden email]]
发送时间: 201526 18:34
收件人: QuantLib users
主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Previous file was wrong - this is the one to look at.

On Fri Feb 06 2015 at 6:23:46 PM John Orford <[hidden email]> wrote:

I attached an example.

 

Suspect this isn't a stupid mistake, but a fundamental misunderstanding of mine, which is a little worrying.

 

Any help'll be appreciated.

 

John

 

On Fri Feb 06 2015 at 1:06:50 PM John Orford <[hidden email]> wrote:

Hey Guys,

 

Long time no questions - looking forward to getting back into QL again! Spending too much time ensconced in Javascript.

 

In any case, I can't figure out what I am doing wrong.

 

I create a FixedRateBond object with all the requisite accoutrements.

 

Then call a zSpread function reusing everything from the FixedRateBond object.

 

For the NPV which'll be calibrated to, I take a quoted clean market price and add the accrued amount from the bond object.

 

For example, MV = 135, Accrued Amt = 9.99, and NPV ~= 145.

 

However, when I take the output of the zSpread function and create a new object, the NPV turns out to be ~144.

 

I tried increasing accuracy and iterations but to no avail.

 

Are there any common gotchas while using the zSpread function?

 

As I write this I realise, a code example would be very helpful. I will do that now.

 

John


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Bond Credit Spread Calibration

John Orford
Thanks Cheng! I'll check your amendments now and let you know : )

On Mon Feb 09 2015 at 9:58:35 AM cheng li <[hidden email]> wrote:

Hi John,

 

Thank you for sharing your codes. There are some changes needed to be made to your codes to make the example work properly:

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ))

 

Should be amended as :

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ), compounding,  payment_frequency)

 

Z-Spread has its own compounding rule and frequency. And you should make it consistent with what you offer to the function when you call CashFlows.zSpread.

 

Line 153: print "NPV+AA\t" + str(fixed_rate_bond.NPV() + fixed_rate_bond.accruedAmount())

 

Should be:

 

Line 153: print "NPV-AA\t" + str(fixed_rate_bond.NPV() - fixed_rate_bond.accruedAmount())

 

Normally NPV of bond is it dirty price. So AA should be excluded to be compared with MV which supposed to be clean price.

 

Regards,

Cheng

 

发件人: John Orford [mailto:[hidden email]]
发送时间: 201526 18:34
收件人: QuantLib users
主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Previous file was wrong - this is the one to look at.

On Fri Feb 06 2015 at 6:23:46 PM John Orford <[hidden email]> wrote:

I attached an example.

 

Suspect this isn't a stupid mistake, but a fundamental misunderstanding of mine, which is a little worrying.

 

Any help'll be appreciated.

 

John

 

On Fri Feb 06 2015 at 1:06:50 PM John Orford <[hidden email]> wrote:

Hey Guys,

 

Long time no questions - looking forward to getting back into QL again! Spending too much time ensconced in Javascript.

 

In any case, I can't figure out what I am doing wrong.

 

I create a FixedRateBond object with all the requisite accoutrements.

 

Then call a zSpread function reusing everything from the FixedRateBond object.

 

For the NPV which'll be calibrated to, I take a quoted clean market price and add the accrued amount from the bond object.

 

For example, MV = 135, Accrued Amt = 9.99, and NPV ~= 145.

 

However, when I take the output of the zSpread function and create a new object, the NPV turns out to be ~144.

 

I tried increasing accuracy and iterations but to no avail.

 

Are there any common gotchas while using the zSpread function?

 

As I write this I realise, a code example would be very helpful. I will do that now.

 

John


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Bond Credit Spread Calibration

John Orford
Cheng,

it looks like you hit the nail on the head - adding payment frequency and compounding to the ZeroSpreadedTermStructure constructor function looks like it will solve my problem.

Only issue is that my version of Quanlib Python bindings only allow 2 inputs into that function, not 4.

Could you let me know which version of the bindings you are using? Maybe it's customised?

Thanks,

John



On Mon Feb 09 2015 at 10:01:27 John Orford <[hidden email]> wrote:
Thanks Cheng! I'll check your amendments now and let you know : )

On Mon Feb 09 2015 at 9:58:35 AM cheng li <[hidden email]> wrote:

Hi John,

 

Thank you for sharing your codes. There are some changes needed to be made to your codes to make the example work properly:

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ))

 

Should be amended as :

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ), compounding,  payment_frequency)

 

Z-Spread has its own compounding rule and frequency. And you should make it consistent with what you offer to the function when you call CashFlows.zSpread.

 

Line 153: print "NPV+AA\t" + str(fixed_rate_bond.NPV() + fixed_rate_bond.accruedAmount())

 

Should be:

 

Line 153: print "NPV-AA\t" + str(fixed_rate_bond.NPV() - fixed_rate_bond.accruedAmount())

 

Normally NPV of bond is it dirty price. So AA should be excluded to be compared with MV which supposed to be clean price.

 

Regards,

Cheng

 

发件人: John Orford [mailto:[hidden email]]
发送时间: 201526 18:34
收件人: QuantLib users
主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Previous file was wrong - this is the one to look at.

On Fri Feb 06 2015 at 6:23:46 PM John Orford <[hidden email]> wrote:

I attached an example.

 

Suspect this isn't a stupid mistake, but a fundamental misunderstanding of mine, which is a little worrying.

 

Any help'll be appreciated.

 

John

 

On Fri Feb 06 2015 at 1:06:50 PM John Orford <[hidden email]> wrote:

Hey Guys,

 

Long time no questions - looking forward to getting back into QL again! Spending too much time ensconced in Javascript.

 

In any case, I can't figure out what I am doing wrong.

 

I create a FixedRateBond object with all the requisite accoutrements.

 

Then call a zSpread function reusing everything from the FixedRateBond object.

 

For the NPV which'll be calibrated to, I take a quoted clean market price and add the accrued amount from the bond object.

 

For example, MV = 135, Accrued Amt = 9.99, and NPV ~= 145.

 

However, when I take the output of the zSpread function and create a new object, the NPV turns out to be ~144.

 

I tried increasing accuracy and iterations but to no avail.

 

Are there any common gotchas while using the zSpread function?

 

As I write this I realise, a code example would be very helpful. I will do that now.

 

John


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

答复: Bond Credit Spread Calibration

cheng li

Hi John

 

Sorry, I checked  the master branch. The Python interface only expects 2 arguments….

 

I think I have changed the interface by myself to fit my purpose some time ago though  I cant’t remember when…

 

On your side, to have the same interface with mine. You have to generate Python bindings with swig by yourself.

 

1.       Change the corresponding .i file

 

You have to change from the line 108  in termstructures.i file:

 

%rename(ZeroSpreadedTermStructure) ZeroSpreadedTermStructurePtr;

class ZeroSpreadedTermStructurePtr

    : public boost::shared_ptr<YieldTermStructure> {

  public:

    %extend {

        ZeroSpreadedTermStructurePtr(

                                const Handle<YieldTermStructure>& curveHandle,

                                const Handle<Quote>& spreadHandle) {

            return new ZeroSpreadedTermStructurePtr(

                new ZeroSpreadedTermStructure(curveHandle,spreadHandle));

        }

    }

};

 

To:

 

%rename(ZeroSpreadedTermStructure) ZeroSpreadedTermStructurePtr;

class ZeroSpreadedTermStructurePtr

    : public boost::shared_ptr<YieldTermStructure> {

  public:

    %extend {

        ZeroSpreadedTermStructurePtr(

                                const Handle<YieldTermStructure>& curveHandle,

                                const Handle<Quote>& spreadHandle,

                               Compounding comp = QuantLib::Continuous,

                                Frequency freq = QuantLib::NoFrequency,

                                const DayCounter& dc = QuantLib::DayCounter()) {

            return new ZeroSpreadedTermStructurePtr(

                new ZeroSpreadedTermStructure(curveHandle,spreadHandle, comp, freq, dc));

        }

    }

};

 

2.       Re-generate swig python binding

 

Regards,

Cheng

 

 

发件人: John Orford [mailto:[hidden email]]
发送时间: 201529 14:45
收件人: cheng li; QuantLib users
主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Cheng,

 

it looks like you hit the nail on the head - adding payment frequency and compounding to the ZeroSpreadedTermStructure constructor function looks like it will solve my problem.

 

Only issue is that my version of Quanlib Python bindings only allow 2 inputs into that function, not 4.

 

Could you let me know which version of the bindings you are using? Maybe it's customised?

 

Thanks,

 

John

 

 

 

On Mon Feb 09 2015 at 10:01:27 John Orford <[hidden email]> wrote:

Thanks Cheng! I'll check your amendments now and let you know : )

 

On Mon Feb 09 2015 at 9:58:35 AM cheng li <[hidden email]> wrote:

Hi John,

 

Thank you for sharing your codes. There are some changes needed to be made to your codes to make the example work properly:

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ))

 

Should be amended as :

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ), compounding,  payment_frequency)

 

Z-Spread has its own compounding rule and frequency. And you should make it consistent with what you offer to the function when you call CashFlows.zSpread.

 

Line 153: print "NPV+AA\t" + str(fixed_rate_bond.NPV() + fixed_rate_bond.accruedAmount())

 

Should be:

 

Line 153: print "NPV-AA\t" + str(fixed_rate_bond.NPV() - fixed_rate_bond.accruedAmount())

 

Normally NPV of bond is it dirty price. So AA should be excluded to be compared with MV which supposed to be clean price.

 

Regards,

Cheng

 

发件人: John Orford [mailto:[hidden email]]
发送时间: 201526 18:34
收件人: QuantLib users
主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Previous file was wrong - this is the one to look at.

On Fri Feb 06 2015 at 6:23:46 PM John Orford <[hidden email]> wrote:

I attached an example.

 

Suspect this isn't a stupid mistake, but a fundamental misunderstanding of mine, which is a little worrying.

 

Any help'll be appreciated.

 

John

 

On Fri Feb 06 2015 at 1:06:50 PM John Orford <[hidden email]> wrote:

Hey Guys,

 

Long time no questions - looking forward to getting back into QL again! Spending too much time ensconced in Javascript.

 

In any case, I can't figure out what I am doing wrong.

 

I create a FixedRateBond object with all the requisite accoutrements.

 

Then call a zSpread function reusing everything from the FixedRateBond object.

 

For the NPV which'll be calibrated to, I take a quoted clean market price and add the accrued amount from the bond object.

 

For example, MV = 135, Accrued Amt = 9.99, and NPV ~= 145.

 

However, when I take the output of the zSpread function and create a new object, the NPV turns out to be ~144.

 

I tried increasing accuracy and iterations but to no avail.

 

Are there any common gotchas while using the zSpread function?

 

As I write this I realise, a code example would be very helpful. I will do that now.

 

John


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Bond Credit Spread Calibration

John Orford
Oh great - OK, I will do that and let you know how it goes, thanks!

On Mon Feb 09 2015 at 15:25:19 cheng li <[hidden email]> wrote:

Hi John

 

Sorry, I checked  the master branch. The Python interface only expects 2 arguments….

 

I think I have changed the interface by myself to fit my purpose some time ago though  I cant’t remember when…

 

On your side, to have the same interface with mine. You have to generate Python bindings with swig by yourself.

 

1.       Change the corresponding .i file

 

You have to change from the line 108  in termstructures.i file:

 

%rename(ZeroSpreadedTermStructure) ZeroSpreadedTermStructurePtr;

class ZeroSpreadedTermStructurePtr

    : public boost::shared_ptr<YieldTermStructure> {

  public:

    %extend {

        ZeroSpreadedTermStructurePtr(

                                const Handle<YieldTermStructure>& curveHandle,

                                const Handle<Quote>& spreadHandle) {

            return new ZeroSpreadedTermStructurePtr(

                new ZeroSpreadedTermStructure(curveHandle,spreadHandle));

        }

    }

};

 

To:

 

%rename(ZeroSpreadedTermStructure) ZeroSpreadedTermStructurePtr;

class ZeroSpreadedTermStructurePtr

    : public boost::shared_ptr<YieldTermStructure> {

  public:

    %extend {

        ZeroSpreadedTermStructurePtr(

                                const Handle<YieldTermStructure>& curveHandle,

                                const Handle<Quote>& spreadHandle,

                               Compounding comp = QuantLib::Continuous,

                                Frequency freq = QuantLib::NoFrequency,

                                const DayCounter& dc = QuantLib::DayCounter()) {

            return new ZeroSpreadedTermStructurePtr(

                new ZeroSpreadedTermStructure(curveHandle,spreadHandle, comp, freq, dc));

        }

    }

};

 

2.       Re-generate swig python binding

 

Regards,

Cheng

 

 

发件人: John Orford [mailto:[hidden email]]

发送时间: 201529 14:45
收件人: cheng li; QuantLib users

主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Cheng,

 

it looks like you hit the nail on the head - adding payment frequency and compounding to the ZeroSpreadedTermStructure constructor function looks like it will solve my problem.

 

Only issue is that my version of Quanlib Python bindings only allow 2 inputs into that function, not 4.

 

Could you let me know which version of the bindings you are using? Maybe it's customised?

 

Thanks,

 

John

 

 

 

On Mon Feb 09 2015 at 10:01:27 John Orford <[hidden email]> wrote:

Thanks Cheng! I'll check your amendments now and let you know : )

 

On Mon Feb 09 2015 at 9:58:35 AM cheng li <[hidden email]> wrote:

Hi John,

 

Thank you for sharing your codes. There are some changes needed to be made to your codes to make the example work properly:

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ))

 

Should be amended as :

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ), compounding,  payment_frequency)

 

Z-Spread has its own compounding rule and frequency. And you should make it consistent with what you offer to the function when you call CashFlows.zSpread.

 

Line 153: print "NPV+AA\t" + str(fixed_rate_bond.NPV() + fixed_rate_bond.accruedAmount())

 

Should be:

 

Line 153: print "NPV-AA\t" + str(fixed_rate_bond.NPV() - fixed_rate_bond.accruedAmount())

 

Normally NPV of bond is it dirty price. So AA should be excluded to be compared with MV which supposed to be clean price.

 

Regards,

Cheng

 

发件人: John Orford [mailto:[hidden email]]
发送时间: 201526 18:34
收件人: QuantLib users
主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Previous file was wrong - this is the one to look at.

On Fri Feb 06 2015 at 6:23:46 PM John Orford <[hidden email]> wrote:

I attached an example.

 

Suspect this isn't a stupid mistake, but a fundamental misunderstanding of mine, which is a little worrying.

 

Any help'll be appreciated.

 

John

 

On Fri Feb 06 2015 at 1:06:50 PM John Orford <[hidden email]> wrote:

Hey Guys,

 

Long time no questions - looking forward to getting back into QL again! Spending too much time ensconced in Javascript.

 

In any case, I can't figure out what I am doing wrong.

 

I create a FixedRateBond object with all the requisite accoutrements.

 

Then call a zSpread function reusing everything from the FixedRateBond object.

 

For the NPV which'll be calibrated to, I take a quoted clean market price and add the accrued amount from the bond object.

 

For example, MV = 135, Accrued Amt = 9.99, and NPV ~= 145.

 

However, when I take the output of the zSpread function and create a new object, the NPV turns out to be ~144.

 

I tried increasing accuracy and iterations but to no avail.

 

Are there any common gotchas while using the zSpread function?

 

As I write this I realise, a code example would be very helpful. I will do that now.

 

John


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Bond Credit Spread Calibration

Luigi Ballabio
Hi John,
    Cheng's right. I'd add a couple more things, though:

- if you want to quickly check consistency before regenerating the wrappers, you can go the other way around; keep the ZeroSpreadedTermStructure as it is, and use the Continuous compounding convention in the call to CashFlows.zSpread instead;

- regardless of the compounding convention, NPV() is probably not the right method to call. In a Bond, the NPV() method returns the value of the cash flows discounted to hte reference date of the discount curve, while in the market price they're discounted to the settlement date of the bond. On the one hand, you should pass the discount date to the zSpread call, as in:

    CashFlows.zSpread(fixed_rate_bond.cashflows(),                          
                      market_value + fixed_rate_bond.accruedAmount(),                   
                      bond_discounting_term_structure,
                      fixed_rate_bond.dayCounter(),                          
                      compounding,
                      fixed_rate_bond.frequency(),
                      False,                                                            
                      fixed_rate_bond.settlementDate())  # here

On the other hand, instead of NPV, you should call bond.cleanPrice() to get the estimated market value (or bond.dirtyPrice() to get the value plus the accrual).

Luigi



On Mon, Feb 9, 2015 at 8:37 AM, John Orford <[hidden email]> wrote:
Oh great - OK, I will do that and let you know how it goes, thanks!

On Mon Feb 09 2015 at 15:25:19 cheng li <[hidden email]> wrote:

Hi John

 

Sorry, I checked  the master branch. The Python interface only expects 2 arguments….

 

I think I have changed the interface by myself to fit my purpose some time ago though  I cant’t remember when…

 

On your side, to have the same interface with mine. You have to generate Python bindings with swig by yourself.

 

1.       Change the corresponding .i file

 

You have to change from the line 108  in termstructures.i file:

 

%rename(ZeroSpreadedTermStructure) ZeroSpreadedTermStructurePtr;

class ZeroSpreadedTermStructurePtr

    : public boost::shared_ptr<YieldTermStructure> {

  public:

    %extend {

        ZeroSpreadedTermStructurePtr(

                                const Handle<YieldTermStructure>& curveHandle,

                                const Handle<Quote>& spreadHandle) {

            return new ZeroSpreadedTermStructurePtr(

                new ZeroSpreadedTermStructure(curveHandle,spreadHandle));

        }

    }

};

 

To:

 

%rename(ZeroSpreadedTermStructure) ZeroSpreadedTermStructurePtr;

class ZeroSpreadedTermStructurePtr

    : public boost::shared_ptr<YieldTermStructure> {

  public:

    %extend {

        ZeroSpreadedTermStructurePtr(

                                const Handle<YieldTermStructure>& curveHandle,

                                const Handle<Quote>& spreadHandle,

                               Compounding comp = QuantLib::Continuous,

                                Frequency freq = QuantLib::NoFrequency,

                                const DayCounter& dc = QuantLib::DayCounter()) {

            return new ZeroSpreadedTermStructurePtr(

                new ZeroSpreadedTermStructure(curveHandle,spreadHandle, comp, freq, dc));

        }

    }

};

 

2.       Re-generate swig python binding

 

Regards,

Cheng

 

 

发件人: John Orford [mailto:[hidden email]]

发送时间: 201529 14:45
收件人: cheng li; QuantLib users

主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Cheng,

 

it looks like you hit the nail on the head - adding payment frequency and compounding to the ZeroSpreadedTermStructure constructor function looks like it will solve my problem.

 

Only issue is that my version of Quanlib Python bindings only allow 2 inputs into that function, not 4.

 

Could you let me know which version of the bindings you are using? Maybe it's customised?

 

Thanks,

 

John

 

 

 

On Mon Feb 09 2015 at 10:01:27 John Orford <[hidden email]> wrote:

Thanks Cheng! I'll check your amendments now and let you know : )

 

On Mon Feb 09 2015 at 9:58:35 AM cheng li <[hidden email]> wrote:

Hi John,

 

Thank you for sharing your codes. There are some changes needed to be made to your codes to make the example work properly:

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ))

 

Should be amended as :

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ), compounding,  payment_frequency)

 

Z-Spread has its own compounding rule and frequency. And you should make it consistent with what you offer to the function when you call CashFlows.zSpread.

 

Line 153: print "NPV+AA\t" + str(fixed_rate_bond.NPV() + fixed_rate_bond.accruedAmount())

 

Should be:

 

Line 153: print "NPV-AA\t" + str(fixed_rate_bond.NPV() - fixed_rate_bond.accruedAmount())

 

Normally NPV of bond is it dirty price. So AA should be excluded to be compared with MV which supposed to be clean price.

 

Regards,

Cheng

 

发件人: John Orford [mailto:[hidden email]]
发送时间: 201526 18:34
收件人: QuantLib users
主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Previous file was wrong - this is the one to look at.

On Fri Feb 06 2015 at 6:23:46 PM John Orford <[hidden email]> wrote:

I attached an example.

 

Suspect this isn't a stupid mistake, but a fundamental misunderstanding of mine, which is a little worrying.

 

Any help'll be appreciated.

 

John

 

On Fri Feb 06 2015 at 1:06:50 PM John Orford <[hidden email]> wrote:

Hey Guys,

 

Long time no questions - looking forward to getting back into QL again! Spending too much time ensconced in Javascript.

 

In any case, I can't figure out what I am doing wrong.

 

I create a FixedRateBond object with all the requisite accoutrements.

 

Then call a zSpread function reusing everything from the FixedRateBond object.

 

For the NPV which'll be calibrated to, I take a quoted clean market price and add the accrued amount from the bond object.

 

For example, MV = 135, Accrued Amt = 9.99, and NPV ~= 145.

 

However, when I take the output of the zSpread function and create a new object, the NPV turns out to be ~144.

 

I tried increasing accuracy and iterations but to no avail.

 

Are there any common gotchas while using the zSpread function?

 

As I write this I realise, a code example would be very helpful. I will do that now.

 

John


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users




--

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Bond Credit Spread Calibration

John Orford
Luigi, setting compounding and payment frequency to the zero spreaded term structure, made everything look as expected.

I am waiting for everything to recompile, and hopefully I should be good to go.

On 9 February 2015 at 17:01, Luigi Ballabio <[hidden email]> wrote:
Hi John,
    Cheng's right. I'd add a couple more things, though:

- if you want to quickly check consistency before regenerating the wrappers, you can go the other way around; keep the ZeroSpreadedTermStructure as it is, and use the Continuous compounding convention in the call to CashFlows.zSpread instead;

- regardless of the compounding convention, NPV() is probably not the right method to call. In a Bond, the NPV() method returns the value of the cash flows discounted to hte reference date of the discount curve, while in the market price they're discounted to the settlement date of the bond. On the one hand, you should pass the discount date to the zSpread call, as in:

    CashFlows.zSpread(fixed_rate_bond.cashflows(),                          
                      market_value + fixed_rate_bond.accruedAmount(),                   
                      bond_discounting_term_structure,
                      fixed_rate_bond.dayCounter(),                          
                      compounding,
                      fixed_rate_bond.frequency(),
                      False,                                                            
                      fixed_rate_bond.settlementDate())  # here

On the other hand, instead of NPV, you should call bond.cleanPrice() to get the estimated market value (or bond.dirtyPrice() to get the value plus the accrual).

Luigi



On Mon, Feb 9, 2015 at 8:37 AM, John Orford <[hidden email]> wrote:
Oh great - OK, I will do that and let you know how it goes, thanks!

On Mon Feb 09 2015 at 15:25:19 cheng li <[hidden email]> wrote:

Hi John

 

Sorry, I checked  the master branch. The Python interface only expects 2 arguments….

 

I think I have changed the interface by myself to fit my purpose some time ago though  I cant’t remember when…

 

On your side, to have the same interface with mine. You have to generate Python bindings with swig by yourself.

 

1.       Change the corresponding .i file

 

You have to change from the line 108  in termstructures.i file:

 

%rename(ZeroSpreadedTermStructure) ZeroSpreadedTermStructurePtr;

class ZeroSpreadedTermStructurePtr

    : public boost::shared_ptr<YieldTermStructure> {

  public:

    %extend {

        ZeroSpreadedTermStructurePtr(

                                const Handle<YieldTermStructure>& curveHandle,

                                const Handle<Quote>& spreadHandle) {

            return new ZeroSpreadedTermStructurePtr(

                new ZeroSpreadedTermStructure(curveHandle,spreadHandle));

        }

    }

};

 

To:

 

%rename(ZeroSpreadedTermStructure) ZeroSpreadedTermStructurePtr;

class ZeroSpreadedTermStructurePtr

    : public boost::shared_ptr<YieldTermStructure> {

  public:

    %extend {

        ZeroSpreadedTermStructurePtr(

                                const Handle<YieldTermStructure>& curveHandle,

                                const Handle<Quote>& spreadHandle,

                               Compounding comp = QuantLib::Continuous,

                                Frequency freq = QuantLib::NoFrequency,

                                const DayCounter& dc = QuantLib::DayCounter()) {

            return new ZeroSpreadedTermStructurePtr(

                new ZeroSpreadedTermStructure(curveHandle,spreadHandle, comp, freq, dc));

        }

    }

};

 

2.       Re-generate swig python binding

 

Regards,

Cheng

 

 

发件人: John Orford [mailto:[hidden email]]

发送时间: 201529 14:45
收件人: cheng li; QuantLib users

主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Cheng,

 

it looks like you hit the nail on the head - adding payment frequency and compounding to the ZeroSpreadedTermStructure constructor function looks like it will solve my problem.

 

Only issue is that my version of Quanlib Python bindings only allow 2 inputs into that function, not 4.

 

Could you let me know which version of the bindings you are using? Maybe it's customised?

 

Thanks,

 

John

 

 

 

On Mon Feb 09 2015 at 10:01:27 John Orford <[hidden email]> wrote:

Thanks Cheng! I'll check your amendments now and let you know : )

 

On Mon Feb 09 2015 at 9:58:35 AM cheng li <[hidden email]> wrote:

Hi John,

 

Thank you for sharing your codes. There are some changes needed to be made to your codes to make the example work properly:

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ))

 

Should be amended as :

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ), compounding,  payment_frequency)

 

Z-Spread has its own compounding rule and frequency. And you should make it consistent with what you offer to the function when you call CashFlows.zSpread.

 

Line 153: print "NPV+AA\t" + str(fixed_rate_bond.NPV() + fixed_rate_bond.accruedAmount())

 

Should be:

 

Line 153: print "NPV-AA\t" + str(fixed_rate_bond.NPV() - fixed_rate_bond.accruedAmount())

 

Normally NPV of bond is it dirty price. So AA should be excluded to be compared with MV which supposed to be clean price.

 

Regards,

Cheng

 

发件人: John Orford [mailto:[hidden email]]
发送时间: 201526 18:34
收件人: QuantLib users
主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Previous file was wrong - this is the one to look at.

On Fri Feb 06 2015 at 6:23:46 PM John Orford <[hidden email]> wrote:

I attached an example.

 

Suspect this isn't a stupid mistake, but a fundamental misunderstanding of mine, which is a little worrying.

 

Any help'll be appreciated.

 

John

 

On Fri Feb 06 2015 at 1:06:50 PM John Orford <[hidden email]> wrote:

Hey Guys,

 

Long time no questions - looking forward to getting back into QL again! Spending too much time ensconced in Javascript.

 

In any case, I can't figure out what I am doing wrong.

 

I create a FixedRateBond object with all the requisite accoutrements.

 

Then call a zSpread function reusing everything from the FixedRateBond object.

 

For the NPV which'll be calibrated to, I take a quoted clean market price and add the accrued amount from the bond object.

 

For example, MV = 135, Accrued Amt = 9.99, and NPV ~= 145.

 

However, when I take the output of the zSpread function and create a new object, the NPV turns out to be ~144.

 

I tried increasing accuracy and iterations but to no avail.

 

Are there any common gotchas while using the zSpread function?

 

As I write this I realise, a code example would be very helpful. I will do that now.

 

John


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users




--


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Bond Credit Spread Calibration

John Orford
Cheng & Luigi,

Everything's looking a lot better now. Thanks so much.

Cheng,

Is it OK to I make a pull request on Github with that SWIG amendment? So that everyone can benefit from your work in future? (or if you want to make the request yourself, I don't mind)

Also, do you have any more SWIG additions which are helpful? If you can share them.

Thanks again,

John



On 9 February 2015 at 17:26, John Orford <[hidden email]> wrote:
Luigi, setting compounding and payment frequency to the zero spreaded term structure, made everything look as expected.

I am waiting for everything to recompile, and hopefully I should be good to go.

On 9 February 2015 at 17:01, Luigi Ballabio <[hidden email]> wrote:
Hi John,
    Cheng's right. I'd add a couple more things, though:

- if you want to quickly check consistency before regenerating the wrappers, you can go the other way around; keep the ZeroSpreadedTermStructure as it is, and use the Continuous compounding convention in the call to CashFlows.zSpread instead;

- regardless of the compounding convention, NPV() is probably not the right method to call. In a Bond, the NPV() method returns the value of the cash flows discounted to hte reference date of the discount curve, while in the market price they're discounted to the settlement date of the bond. On the one hand, you should pass the discount date to the zSpread call, as in:

    CashFlows.zSpread(fixed_rate_bond.cashflows(),                          
                      market_value + fixed_rate_bond.accruedAmount(),                   
                      bond_discounting_term_structure,
                      fixed_rate_bond.dayCounter(),                          
                      compounding,
                      fixed_rate_bond.frequency(),
                      False,                                                            
                      fixed_rate_bond.settlementDate())  # here

On the other hand, instead of NPV, you should call bond.cleanPrice() to get the estimated market value (or bond.dirtyPrice() to get the value plus the accrual).

Luigi



On Mon, Feb 9, 2015 at 8:37 AM, John Orford <[hidden email]> wrote:
Oh great - OK, I will do that and let you know how it goes, thanks!

On Mon Feb 09 2015 at 15:25:19 cheng li <[hidden email]> wrote:

Hi John

 

Sorry, I checked  the master branch. The Python interface only expects 2 arguments….

 

I think I have changed the interface by myself to fit my purpose some time ago though  I cant’t remember when…

 

On your side, to have the same interface with mine. You have to generate Python bindings with swig by yourself.

 

1.       Change the corresponding .i file

 

You have to change from the line 108  in termstructures.i file:

 

%rename(ZeroSpreadedTermStructure) ZeroSpreadedTermStructurePtr;

class ZeroSpreadedTermStructurePtr

    : public boost::shared_ptr<YieldTermStructure> {

  public:

    %extend {

        ZeroSpreadedTermStructurePtr(

                                const Handle<YieldTermStructure>& curveHandle,

                                const Handle<Quote>& spreadHandle) {

            return new ZeroSpreadedTermStructurePtr(

                new ZeroSpreadedTermStructure(curveHandle,spreadHandle));

        }

    }

};

 

To:

 

%rename(ZeroSpreadedTermStructure) ZeroSpreadedTermStructurePtr;

class ZeroSpreadedTermStructurePtr

    : public boost::shared_ptr<YieldTermStructure> {

  public:

    %extend {

        ZeroSpreadedTermStructurePtr(

                                const Handle<YieldTermStructure>& curveHandle,

                                const Handle<Quote>& spreadHandle,

                               Compounding comp = QuantLib::Continuous,

                                Frequency freq = QuantLib::NoFrequency,

                                const DayCounter& dc = QuantLib::DayCounter()) {

            return new ZeroSpreadedTermStructurePtr(

                new ZeroSpreadedTermStructure(curveHandle,spreadHandle, comp, freq, dc));

        }

    }

};

 

2.       Re-generate swig python binding

 

Regards,

Cheng

 

 

发件人: John Orford [mailto:[hidden email]]

发送时间: 201529 14:45
收件人: cheng li; QuantLib users

主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Cheng,

 

it looks like you hit the nail on the head - adding payment frequency and compounding to the ZeroSpreadedTermStructure constructor function looks like it will solve my problem.

 

Only issue is that my version of Quanlib Python bindings only allow 2 inputs into that function, not 4.

 

Could you let me know which version of the bindings you are using? Maybe it's customised?

 

Thanks,

 

John

 

 

 

On Mon Feb 09 2015 at 10:01:27 John Orford <[hidden email]> wrote:

Thanks Cheng! I'll check your amendments now and let you know : )

 

On Mon Feb 09 2015 at 9:58:35 AM cheng li <[hidden email]> wrote:

Hi John,

 

Thank you for sharing your codes. There are some changes needed to be made to your codes to make the example work properly:

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ))

 

Should be amended as :

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ), compounding,  payment_frequency)

 

Z-Spread has its own compounding rule and frequency. And you should make it consistent with what you offer to the function when you call CashFlows.zSpread.

 

Line 153: print "NPV+AA\t" + str(fixed_rate_bond.NPV() + fixed_rate_bond.accruedAmount())

 

Should be:

 

Line 153: print "NPV-AA\t" + str(fixed_rate_bond.NPV() - fixed_rate_bond.accruedAmount())

 

Normally NPV of bond is it dirty price. So AA should be excluded to be compared with MV which supposed to be clean price.

 

Regards,

Cheng

 

发件人: John Orford [mailto:[hidden email]]
发送时间: 201526 18:34
收件人: QuantLib users
主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Previous file was wrong - this is the one to look at.

On Fri Feb 06 2015 at 6:23:46 PM John Orford <[hidden email]> wrote:

I attached an example.

 

Suspect this isn't a stupid mistake, but a fundamental misunderstanding of mine, which is a little worrying.

 

Any help'll be appreciated.

 

John

 

On Fri Feb 06 2015 at 1:06:50 PM John Orford <[hidden email]> wrote:

Hey Guys,

 

Long time no questions - looking forward to getting back into QL again! Spending too much time ensconced in Javascript.

 

In any case, I can't figure out what I am doing wrong.

 

I create a FixedRateBond object with all the requisite accoutrements.

 

Then call a zSpread function reusing everything from the FixedRateBond object.

 

For the NPV which'll be calibrated to, I take a quoted clean market price and add the accrued amount from the bond object.

 

For example, MV = 135, Accrued Amt = 9.99, and NPV ~= 145.

 

However, when I take the output of the zSpread function and create a new object, the NPV turns out to be ~144.

 

I tried increasing accuracy and iterations but to no avail.

 

Are there any common gotchas while using the zSpread function?

 

As I write this I realise, a code example would be very helpful. I will do that now.

 

John


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users




--



------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

答复: Bond Credit Spread Calibration

cheng li

Hi John,

 

1.       Just go ahead, it is just fineJ

 

2.       Let me find some….

 

Regards,

Cheng

 

发件人: John Orford [mailto:[hidden email]]
发送时间: 201529 19:03
收件人: Luigi Ballabio
抄送: cheng li; QuantLib users
主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Cheng & Luigi,

Everything's looking a lot better now. Thanks so much.

Cheng,

Is it OK to I make a pull request on Github with that SWIG amendment? So that everyone can benefit from your work in future? (or if you want to make the request yourself, I don't mind)

Also, do you have any more SWIG additions which are helpful? If you can share them.

Thanks again,

John

 

 

On 9 February 2015 at 17:26, John Orford <[hidden email]> wrote:

Luigi, setting compounding and payment frequency to the zero spreaded term structure, made everything look as expected.

I am waiting for everything to recompile, and hopefully I should be good to go.

 

On 9 February 2015 at 17:01, Luigi Ballabio <[hidden email]> wrote:

Hi John,

    Cheng's right. I'd add a couple more things, though:

 

- if you want to quickly check consistency before regenerating the wrappers, you can go the other way around; keep the ZeroSpreadedTermStructure as it is, and use the Continuous compounding convention in the call to CashFlows.zSpread instead;

 

- regardless of the compounding convention, NPV() is probably not the right method to call. In a Bond, the NPV() method returns the value of the cash flows discounted to hte reference date of the discount curve, while in the market price they're discounted to the settlement date of the bond. On the one hand, you should pass the discount date to the zSpread call, as in:

 

    CashFlows.zSpread(fixed_rate_bond.cashflows(),                          

                      market_value + fixed_rate_bond.accruedAmount(),                   

                      bond_discounting_term_structure,

                      fixed_rate_bond.dayCounter(),                          

                      compounding,

                      fixed_rate_bond.frequency(),

                      False,                                                            

                      fixed_rate_bond.settlementDate())  # here

 

On the other hand, instead of NPV, you should call bond.cleanPrice() to get the estimated market value (or bond.dirtyPrice() to get the value plus the accrual).

 

Luigi

 

 

 

On Mon, Feb 9, 2015 at 8:37 AM, John Orford <[hidden email]> wrote:

Oh great - OK, I will do that and let you know how it goes, thanks!

 

On Mon Feb 09 2015 at 15:25:19 cheng li <[hidden email]> wrote:

Hi John

 

Sorry, I checked  the master branch. The Python interface only expects 2 arguments….

 

I think I have changed the interface by myself to fit my purpose some time ago though  I cant’t remember when…

 

On your side, to have the same interface with mine. You have to generate Python bindings with swig by yourself.

 

1.       Change the corresponding .i file

 

You have to change from the line 108  in termstructures.i file:

 

%rename(ZeroSpreadedTermStructure) ZeroSpreadedTermStructurePtr;

class ZeroSpreadedTermStructurePtr

    : public boost::shared_ptr<YieldTermStructure> {

  public:

    %extend {

        ZeroSpreadedTermStructurePtr(

                                const Handle<YieldTermStructure>& curveHandle,

                                const Handle<Quote>& spreadHandle) {

            return new ZeroSpreadedTermStructurePtr(

                new ZeroSpreadedTermStructure(curveHandle,spreadHandle));

        }

    }

};

 

To:

 

%rename(ZeroSpreadedTermStructure) ZeroSpreadedTermStructurePtr;

class ZeroSpreadedTermStructurePtr

    : public boost::shared_ptr<YieldTermStructure> {

  public:

    %extend {

        ZeroSpreadedTermStructurePtr(

                                const Handle<YieldTermStructure>& curveHandle,

                                const Handle<Quote>& spreadHandle,

                               Compounding comp = QuantLib::Continuous,

                                Frequency freq = QuantLib::NoFrequency,

                                const DayCounter& dc = QuantLib::DayCounter()) {

            return new ZeroSpreadedTermStructurePtr(

                new ZeroSpreadedTermStructure(curveHandle,spreadHandle, comp, freq, dc));

        }

    }

};

 

2.       Re-generate swig python binding

 

Regards,

Cheng

 

 

发件人: John Orford [mailto:[hidden email]]

发送时间: 201529 14:45
收件人: cheng li; QuantLib users

主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Cheng,

 

it looks like you hit the nail on the head - adding payment frequency and compounding to the ZeroSpreadedTermStructure constructor function looks like it will solve my problem.

 

Only issue is that my version of Quanlib Python bindings only allow 2 inputs into that function, not 4.

 

Could you let me know which version of the bindings you are using? Maybe it's customised?

 

Thanks,

 

John

 

 

 

On Mon Feb 09 2015 at 10:01:27 John Orford <[hidden email]> wrote:

Thanks Cheng! I'll check your amendments now and let you know : )

 

On Mon Feb 09 2015 at 9:58:35 AM cheng li <[hidden email]> wrote:

Hi John,

 

Thank you for sharing your codes. There are some changes needed to be made to your codes to make the example work properly:

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ))

 

Should be amended as :

 

Line 80: z_spreaded_term_structure = ZeroSpreadedTermStructure( discounting_term_structure, QuoteHandle( z_spread ), compounding,  payment_frequency)

 

Z-Spread has its own compounding rule and frequency. And you should make it consistent with what you offer to the function when you call CashFlows.zSpread.

 

Line 153: print "NPV+AA\t" + str(fixed_rate_bond.NPV() + fixed_rate_bond.accruedAmount())

 

Should be:

 

Line 153: print "NPV-AA\t" + str(fixed_rate_bond.NPV() - fixed_rate_bond.accruedAmount())

 

Normally NPV of bond is it dirty price. So AA should be excluded to be compared with MV which supposed to be clean price.

 

Regards,

Cheng

 

发件人: John Orford [mailto:[hidden email]]
发送时间: 201526 18:34
收件人: QuantLib users
主题: Re: [Quantlib-users] Bond Credit Spread Calibration

 

Previous file was wrong - this is the one to look at.

On Fri Feb 06 2015 at 6:23:46 PM John Orford <[hidden email]> wrote:

I attached an example.

 

Suspect this isn't a stupid mistake, but a fundamental misunderstanding of mine, which is a little worrying.

 

Any help'll be appreciated.

 

John

 

On Fri Feb 06 2015 at 1:06:50 PM John Orford <[hidden email]> wrote:

Hey Guys,

 

Long time no questions - looking forward to getting back into QL again! Spending too much time ensconced in Javascript.

 

In any case, I can't figure out what I am doing wrong.

 

I create a FixedRateBond object with all the requisite accoutrements.

 

Then call a zSpread function reusing everything from the FixedRateBond object.

 

For the NPV which'll be calibrated to, I take a quoted clean market price and add the accrued amount from the bond object.

 

For example, MV = 135, Accrued Amt = 9.99, and NPV ~= 145.

 

However, when I take the output of the zSpread function and create a new object, the NPV turns out to be ~144.

 

I tried increasing accuracy and iterations but to no avail.

 

Are there any common gotchas while using the zSpread function?

 

As I write this I realise, a code example would be very helpful. I will do that now.

 

John

 

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users



 

--

 

 


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users