19#include <ql/cashflows/cpicoupon.hpp>
20#include <ql/settings.hpp>
25#include <boost/make_shared.hpp>
30 const Calendar& fixingCalendar,
const QuantLib::ext::shared_ptr<QuantLib::Bond>& bond,
31 const Handle<YieldTermStructure>& discountCurve,
32 const Handle<DefaultProbabilityTermStructure>& defaultCurve,
const Handle<Quote>& recoveryRate,
33 const Handle<Quote>& securitySpread,
const Handle<YieldTermStructure>& incomeCurve,
34 const bool conditionalOnSurvival,
const Date& issueDate,
const PriceQuoteMethod priceQuoteMethod,
35 const double priceQuoteBaseValue,
const bool isInflationLinked,
const double bidAskAdjustment,
36 const bool bondIssueDateFallback)
37 : securityName_(securityName), dirty_(dirty), relative_(relative), fixingCalendar_(fixingCalendar),
bond_(bond),
38 discountCurve_(discountCurve), defaultCurve_(defaultCurve), recoveryRate_(recoveryRate),
39 securitySpread_(securitySpread), incomeCurve_(incomeCurve), conditionalOnSurvival_(conditionalOnSurvival),
40 issueDate_(issueDate), priceQuoteMethod_(priceQuoteMethod), priceQuoteBaseValue_(priceQuoteBaseValue),
41 isInflationLinked_(isInflationLinked), bidAskAdjustment_(bidAskAdjustment),
42 bondIssueDateFallback_(bondIssueDateFallback) {
44 registerWith(Settings::instance().evaluationDate());
67 QL_REQUIRE(
isValidFixingDate(fixingDate),
"Fixing date " << fixingDate <<
" is not valid for '" <<
name() <<
"'");
68 Date today = Settings::instance().evaluationDate();
69 if (fixingDate > today || (fixingDate == today && forecastTodaysFixing))
72 if (fixingDate < today || Settings::instance().enforcesTodaysHistoricFixings()) {
76 QL_REQUIRE(result != Null<Real>(),
"Missing " <<
name() <<
" fixing for " << fixingDate);
82 if (result != Null<Real>())
93 Date today = Settings::instance().evaluationDate();
94 QL_REQUIRE(fixingDate >= today,
95 "BondIndex::forecastFixing(): fixingDate (" << fixingDate <<
") must be >= today (" << today <<
")");
96 QL_REQUIRE(
bond_,
"BondIndex::forecastFixing(): bond required");
100 Real price = Null<Real>();
101 if (fixingDate == today) {
103 price =
bond_->settlementValue();
111 if (price == Null<Real>()) {
113 bond_->settlementDate(fixingDate),
bond_->cashflows(), boost::none,
121 price -=
bond_->accruedAmount(fixingDate) / 100.0 *
bond_->notional(fixingDate);
128 price /=
bond_->notional(fixingDate);
135 QL_REQUIRE(
isValidFixingDate(fixingDate), fixingDate <<
" is not a valid fixing date for '" <<
name() <<
"'");
140 if (price == Null<Real>())
143 QL_REQUIRE(
bond_,
"BondIndex::pastFixing(): bond required for dirty prices");
144 price +=
bond_->accruedAmount(fd) / 100.0;
152 QL_REQUIRE(
bond_,
"BondIndex::pastFixing(): bond required for absolute prices");
153 price *=
bond_->notional(fd);
159 const bool relative,
const Calendar& fixingCalendar,
160 const QuantLib::ext::shared_ptr<QuantLib::Bond>& bond,
161 const Handle<YieldTermStructure>& discountCurve,
162 const Handle<DefaultProbabilityTermStructure>& defaultCurve,
163 const Handle<Quote>& recoveryRate,
const Handle<Quote>& securitySpread,
164 const Handle<YieldTermStructure>& incomeCurve,
const bool conditionalOnSurvival,
165 const Date& issueDate,
const PriceQuoteMethod priceQuoteMethod,
const double priceQuoteBaseValue)
166 :
BondIndex(securityName, dirty, relative, fixingCalendar, bond, discountCurve, defaultCurve, recoveryRate,
167 securitySpread, incomeCurve, conditionalOnSurvival, issueDate, priceQuoteMethod, priceQuoteBaseValue),
168 expiryDate_(expiryDate) {}
172 std::ostringstream o;
183 Date today = Settings::instance().evaluationDate();
184 QL_REQUIRE(fixingDate >= today,
"BondFuturesIndex::forecastFixing(): fixingDate ("
185 << fixingDate <<
") must be >= today (" << today <<
")");
186 QL_REQUIRE(
bond_,
"BondFuturesIndex::forecastFixing(): bond required");
191 Real price = bondNpvResults.npv;
213 QL_REQUIRE(
bond_,
"cannot forecast ConstantMaturityBondIndex fixing, because underlying bond not set");
214 QL_REQUIRE(fixingDate ==
bondStartDate_,
"bond yield fixing only available at bond start date, "
215 << io::iso_date(fixingDate) <<
" != " << io::iso_date(
bondStartDate_));
bond index class representing historical and forward bond prices
std::string name() const override
Rate forecastFixing(const Date &fixingDate) const override
BondFuturesIndex(const QuantLib::Date &expiryDate, const std::string &securityName, const bool dirty=false, const bool relative=true, const Calendar &fixingCalendar=NullCalendar(), const QuantLib::ext::shared_ptr< QuantLib::Bond > &bond=nullptr, const Handle< YieldTermStructure > &discountCurve=Handle< YieldTermStructure >(), const Handle< DefaultProbabilityTermStructure > &defaultCurve=Handle< DefaultProbabilityTermStructure >(), const Handle< Quote > &recoveryRate=Handle< Quote >(), const Handle< Quote > &securitySpread=Handle< Quote >(), const Handle< YieldTermStructure > &incomeCurve=Handle< YieldTermStructure >(), const bool conditionalOnSurvival=true, const Date &issueDate=Date(), const PriceQuoteMethod priceQuoteMethod=PriceQuoteMethod::PercentageOfPar, const double priceQuoteBaseValue=1.0)
BondIndex(const std::string &securityName, const bool dirty=false, const bool relative=true, const Calendar &fixingCalendar=NullCalendar(), const QuantLib::ext::shared_ptr< QuantLib::Bond > &bond=nullptr, const Handle< YieldTermStructure > &discountCurve=Handle< YieldTermStructure >(), const Handle< DefaultProbabilityTermStructure > &defaultCurve=Handle< DefaultProbabilityTermStructure >(), const Handle< Quote > &recoveryRate=Handle< Quote >(), const Handle< Quote > &securitySpread=Handle< Quote >(), const Handle< YieldTermStructure > &incomeCurve=Handle< YieldTermStructure >(), const bool conditionalOnSurvival=true, const Date &issueDate=Date(), const PriceQuoteMethod priceQuoteMethod=PriceQuoteMethod::PercentageOfPar, const double priceQuoteBaseValue=1.0, const bool isInflationLinked=false, const double bidAskAdjustment=0.0, const bool bondIssueDateFallback=false)
const std::string & securityName() const
virtual Rate forecastFixing(const Date &fixingDate) const
bool conditionalOnSurvival_
Handle< YieldTermStructure > discountCurve_
Handle< Quote > recoveryRate() const
double priceQuoteBaseValue_
Handle< YieldTermStructure > incomeCurve_
std::string securityName_
Calendar fixingCalendar() const override
Handle< YieldTermStructure > discountCurve() const
bool conditionalOnSurvival() const
Handle< DefaultProbabilityTermStructure > defaultCurve() const
Handle< YieldTermStructure > incomeCurve() const
bool bondIssueDateFallback_
PriceQuoteMethod priceQuoteMethod_
Rate pastFixing(const Date &fixingDate) const
std::string name() const override
Handle< Quote > securitySpread_
Handle< Quote > securitySpread() const
QuantLib::ext::shared_ptr< QuantLib::Bond > bond() const
Handle< DefaultProbabilityTermStructure > defaultCurve_
bool isValidFixingDate(const Date &fixingDate) const override
QuantLib::ext::shared_ptr< DiscountingRiskyBondEngine > vanillaBondEngine_
QuantLib::ext::shared_ptr< QuantLib::Bond > bond_
Handle< Quote > recoveryRate_
Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
Bond::Price::Type priceType_
Date maturityDate(const Date &valueDate) const override
BusinessDayConvention convention_
ext::shared_ptr< Bond > bond_
Rate forecastFixing(const Date &fixingDate) const override
some inflation related utilities.
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
Real inflationLinkedBondQuoteFactor(const QuantLib::ext::shared_ptr< QuantLib::Bond > &bond)