Re: FixedRateBond question

Posted by Piter Dias-4 on
URL: http://quantlib.414.s1.nabble.com/FixedRateBond-question-tp5985p5987.html

Dagur,

 

Please try the FixedRateBond constructor that accepts InterestRate object instead of just Rate one.

Something like

 

  InterestRate coupon(0.06,

                           dayCounter,

                           Compounded, Annual);

 

  FixedRateBond* bond = new FixedRateBond(0,

                                   100.0,

                                   *schedule,

                                   vector<InterestRate>(1, coupon),

                                   Unadjusted,

                                  Real(100.0),

                                   issueDate);

 

may work for you.

 

From: Dagur Gunnarsson [mailto:[hidden email]]
Sent: 12 December 2011 14:27
To: [hidden email]
Subject: [Quantlib-users] FixedRateBond question

 

I am calculating the cashflow for a FixedRateBond which start paying coupons 2,37222 years after its issue date.  After that period the coupons are semiannual.  During the 2,37222 years period, I would like my bond to accrue Compounding interests (1.06)^2,37222-1 and not Simple interests (0,06)*2,37222 - which seems to be the Default for FixedRateBonds.

 

My question is, how do I make my FixedRateBond calculate Compounding interests instead of Simple??

 

my program is the following :

 

#include <ql/quantlib.hpp>

#include <iostream>

 

using namespace QuantLib;

using namespace std;

 

int main(int, char* [])

{

  Date interestFromDate(Date(1, Jun, 2011)), issueDate(Date(1, Jun, 2011)),

    firstInstallmentDate(Date(15, Oct, 2016)), maturityDate(Date(15, Oct, 2016)),

    firstCouponDate(Date(15, Oct, 2013));

 

  Rate rate(0.06);

 

  Frequency freq(Semiannual);

 

  DayCounter dayCounter(Thirty360(Thirty360::European));

  Compounding compounding(Compounded);

  

 

  Schedule *schedule = new Schedule(interestFromDate, 

                                                  maturityDate, 

                                                  Period(freq), 

                                                  Iceland(), 

                                                  Unadjusted, 

                                                  Unadjusted, 

                                                  DateGeneration::Backward, 

                                                  false, 

                                                  firstCouponDate);

 

  FixedRateBond* bond = new FixedRateBond(0, 

                                                            100.0, 

                                                            *schedule, 

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

                                                            dayCounter, 

                                                            Unadjusted,

                                                            Real(100.0), 

                                                            issueDate);

 

  boost::shared_ptr<YieldTermStructure> 

    flatTermStructure(

                             new FlatForward(

                                                    issueDate, 

                                                    Handle<Quote>(boost::shared_ptr<Quote>(new SimpleQuote(rate))), 

                                                    dayCounter,

                                                    compounding,

                                                    freq));

  

  RelinkableHandle<YieldTermStructure> discountingTermStructure(flatTermStructure);

  discountingTermStructure.linkTo(flatTermStructure);

  

  boost::shared_ptr<PricingEngine> bondEngine(new DiscountingBondEngine(discountingTermStructure));

  bond->setPricingEngine(bondEngine);

  

  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(Date(1, Jun, 2011), leg[i]->date())<<", cashflow["<<i<<"] is "<<leg[i]->amount()<<endl;

    }

 

}


------------------------------------------------------------------------------
Systems Optimization Self Assessment
Improve efficiency and utilization of IT resources. Drive out cost and
improve service delivery. Take 5 minutes to use this Systems Optimization
Self Assessment. http://www.accelacomm.com/jaw/sdnl/114/51450054/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users