ActualActual::ISMA bond duration problem (1.0.1 version of bondscalc)

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

ActualActual::ISMA bond duration problem (1.0.1 version of bondscalc)

Dagur Gunnarsson-2
hello,

Could there be a bug in the calculation of duration for ActualActual::ISMA FixedRateBonds - as I am getting the same Duration for all settlement dates from 21. of Mars to the 28 of Mars.

Here is the program I am running 

#include <ql/quantlib.hpp>
#include <iostream>

using namespace QuantLib;
using namespace std;

int main(int, char* [])
{
  Date settlementDate = Date(21, Mar, 2012);
  Date issueDate = Date(13, Oct, 2010);
  Date interestFromDate = Date(13, Oct, 2010);
  Date firstCouponDate = Date(13, Oct, 2011);
  Date firstInstallmentDate = Date(13, Oct, 2016);
  Date maturityDate = Date(13, Oct, 2016);
  Real couponRate = 0.06;

  Frequency freq(Annual);

  DayCounter dayCounter =  ActualActual(ActualActual::ISMA);
  Compounding compounding(Compounded);

  Schedule *schedule = new Schedule(interestFromDate, 
   maturityDate, 
   Period(freq), 
   Iceland(), 
   Unadjusted, 
   Unadjusted, 
   DateGeneration::Backward, 
   false, 
   firstCouponDate);

  FixedRateBond* bond = new FixedRateBond(1, 
 100.0, 
 *schedule, 
 vector<Rate>(1, Rate(couponRate)), 
 dayCounter, 
 Following,
 Real(100.0), 
 issueDate);
  
  std::vector <boost::shared_ptr<QuantLib::CashFlow>, std::allocator<boost::shared_ptr<QuantLib::CashFlow> > > leg = bond->cashflows();
    
  for (unsigned i = 0; i < leg.size(); i++) {
    cout<<"day["<<i<<"] is "<<leg[i]->date()<<" "<<setprecision(15)
<<dayCounter.yearFraction(settlementDate, leg[i]->date())<<", cashflow["<<i<<"] is "<<leg[i]->amount()<<endl;
    }

  Real yield = 0.05;
  Real d1 = BondFunctions::duration(*bond, InterestRate(yield, dayCounter, compounding, Annual), Duration::Macaulay, settlementDate);
  Real d2 = BondFunctions::duration(*bond, InterestRate(yield, dayCounter, compounding, Annual), Duration::Macaulay, settlementDate+7);

  cout<<"duration for settlement date1 "<<settlementDate<<" is "<<d1<<endl;
  cout<<"duration for settlement date1 "<<settlementDate+7<<" is "<<d2<<endl;
}

this gives me

day[0] is October 13th, 2011 -0.416666666666667, cashflow[0] is 6.00000000000001
day[1] is October 15th, 2012 0.583333333333333, cashflow[1] is 6.00000000000001
day[2] is October 14th, 2013 1.58333333333333, cashflow[2] is 6.00000000000001
day[3] is October 13th, 2014 2.58333333333333, cashflow[3] is 6.00000000000001
day[4] is October 13th, 2015 3.58333333333333, cashflow[4] is 6.00000000000001
day[5] is October 13th, 2016 4.58333333333333, cashflow[5] is 6.00000000000001
day[6] is October 13th, 2016 4.58333333333333, cashflow[6] is 100
duration for settlement date1 March 21st, 2012 is 4.06108457642133
duration for settlement date1 March 28th, 2012 is 4.06108457642133

the duration is the same on both dates for ActualActual::ISMA, but not for i.e. ActualActual::AFB - Could this be a bug?

regards
Dagur G 



------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: ActualActual::ISMA bond duration problem (1.0.1 version of bondscalc)

Guowen Han

The implementation for the yearFraction for ActualActual::ISMA daycount was not correct. I would suggest you to use ActualActual::ISDA instead.

 

From: Dagur Gunnarsson [mailto:[hidden email]]
Sent: Thursday, March 22, 2012 11:16 AM
To: [hidden email]
Subject: [Quantlib-users] ActualActual::ISMA bond duration problem (1.0.1 version of bondscalc)

 

hello,

 

Could there be a bug in the calculation of duration for ActualActual::ISMA FixedRateBonds - as I am getting the same Duration for all settlement dates from 21. of Mars to the 28 of Mars.

 

Here is the program I am running 

 

#include <ql/quantlib.hpp>

#include <iostream>

 

using namespace QuantLib;

using namespace std;

 

int main(int, char* [])

{

  Date settlementDate = Date(21, Mar, 2012);

  Date issueDate = Date(13, Oct, 2010);

  Date interestFromDate = Date(13, Oct, 2010);

  Date firstCouponDate = Date(13, Oct, 2011);

  Date firstInstallmentDate = Date(13, Oct, 2016);

  Date maturityDate = Date(13, Oct, 2016);

  Real couponRate = 0.06;

 

  Frequency freq(Annual);

 

  DayCounter dayCounter =  ActualActual(ActualActual::ISMA);

  Compounding compounding(Compounded);

 

  Schedule *schedule = new Schedule(interestFromDate, 

                                                   maturityDate, 

                                                   Period(freq), 

                                                   Iceland(), 

                                                   Unadjusted, 

                                                   Unadjusted, 

                                                   DateGeneration::Backward, 

                                                   false, 

                                                   firstCouponDate);

 

  FixedRateBond* bond = new FixedRateBond(1, 

                                                             100.0, 

                                                             *schedule, 

                                                             vector<Rate>(1, Rate(couponRate)), 

                                                             dayCounter, 

                                                             Following,

                                                             Real(100.0), 

                                                             issueDate);

  

  std::vector <boost::shared_ptr<QuantLib::CashFlow>, std::allocator<boost::shared_ptr<QuantLib::CashFlow> > > leg = bond->cashflows();

    

  for (unsigned i = 0; i < leg.size(); i++) {

    cout<<"day["<<i<<"] is "<<leg[i]->date()<<" "<<setprecision(15)

            <<dayCounter.yearFraction(settlementDate, leg[i]->date())<<", cashflow["<<i<<"] is "<<leg[i]->amount()<<endl;

    }

 

  Real yield = 0.05;

  Real d1 = BondFunctions::duration(*bond, InterestRate(yield, dayCounter, compounding, Annual), Duration::Macaulay, settlementDate);

  Real d2 = BondFunctions::duration(*bond, InterestRate(yield, dayCounter, compounding, Annual), Duration::Macaulay, settlementDate+7);

 

  cout<<"duration for settlement date1 "<<settlementDate<<" is "<<d1<<endl;

  cout<<"duration for settlement date1 "<<settlementDate+7<<" is "<<d2<<endl;

}

 

this gives me

 

day[0] is October 13th, 2011 -0.416666666666667, cashflow[0] is 6.00000000000001

day[1] is October 15th, 2012 0.583333333333333, cashflow[1] is 6.00000000000001

day[2] is October 14th, 2013 1.58333333333333, cashflow[2] is 6.00000000000001

day[3] is October 13th, 2014 2.58333333333333, cashflow[3] is 6.00000000000001

day[4] is October 13th, 2015 3.58333333333333, cashflow[4] is 6.00000000000001

day[5] is October 13th, 2016 4.58333333333333, cashflow[5] is 6.00000000000001

day[6] is October 13th, 2016 4.58333333333333, cashflow[6] is 100

duration for settlement date1 March 21st, 2012 is 4.06108457642133

duration for settlement date1 March 28th, 2012 is 4.06108457642133

 

the duration is the same on both dates for ActualActual::ISMA, but not for i.e. ActualActual::AFB - Could this be a bug?

 

regards

Dagur G 

 

 


_____________________________________________________________
DTCC DISCLAIMER: This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error, please notify us immediately and delete the email and any attachments from your system. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: ActualActual::ISMA bond duration problem (1.0.1 version of bondscalc)

Luigi Ballabio
On Thu, Mar 22, 2012 at 4:20 PM, Han, Guowen <[hidden email]> wrote:
> The implementation for the yearFraction for ActualActual::ISMA daycount was
> not correct.

And the bug was what exactly? Was it reported?

Thanks,
    Luigi

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: ActualActual::ISMA bond duration problem (1.0.1 version of bondscalc)

Luigi Ballabio
In reply to this post by Dagur Gunnarsson-2
On Thu, Mar 22, 2012 at 4:15 PM, Dagur Gunnarsson <[hidden email]> wrote:
> Could there be a bug in the calculation of duration for ActualActual::ISMA
> FixedRateBonds - as I am getting the same Duration for all settlement dates
> from 21. of Mars to the 28 of Mars.

It could.  It might have to do with the reference dates passed (or not
passed) to the day counter during calculation.  I'll have to run your
code in a debugger, though, so it might be a while before I find some
time. (Of course you're welcome to try yourself and tell me what you
find, if you want).

Later,
    Luigi


> Here is the program I am running
>
> #include <ql/quantlib.hpp>
> #include <iostream>
>
> using namespace QuantLib;
> using namespace std;
>
> int main(int, char* [])
> {
>   Date settlementDate = Date(21, Mar, 2012);
>   Date issueDate = Date(13, Oct, 2010);
>   Date interestFromDate = Date(13, Oct, 2010);
>   Date firstCouponDate = Date(13, Oct, 2011);
>   Date firstInstallmentDate = Date(13, Oct, 2016);
>   Date maturityDate = Date(13, Oct, 2016);
>   Real couponRate = 0.06;
>
>   Frequency freq(Annual);
>
>   DayCounter dayCounter =  ActualActual(ActualActual::ISMA);
>   Compounding compounding(Compounded);
>
>   Schedule *schedule = new Schedule(interestFromDate,
>    maturityDate,
>    Period(freq),
>    Iceland(),
>    Unadjusted,
>    Unadjusted,
>    DateGeneration::Backward,
>    false,
>    firstCouponDate);
>
>   FixedRateBond* bond = new FixedRateBond(1,
>  100.0,
>  *schedule,
>  vector<Rate>(1, Rate(couponRate)),
>  dayCounter,
>  Following,
>  Real(100.0),
>  issueDate);
>
>   std::vector <boost::shared_ptr<QuantLib::CashFlow>,
> std::allocator<boost::shared_ptr<QuantLib::CashFlow> > > leg =
> bond->cashflows();
>
>   for (unsigned i = 0; i < leg.size(); i++) {
>     cout<<"day["<<i<<"] is "<<leg[i]->date()<<" "<<setprecision(15)
> <<dayCounter.yearFraction(settlementDate, leg[i]->date())<<",
> cashflow["<<i<<"] is "<<leg[i]->amount()<<endl;
>     }
>
>   Real yield = 0.05;
>   Real d1 = BondFunctions::duration(*bond, InterestRate(yield, dayCounter,
> compounding, Annual), Duration::Macaulay, settlementDate);
>   Real d2 = BondFunctions::duration(*bond, InterestRate(yield, dayCounter,
> compounding, Annual), Duration::Macaulay, settlementDate+7);
>
>   cout<<"duration for settlement date1 "<<settlementDate<<" is "<<d1<<endl;
>   cout<<"duration for settlement date1 "<<settlementDate+7<<" is
> "<<d2<<endl;
> }
>
> this gives me
>
> day[0] is October 13th, 2011 -0.416666666666667, cashflow[0] is
> 6.00000000000001
> day[1] is October 15th, 2012 0.583333333333333, cashflow[1] is
> 6.00000000000001
> day[2] is October 14th, 2013 1.58333333333333, cashflow[2] is
> 6.00000000000001
> day[3] is October 13th, 2014 2.58333333333333, cashflow[3] is
> 6.00000000000001
> day[4] is October 13th, 2015 3.58333333333333, cashflow[4] is
> 6.00000000000001
> day[5] is October 13th, 2016 4.58333333333333, cashflow[5] is
> 6.00000000000001
> day[6] is October 13th, 2016 4.58333333333333, cashflow[6] is 100
> duration for settlement date1 March 21st, 2012 is 4.06108457642133
> duration for settlement date1 March 28th, 2012 is 4.06108457642133
>
> the duration is the same on both dates for ActualActual::ISMA, but not for
> i.e. ActualActual::AFB - Could this be a bug?
>
> regards
> Dagur G
>
>
>
> ------------------------------------------------------------------------------
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here
> http://p.sf.net/sfu/sfd2d-msazure
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users