I would like to produce the same results Excel (or OpenOffice) does when
calculating PRICE and YIELD on bonds. I understand that Excel may technically producing an invalid result, but it's something I'd like to replicate nonetheless. I've modified as much of the code below (modified from another list/blog I found) but can't get the same result as OpenOffice. Can anybody see what else could be modified, or what I'd have to do/write to get the same result? (This is to copy the PRICE function) // date set up Calendar calendar = UnitedStates(UnitedStates::GovernmentBond); //Calendar calendar = NullCalendar(); //no difference Date settlementDate(15, February, 2008); // the settlement date must be a business day settlementDate = calendar.adjust(settlementDate); Integer fixingDays = 0; //1; Natural settlementDays = 0; //1 Date evalDate = calendar.advance(settlementDate, -fixingDays, Days); // Evaluation date (TODO: What should this actually be?) Settings::instance().evaluationDate() = evalDate; // bond set up Real faceAmount = 100.0; Real redemption = 100.0; Date issueDate(17, November, 2003); //shouldn't be relevant for clean price Date maturity(15, November, 2010); Real couponRate = 0.05; Real yield = 0.07; //ActualActual dayCounter( ActualActual::Bond ); ActualActual dayCounter; //Actual365Fixed dayCounter; //SimpleDayCounter dayCounter; RelinkableHandle<YieldTermStructure> discountingTermStructure; boost::shared_ptr<YieldTermStructure> flatTermStructure( new FlatForward( settlementDate, yield, dayCounter, Compounded, Semiannual)); discountingTermStructure.linkTo(flatTermStructure); boost::shared_ptr<PricingEngine> bondEngine( new DiscountingBondEngine(discountingTermStructure)); Schedule fixedBondSchedule( issueDate, maturity, Period(Semiannual), calendar, Unadjusted, Unadjusted, DateGeneration::Backward, false); FixedRateBond fixedRateBond( settlementDays, faceAmount, fixedBondSchedule, std::vector<Rate>(1, couponRate), dayCounter, Unadjusted, redemption); fixedRateBond.setPricingEngine(bondEngine); std::cout << "Actual Clean Price: " << std::setprecision (8) << fixedRateBond.cleanPrice() << std::endl; //OpenOffice: PRICE("2008-02-15","2010-11-15",5%,7%,100,2,1) std::cout << "Desire Clean Price: " << std::setprecision(8) << 95.068419616675 << std::endl; -- edA-qa mort-ora-y -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- BigTPoker - Poker fun and games http://BigTPoker.com/ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Sign: Please digitally sign your emails. Encrypt: I'm also happy to receive encrypted mail. ------------------------------------------------------------------------------ What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users signature.asc (270 bytes) Download Attachment |
Free forum by Nabble | Edit this page |