Fwd: Price Bond from CDS Spread & Recovery Rate

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

Fwd: Price Bond from CDS Spread & Recovery Rate

japari


----- Forwarded Message -----
From: [hidden email]
To: "Ferdinando M. Ametrano" <[hidden email]>
Sent: Tuesday, 18 February, 2014 9:56:35 AM

Sorry Nando,

Subject: Re: [Quantlib-users] Price Bond from CDS Spread & Recovery Rate

Hi,
unless your looking to modify directly the YTS a small modif from the Examples code would do the trick, this is a modified  copy/paste from there, it uses the bond in experimental, look the file there.
Also one of my branches at github has QXL code for this but that probably wouldnt pass Nandos tough exam requirements ;-)


#include <ql/quantlib.hpp>

using namespace QuantLib;
using namespace std;

int main() {

    Calendar calendar = TARGET();
    Date todaysDate(18, Feb, 2014);
    // must be a business day
    todaysDate = calendar.adjust(todaysDate);
    Settings::instance().evaluationDate() = todaysDate;
    // dummy curve
    boost::shared_ptr<Quote> flatRate(new SimpleQuote(0.01));
    Handle<YieldTermStructure> tsCurve(
          boost::shared_ptr<FlatForward>(
                  new FlatForward(todaysDate, Handle<Quote>(flatRate),
                                  Actual365Fixed())));
    // market
    Real recovery_rate = 0.5;
    Real marketSpread  = 0.05;
    vector<Date> maturities(1, calendar.adjust(todaysDate + Period(5*Years),
                                             Following));
    std::vector<boost::shared_ptr<DefaultProbabilityHelper> > instruments(1,
       // instruments.push_back(
         boost::shared_ptr<SpreadCdsHelper>(
           new SpreadCdsHelper(
                          marketSpread,
                          Period(5*Years),
                          0,
                          calendar,
                          Quarterly,
                          Following,
                          DateGeneration::TwentiethIMM,
                          Actual365Fixed(),
                          recovery_rate,
                          tsCurve))); // no make_shared prior to c11; 10 arguments
    // Bootstrap hazard rates
    boost::shared_ptr<PiecewiseDefaultCurve<HazardRate, BackwardFlat> >
        hazardRateStructure(boost::make_shared<PiecewiseDefaultCurve<HazardRate, BackwardFlat> >(
                                                       todaysDate,
                                                       instruments,
                                                       Actual365Fixed()));
    Handle<DefaultProbabilityTermStructure> probability(hazardRateStructure);
    Date bondMaturity =
        calendar.adjust(todaysDate + Period(3*Years), Following);
        Schedule bondSchedule =
            MakeSchedule().from(todaysDate).to(bondMaturity)
                          .withFrequency(Quarterly)
                          .withCalendar(calendar)
                          .withTerminationDateConvention(Unadjusted)
                          .withRule(DateGeneration::TwentiethIMM);
    Rate bondRate = flatRate->value() * 1.2;// 20% above risk free flat rate
    std::vector<Real> notionals(1, 1000000.);
    RiskyFixedBond theBond(std::string("AcmeBond"), EURCurrency(),
        recovery_rate, probability, bondSchedule, bondRate,
    Actual365Fixed(), Unadjusted, notionals, tsCurve);
    Real riskyValue = theBond.NPV();

    return 0;
}

Best
Pepe


----- Original Message -----
From: "Ferdinando M. Ametrano" <[hidden email]>
To: "Alexis Chaupin" <[hidden email]>
Cc: "QuantLib Mailing Lists" <[hidden email]>
Sent: Tuesday, 18 February, 2014 7:55:31 AM
Subject: Re: [Quantlib-users] Price Bond from CDS Spread & Recovery Rate




This is the common exam assignment for my students using QuantLibXL.
Not everything is properly packaged ready to be used, but it is easy enough

On Feb 17, 2014 9:03 PM, "Alexis Chaupin" < [hidden email] > wrote:




Hi everyone,


I would like to use QuantLib for pricing Bonds from CDS Spread and Recovery Rate.
Is it already implemented in QL or do I need to do it myself?


It is the first time that I am using QL so any help will be appreciated.


Many thanks,
Alexis
------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk 
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users 


------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Price Bond from CDS Spread & Recovery Rate

Alexis Chaupin
Thanks Pepe, it's a good start :)


On 18 February 2014 10:00, <[hidden email]> wrote:


----- Forwarded Message -----
From: [hidden email]
To: "Ferdinando M. Ametrano" <[hidden email]>
Sent: Tuesday, 18 February, 2014 9:56:35 AM

Sorry Nando,

Subject: Re: [Quantlib-users] Price Bond from CDS Spread & Recovery Rate

Hi,
unless your looking to modify directly the YTS a small modif from the Examples code would do the trick, this is a modified  copy/paste from there, it uses the bond in experimental, look the file there.
Also one of my branches at github has QXL code for this but that probably wouldnt pass Nandos tough exam requirements ;-)


#include <ql/quantlib.hpp>

using namespace QuantLib;
using namespace std;

int main() {

    Calendar calendar = TARGET();
    Date todaysDate(18, Feb, 2014);
    // must be a business day
    todaysDate = calendar.adjust(todaysDate);
    Settings::instance().evaluationDate() = todaysDate;
    // dummy curve
    boost::shared_ptr<Quote> flatRate(new SimpleQuote(0.01));
    Handle<YieldTermStructure> tsCurve(
          boost::shared_ptr<FlatForward>(
                  new FlatForward(todaysDate, Handle<Quote>(flatRate),
                                  Actual365Fixed())));
    // market
    Real recovery_rate = 0.5;
    Real marketSpread  = 0.05;
    vector<Date> maturities(1, calendar.adjust(todaysDate + Period(5*Years),
                                             Following));
    std::vector<boost::shared_ptr<DefaultProbabilityHelper> > instruments(1,
       // instruments.push_back(
         boost::shared_ptr<SpreadCdsHelper>(
           new SpreadCdsHelper(
                          marketSpread,
                          Period(5*Years),
                          0,
                          calendar,
                          Quarterly,
                          Following,
                          DateGeneration::TwentiethIMM,
                          Actual365Fixed(),
                          recovery_rate,
                          tsCurve))); // no make_shared prior to c11; 10 arguments
    // Bootstrap hazard rates
    boost::shared_ptr<PiecewiseDefaultCurve<HazardRate, BackwardFlat> >
        hazardRateStructure(boost::make_shared<PiecewiseDefaultCurve<HazardRate, BackwardFlat> >(
                                                       todaysDate,
                                                       instruments,
                                                       Actual365Fixed()));
    Handle<DefaultProbabilityTermStructure> probability(hazardRateStructure);
    Date bondMaturity =
        calendar.adjust(todaysDate + Period(3*Years), Following);
        Schedule bondSchedule =
            MakeSchedule().from(todaysDate).to(bondMaturity)
                          .withFrequency(Quarterly)
                          .withCalendar(calendar)
                          .withTerminationDateConvention(Unadjusted)
                          .withRule(DateGeneration::TwentiethIMM);
    Rate bondRate = flatRate->value() * 1.2;// 20% above risk free flat rate
    std::vector<Real> notionals(1, 1000000.);
    RiskyFixedBond theBond(std::string("AcmeBond"), EURCurrency(),
        recovery_rate, probability, bondSchedule, bondRate,
    Actual365Fixed(), Unadjusted, notionals, tsCurve);
    Real riskyValue = theBond.NPV();

    return 0;
}

Best
Pepe


----- Original Message -----
From: "Ferdinando M. Ametrano" <[hidden email]>
To: "Alexis Chaupin" <[hidden email]>
Cc: "QuantLib Mailing Lists" <[hidden email]>
Sent: Tuesday, 18 February, 2014 7:55:31 AM
Subject: Re: [Quantlib-users] Price Bond from CDS Spread & Recovery Rate




This is the common exam assignment for my students using QuantLibXL.
Not everything is properly packaged ready to be used, but it is easy enough

On Feb 17, 2014 9:03 PM, "Alexis Chaupin" < [hidden email] > wrote:




Hi everyone,


I would like to use QuantLib for pricing Bonds from CDS Spread and Recovery Rate.
Is it already implemented in QL or do I need to do it myself?


It is the first time that I am using QL so any help will be appreciated.


Many thanks,
Alexis
------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users