Posted by
Jeffrey-J.Yu on
URL: http://quantlib.414.s1.nabble.com/FixedCouponBond-pricing-wrong-tp3741p3744.html
Ning,
I think you present one extreme condition in the way you use FixedCouponBond:
1. the issue date is 11/1/04;
2. the settlement date is 11/1/04;
In reality, I dont know if you can do this. However, you make a case that the
price/yield calculation should consider this, or prevent further calculation because of
the invalid entry. Let me think about how this should be addressed.
You can certainly put in some more realistic inputs to test it out.
Cheers,
Jeff
-----Original Message-----
From:
[hidden email]
[mailto:
[hidden email]]On Behalf Of Feng
Ning
Sent: Friday, April 22, 2005 10:23 AM
To:
[hidden email]
Cc:
[hidden email]
Subject: Re: [Quantlib-users] FixedCouponBond pricing wrong?
Thanks to Luigi for his reply. But the problem persist.
1) I am not clear what it means:
Date today(30, October, 2004);
I assume it means we should set the evaluation date, so I use:
Settings::instance().setEvaluationDate(Date(31,October,2004));
It turns out: calculated clean price=95.92, dirty price = 98.42.
2) my computation differs from Luigi's bcoz I feel that the coupon is
semiannual value, so I use c=0.025/2, instead of c=0.025.
I verify this by printing out the cashflows as in the code.
The complete code is below:
// bond-tester.cpp
#include <iostream>
#include <ql/quantlib.hpp>
using namespace QuantLib;
int main() {
Settings::instance().setEvaluationDate(Date(31,October,2004));
std::cout << "today date: "<< Date::todaysDate() << std::endl;
Calendar bondCalendar = nullCalendar();
DayCounter bondDayCount = OneDayCounter();
Integer settlementDays = 1;
// actual market values from the evaluation date
FixedCouponBond bond1(Date(1,November,2004),
Date(31,October,2004),
Date(31,October,2006),
settlementDays,
0.025, Semiannual,
bondDayCount, bondCalendar,
Unadjusted, 100.0);
Real marketPrice1 = 99.203125;
Rate marketYield1 = 0.02925;
// check
Real tolerance = 1.0e-6;
Real price, dprice, yield;
// calculated values
Real cachedPrice1 = 99.204505;
Rate cachedYield1 = 0.029257;
price = bond1.cleanPrice(marketYield1);
dprice = bond1.dirtyPrice(marketYield1);
std::cout << " calculated clean price: "
<< DecimalFormatter::toString(price,6) << "\n"
<< " calculated dirty price: "
<< DecimalFormatter::toString(dprice,6) << "\n"
<< " expected: "
<< DecimalFormatter::toString(cachedPrice1,6) << "\n"
<< " error: "
<< DecimalFormatter::toString(price-cachedPrice1,6)
<< std::endl;
std::cout << " Show cashflow: \n";
std::vector<boost::shared_ptr<CashFlow> > cashflows = bond1.cashflows();
for (Size i=0; i<cashflows.size(); ++i) {
std::cout << cashflows[i]->date() << ": " <<
cashflows[i]->amount() <<"\n";
}
return 0;
} //main
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click_______________________________________________
Quantlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-usersVisit our website at
http://www.ubs.comThis message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail. Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.
E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses. The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission. If
verification is required please request a hard-copy version. This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.