This example values a fixed-coupon bond repurchase (repo). The repurchase agreement example is set up to use the repo rate to do all discounting (including the underlying bond income). Forward delivery price is also obtained using this repo rate. All this is done by supplying the FixedCouponBondForward constructor with a flat repo YieldTermStructure.
#if !defined(BOOST_ALL_NO_LIB) && defined(BOOST_MSVC)
#endif
#include <iostream>
#include <iomanip>
int main(int, char* []) {
try {
std::cout << std::endl;
Date repoSettlementDate(14,February,2000);;
Date repoDeliveryDate(15,August,2000);
Date bondIssueDate(15,September,1995);
Date bondDatedDate(15,September,1995);
Date bondMaturityDate(15,September,2005);
Bond::Price bondCleanPrice(89.97693786, Bond::Price::Clean);
Real bondRedemption = 100.0;
Settings::instance().evaluationDate() = repoSettlementDate;
bondCurve.
linkTo(ext::make_shared<FlatForward>(repoSettlementDate,
.01,
bondDayCountConvention,
Compounded,
bondCouponFrequency));
Schedule bondSchedule(bondDatedDate, bondMaturityDate,
bondCalendar,bondBusinessDayConvention,
bondBusinessDayConvention,
DateGeneration::Backward,false);
auto bond = ext::make_shared<FixedRateBond>(bondSettlementDays,
faceAmount,
bondSchedule,
std::vector<Rate>(1,bondCoupon),
bondDayCountConvention,
bondBusinessDayConvention,
bondRedemption,
bondIssueDate);
bond->setPricingEngine(ext::make_shared<DiscountingBondEngine>(bondCurve));
bondCurve.
linkTo(ext::make_shared<FlatForward>(repoSettlementDate,
bond->yield(bondCleanPrice,
bondDayCountConvention,
Compounded,
bondCouponFrequency),
bondDayCountConvention,
Compounded,
bondCouponFrequency));
double dummyStrike = 91.5745;
repoCurve.
linkTo(ext::make_shared<FlatForward>(repoSettlementDate,
repoRate,
repoDayCountConvention,
repoCompounding,
repoCompoundFreq));
BondForward bondFwd(repoSettlementDate, repoDeliveryDate, fwdType, dummyStrike,
repoSettlementDays, repoDayCountConvention, bondCalendar,
bondBusinessDayConvention, bond, repoCurve, repoCurve);
cout << "Underlying bond clean price: "
<< bond->cleanPrice()
<< endl;
cout << "Underlying bond dirty price: "
<< bond->dirtyPrice()
<< endl;
cout << "Underlying bond accrued at settlement: "
<< bond->accruedAmount(repoSettlementDate)
<< endl;
cout << "Underlying bond accrued at delivery: "
<< bond->accruedAmount(repoDeliveryDate)
<< endl;
cout << "Underlying bond spot income: "
<< endl;
cout << "Underlying bond fwd income: "
repoCurve->discount(repoDeliveryDate)
<< endl;
cout << "Repo strike: "
<< dummyStrike
<< endl;
cout << "Repo NPV: "
<< endl;
cout << "Repo clean forward price: "
<< endl;
cout << "Repo dirty forward price: "
<< endl;
cout << "Repo implied yield: "
dummyStrike,
repoSettlementDate,
repoCompounding,
repoDayCountConvention)
<< endl;
cout << "Market repo rate: "
<< repoCurve->zeroRate(repoDeliveryDate,
repoDayCountConvention,
repoCompounding,
repoCompoundFreq)
<< endl
<< endl;
cout << "Compare with example given at \n"
<< "http://www.fincad.com/support/developerFunc/mathref/BFWD.htm"
<< endl;
cout << "Clean forward price = 88.2408"
<< endl
<< endl;
cout << "In that example, it is unknown what bond calendar they are\n"
<< "using, as well as settlement Days. For that reason, I have\n"
<< "made the simplest possible assumptions here: NullCalendar\n"
<< "and 0 settlement days."
<< endl;
return 0;
} catch (exception& e) {
cerr << e.what() << endl;
return 1;
} catch (...) {
cerr << "unknown error" << endl;
return 1;
}
}
forward contract on a bond
Actual/360 day count convention.
Forward contract on a bond
Real forwardPrice() const
(dirty) forward bond price
Real cleanForwardPrice() const
(dirty) forward bond price minus accrued on bond at delivery
Real spotIncome(const Handle< YieldTermStructure > &incomeDiscountCurve) const override
NPV of bond coupons discounted using incomeDiscountCurve.
InterestRate impliedYield(Real underlyingSpotValue, Real forwardValue, Date settlementDate, Compounding compoundingConvention, const DayCounter &dayCounter)
Real NPV() const
returns the net present value of the instrument.
Calendar for reproducing theoretical calculations.
Relinkable handle to an observable.
void linkTo(const ext::shared_ptr< T > &h, bool registerAsObserver=true)
30/360 day count convention
flat forward rate term structure
Frequency
Frequency of events.
BusinessDayConvention
Business Day conventions.
QL_INTEGER Integer
integer number
Compounding
Interest rate coumpounding rule.
Calendar for reproducing theoretical calculations.
Global definitions and compiler switches.