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;
} } ------------------------------------------------------------------------------ Learn Windows Azure Live! Tuesday, Dec 13, 2011 Microsoft is holding a special Learn Windows Azure training event for developers. It will provide a great way to learn Windows Azure and what it provides. You can attend the event by watching it streamed LIVE online. Learn more at http://p.sf.net/sfu/ms-windowsazure _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
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]] 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 |
In reply to this post by Dagur Gunnarsson-2
On Tue, Dec 13, 2011 at 2:40 AM, Piter Dias <[hidden email]> wrote:
> Please try the FixedRateBond constructor that accepts InterestRate object > instead of just Rate one. Correct, but the coupons after the first are simple. Instead of InterestRate coupon(0.06, dayCounter, Compounded, Annual); FixedRateBond(..., vector<InterestRate>(1, coupon), ...) you'll have to build a vector with the first element set to the InterestRate instance above and the others set to an instance of InterestRate with simple compounding. Luigi ------------------------------------------------------------------------------ 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 |
Free forum by Nabble | Edit this page |