26#include <ql/cashflows/iborcoupon.hpp>
27#include <ql/currency.hpp>
28#include <ql/indexes/swapindex.hpp>
29#include <ql/instruments/makevanillaswap.hpp>
30#include <ql/instruments/simplifynotificationgraph.hpp>
31#include <ql/pricingengines/swap/discountingswapengine.hpp>
32#include <ql/quote.hpp>
33#include <ql/termstructures/yield/ratehelpers.hpp>
34#include <ql/time/asx.hpp>
35#include <ql/time/calendars/jointcalendar.hpp>
36#include <ql/time/calendars/unitedstates.hpp>
37#include <ql/time/imm.hpp>
38#include <ql/utilities/null_deleter.hpp>
39#include <ql/optional.hpp>
45 const Date& iborStartDate,
57 iborStartDate <<
" is not a valid IMM date");
61 iborStartDate <<
" is not a valid ASX date");
64 QL_FAIL(
"unknown futures type (" <<
Integer(type) <<
")");
68 convention, endOfMonth);
76 const Date& iborStartDate,
90 iborStartDate <<
" is not a valid IMM date");
94 iborStartDate <<
" is not a valid ASX date");
97 QL_FAIL(
"unknown futures type (" <<
Integer(type) <<
")");
101 convention, endOfMonth);
107 const Date& iborStartDate,
108 const Date& iborEndDate,
116 iborStartDate <<
" is not a valid IMM date");
117 if (iborEndDate ==
Date()) {
124 QL_REQUIRE(iborEndDate>iborStartDate,
125 "end date (" << iborEndDate <<
126 ") must be greater than start date (" <<
127 iborStartDate <<
")");
133 iborStartDate <<
" is not a valid ASX date");
134 if (iborEndDate ==
Date()) {
141 QL_REQUIRE(iborEndDate>iborStartDate,
142 "end date (" << iborEndDate <<
143 ") must be greater than start date (" <<
144 iborStartDate <<
")");
149 QL_FAIL(
"unknown futures type (" <<
Integer(type) <<
")");
159 const Date& iborStartDate,
160 const Date& iborEndDate,
170 iborStartDate <<
" is not a valid IMM date");
171 if (iborEndDate ==
Date()) {
178 QL_REQUIRE(iborEndDate>iborStartDate,
179 "end date (" << iborEndDate <<
180 ") must be greater than start date (" <<
181 iborStartDate <<
")");
187 iborStartDate <<
" is not a valid ASX date");
188 if (iborEndDate ==
Date()) {
195 QL_REQUIRE(iborEndDate>iborStartDate,
196 "end date (" << iborEndDate <<
197 ") must be greater than start date (" <<
198 iborStartDate <<
")");
203 QL_FAIL(
"unknown futures type (" <<
Integer(type) <<
")");
211 const Date& iborStartDate,
212 const ext::shared_ptr<IborIndex>& i,
219 iborStartDate <<
" is not a valid IMM date");
223 iborStartDate <<
" is not a valid ASX date");
226 QL_FAIL(
"unknown futures type (" <<
Integer(type) <<
")");
229 const Calendar& cal = i->fixingCalendar();
231 i->businessDayConvention());
240 const Date& iborStartDate,
241 const ext::shared_ptr<IborIndex>& i,
250 iborStartDate <<
" is not a valid IMM date");
254 iborStartDate <<
" is not a valid ASX date");
257 QL_FAIL(
"unknown futures type (" <<
Integer(type) <<
")");
260 const Calendar& cal = i->fixingCalendar();
262 i->businessDayConvention());
276 Rate futureRate = forwardRate + convAdj;
277 return 100.0 * (1.0 - futureRate);
300 iborIndex_ = ext::make_shared<IborIndex>(
"no-fix",
315 iborIndex_ = ext::make_shared<IborIndex>(
"no-fix",
323 const ext::shared_ptr<IborIndex>& i)
330 const ext::shared_ptr<IborIndex>& i)
346 bool observer =
false;
348 ext::shared_ptr<YieldTermStructure> temp(t,
null_deleter());
383 Date customPillarDate,
384 bool useIndexedCoupon)
386 pillarChoice_(pillarChoice), useIndexedCoupon_(useIndexedCoupon) {
387 QL_REQUIRE(monthsToEnd>monthsToStart,
388 "monthsToEnd (" << monthsToEnd <<
389 ") must be grater than monthsToStart (" << monthsToStart <<
393 iborIndex_ = ext::make_shared<IborIndex>(
"no-fix",
394 (monthsToEnd-monthsToStart)*
Months,
411 Date customPillarDate,
412 bool useIndexedCoupon)
414 pillarChoice_(pillarChoice), useIndexedCoupon_(useIndexedCoupon) {
415 QL_REQUIRE(monthsToEnd>monthsToStart,
416 "monthsToEnd (" << monthsToEnd <<
417 ") must be grater than monthsToStart (" << monthsToStart <<
421 iborIndex_ = ext::make_shared<IborIndex>(
"no-fix",
422 (monthsToEnd-monthsToStart)*
Months,
432 const ext::shared_ptr<IborIndex>& i,
434 Date customPillarDate,
435 bool useIndexedCoupon)
437 pillarChoice_(pillarChoice), useIndexedCoupon_(useIndexedCoupon) {
451 const ext::shared_ptr<IborIndex>& i,
453 Date customPillarDate,
454 bool useIndexedCoupon)
456 pillarChoice_(pillarChoice), useIndexedCoupon_(useIndexedCoupon) {
475 Date customPillarDate,
476 bool useIndexedCoupon)
478 pillarChoice_(pillarChoice), useIndexedCoupon_(useIndexedCoupon) {
481 iborIndex_ = ext::make_shared<IborIndex>(
"no-fix",
499 Date customPillarDate,
500 bool useIndexedCoupon)
502 pillarChoice_(pillarChoice), useIndexedCoupon_(useIndexedCoupon) {
505 iborIndex_ = ext::make_shared<IborIndex>(
"no-fix",
516 const ext::shared_ptr<IborIndex>& i,
518 Date customPillarDate,
519 bool useIndexedCoupon)
521 pillarChoice_(pillarChoice), useIndexedCoupon_(useIndexedCoupon) {
533 const ext::shared_ptr<IborIndex>& i,
535 Date customPillarDate,
536 bool useIndexedCoupon)
538 pillarChoice_(pillarChoice), useIndexedCoupon_(useIndexedCoupon) {
551 const ext::shared_ptr<IborIndex>& i,
553 Date customPillarDate,
554 bool useIndexedCoupon)
556 pillarChoice_(pillarChoice), useIndexedCoupon_(useIndexedCoupon) {
569 const ext::shared_ptr<IborIndex>& i,
571 Date customPillarDate,
572 bool useIndexedCoupon)
574 pillarChoice_(pillarChoice), useIndexedCoupon_(useIndexedCoupon) {
598 bool observer =
false;
600 ext::shared_ptr<YieldTermStructure> temp(t,
null_deleter());
609 for (
Size i = 0; i < n; ++i) {
636 QL_FAIL(
"neither periodToStart nor immOffsetStart/End given");
657 "pillar date (" <<
pillarDate_ <<
") must be later "
658 "than or equal to the instrument's earliest date (" <<
661 "pillar date (" <<
pillarDate_ <<
") must be before "
662 "or equal to the instrument's latest relevant date (" <<
684 const ext::shared_ptr<SwapIndex>& swapIndex,
689 Date customPillarDate,
691 const ext::optional<bool>& useIndexedCoupons)
693 pillarChoice_(pillarChoice), calendar_(swapIndex->fixingCalendar()),
694 fixedConvention_(swapIndex->fixedLegConvention()),
695 fixedFrequency_(swapIndex->fixedLegTenor().frequency()),
696 fixedDayCount_(swapIndex->dayCounter()), spread_(
std::move(spread)), endOfMonth_(endOfMonth),
697 fwdStart_(fwdStart), discountHandle_(
std::move(discount)), useIndexedCoupons_(useIndexedCoupons) {
719 const ext::shared_ptr<IborIndex>& iborIndex,
725 Date customPillarDate,
727 const ext::optional<bool>& useIndexedCoupons)
729 pillarChoice_(pillarChoice), calendar_(
std::move(calendar)),
730 fixedConvention_(fixedConvention), fixedFrequency_(fixedFrequency),
731 fixedDayCount_(
std::move(fixedDayCount)), spread_(
std::move(spread)), endOfMonth_(endOfMonth),
732 fwdStart_(fwdStart), discountHandle_(
std::move(discount)),
733 useIndexedCoupons_(useIndexedCoupons) {
751 const ext::shared_ptr<SwapIndex>& swapIndex,
756 Date customPillarDate,
758 const ext::optional<bool>& useIndexedCoupons)
760 pillarChoice_(pillarChoice), calendar_(swapIndex->fixingCalendar()),
761 fixedConvention_(swapIndex->fixedLegConvention()),
762 fixedFrequency_(swapIndex->fixedLegTenor().frequency()),
763 fixedDayCount_(swapIndex->dayCounter()), spread_(
std::move(spread)), endOfMonth_(endOfMonth),
764 fwdStart_(fwdStart), discountHandle_(
std::move(discount)),
765 useIndexedCoupons_(useIndexedCoupons) {
787 const ext::shared_ptr<IborIndex>& iborIndex,
793 Date customPillarDate,
795 const ext::optional<bool>& useIndexedCoupons)
797 pillarChoice_(pillarChoice), calendar_(
std::move(calendar)),
798 fixedConvention_(fixedConvention), fixedFrequency_(fixedFrequency),
799 fixedDayCount_(
std::move(fixedDayCount)), spread_(
std::move(spread)), endOfMonth_(endOfMonth),
800 fwdStart_(fwdStart), discountHandle_(
std::move(discount)),
801 useIndexedCoupons_(useIndexedCoupons) {
842 ext::shared_ptr<IborCoupon> lastCoupon =
843 ext::dynamic_pointer_cast<IborCoupon>(
swap_->floatingLeg().back());
856 "pillar date (" <<
pillarDate_ <<
") must be later "
857 "than or equal to the instrument's earliest date (" <<
860 "pillar date (" <<
pillarDate_ <<
") must be before "
861 "or equal to the instrument's latest relevant date (" <<
875 bool observer =
false;
877 ext::shared_ptr<YieldTermStructure> temp(t,
null_deleter());
893 static const Spread basisPoint = 1.0e-4;
894 Real floatingLegNPV =
swap_->floatingLegNPV();
897 Real totNPV = - (floatingLegNPV+spreadNPV);
898 Real result = totNPV/(
swap_->fixedLegBPS()/basisPoint);
918 ext::shared_ptr<BMAIndex> bmaIndex,
920 ext::shared_ptr<IborIndex> iborIndex)
922 calendar_(
std::move(calendar)), bmaPeriod_(bmaPeriod), bmaConvention_(bmaConvention),
923 bmaDayCount_(
std::move(bmaDayCount)), bmaIndex_(
std::move(bmaIndex)),
924 iborIndex_(
std::move(iborIndex)) {
968 swap_->setPricingEngine(ext::shared_ptr<PricingEngine>(
new
973 Date nextWednesday = (w >= 4) ?
974 d + (11 - w) *
Days :
977 clonedIndex->fixingCalendar().adjust(nextWednesday));
983 bool observer =
false;
985 ext::shared_ptr<YieldTermStructure> temp(t,
null_deleter());
995 return swap_->fairLiborFraction();
1013 bool isFxBaseCurrencyCollateralCurrency,
1017 fixingDays_(fixingDays), cal_(
std::move(calendar)), conv_(convention), eom_(endOfMonth),
1018 isFxBaseCurrencyCollateralCurrency_(isFxBaseCurrencyCollateralCurrency),
1019 collHandle_(
std::move(coll)), tradingCalendar_(
std::move(tradingCalendar)) {
1050 QL_REQUIRE(!
collHandle_.empty(),
"collateral term structure not set");
1054 Real collRatio = d1 / d2;
1057 Real ratio = d1 / d2;
1060 return (ratio/collRatio-1)*
spot;
1062 return (collRatio/ratio-1)*
spot;
1069 bool observer =
false;
1071 ext::shared_ptr<YieldTermStructure> temp(t,
null_deleter());
degenerate base class for the Acyclic Visitor pattern
Bond Market Association index.
void setTermStructure(YieldTermStructure *) override
RelinkableHandle< YieldTermStructure > termStructureHandle_
ext::shared_ptr< IborIndex > iborIndex_
void accept(AcyclicVisitor &) override
void initializeDates() override
ext::shared_ptr< BMAIndex > bmaIndex_
Real impliedQuote() const override
BusinessDayConvention bmaConvention_
BMASwapRateHelper(const Handle< Quote > &liborFraction, const Period &tenor, Natural settlementDays, Calendar calendar, const Period &bmaPeriod, BusinessDayConvention bmaConvention, DayCounter bmaDayCount, ext::shared_ptr< BMAIndex > bmaIndex, ext::shared_ptr< IborIndex > index)
ext::shared_ptr< BMASwap > swap_
Base helper class for bootstrapping.
virtual void accept(AcyclicVisitor &)
virtual void setTermStructure(TS *)
sets the term structure to be used for pricing
bool empty() const
Returns whether or not the calendar is initialized.
Date adjust(const Date &, BusinessDayConvention convention=Following) const
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
void setTermStructure(YieldTermStructure *) override
RelinkableHandle< YieldTermStructure > termStructureHandle_
ext::shared_ptr< IborIndex > iborIndex_
void accept(AcyclicVisitor &) override
void initializeDates() override
Real impliedQuote() const override
DepositRateHelper(const Handle< Quote > &rate, const Period &tenor, Natural fixingDays, const Calendar &calendar, BusinessDayConvention convention, bool endOfMonth, const DayCounter &dayCounter)
ext::optional< Natural > immOffsetEnd_
void setTermStructure(YieldTermStructure *) override
ext::optional< Natural > immOffsetStart_
RelinkableHandle< YieldTermStructure > termStructureHandle_
Pillar::Choice pillarChoice_
ext::shared_ptr< IborIndex > iborIndex_
ext::optional< Period > periodToStart_
void accept(AcyclicVisitor &) override
FraRateHelper(const Handle< Quote > &rate, Natural monthsToStart, Natural monthsToEnd, Natural fixingDays, const Calendar &calendar, BusinessDayConvention convention, bool endOfMonth, const DayCounter &dayCounter, Pillar::Choice pillar=Pillar::LastRelevantDate, Date customPillarDate=Date(), bool useIndexedCoupon=true)
void initializeDates() override
Real impliedQuote() const override
void accept(AcyclicVisitor &) override
Real impliedQuote() const override
Real convexityAdjustment() const
FuturesRateHelper(const Handle< Quote > &price, const Date &iborStartDate, Natural lengthInMonths, const Calendar &calendar, BusinessDayConvention convention, bool endOfMonth, const DayCounter &dayCounter, Handle< Quote > convexityAdjustment={}, Futures::Type type=Futures::IMM)
void setTermStructure(YieldTermStructure *) override
RelinkableHandle< YieldTermStructure > termStructureHandle_
Calendar tradingCalendar_
void accept(AcyclicVisitor &) override
RelinkableHandle< YieldTermStructure > collRelinkableHandle_
Handle< YieldTermStructure > collHandle_
void initializeDates() override
BusinessDayConvention conv_
bool isFxBaseCurrencyCollateralCurrency_
Real impliedQuote() const override
FxSwapRateHelper(const Handle< Quote > &fwdPoint, Handle< Quote > spotFx, const Period &tenor, Natural fixingDays, Calendar calendar, BusinessDayConvention convention, bool endOfMonth, bool isFxBaseCurrencyCollateralCurrency, Handle< YieldTermStructure > collateralCurve, Calendar tradingCalendar=Calendar())
Shared handle to an observable.
MakeSchedule & withConvention(BusinessDayConvention)
MakeSchedule & backwards()
MakeSchedule & to(const Date &terminationDate)
MakeSchedule & withTenor(const Period &)
MakeSchedule & from(const Date &effectiveDate)
MakeSchedule & endOfMonth(bool flag=true)
MakeSchedule & withCalendar(const Calendar &)
MakeVanillaSwap & withFixedLegConvention(BusinessDayConvention bdc)
MakeVanillaSwap & withFixedLegTerminationDateConvention(BusinessDayConvention bdc)
MakeVanillaSwap & withFixedLegCalendar(const Calendar &cal)
MakeVanillaSwap & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountCurve)
MakeVanillaSwap & withIndexedCoupons(const ext::optional< bool > &b=true)
MakeVanillaSwap & withSettlementDays(Natural settlementDays)
MakeVanillaSwap & withFixedLegDayCount(const DayCounter &dc)
MakeVanillaSwap & withFixedLegEndOfMonth(bool flag=true)
MakeVanillaSwap & withFloatingLegCalendar(const Calendar &cal)
MakeVanillaSwap & withFloatingLegEndOfMonth(bool flag=true)
MakeVanillaSwap & withFixedLegTenor(const Period &t)
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
purely virtual base class for market observables
Bootstrap helper with date schedule relative to global evaluation date.
market element returning a stored value
RelinkableHandle< YieldTermStructure > discountRelinkableHandle_
void setTermStructure(YieldTermStructure *) override
BusinessDayConvention fixedConvention_
RelinkableHandle< YieldTermStructure > termStructureHandle_
ext::shared_ptr< VanillaSwap > swap_
Pillar::Choice pillarChoice_
DayCounter fixedDayCount_
Handle< YieldTermStructure > discountHandle_
ext::shared_ptr< IborIndex > iborIndex_
ext::optional< bool > useIndexedCoupons_
void accept(AcyclicVisitor &) override
SwapRateHelper(const Handle< Quote > &rate, const ext::shared_ptr< SwapIndex > &swapIndex, Handle< Quote > spread={}, const Period &fwdStart=0 *Days, Handle< YieldTermStructure > discountingCurve={}, Pillar::Choice pillar=Pillar::LastRelevantDate, Date customPillarDate=Date(), bool endOfMonth=false, const ext::optional< bool > &useIndexedCoupons=ext::nullopt)
Frequency fixedFrequency_
void initializeDates() override
Real impliedQuote() const override
Visitor for a specific class
virtual void visit(T &)=0
Interest-rate term structure.
Frequency
Frequency of events.
BusinessDayConvention
Business Day conventions.
Real DiscountFactor
discount factor between dates
unsigned QL_INTEGER Natural
positive integer
QL_INTEGER Integer
integer number
Real Spread
spreads on interest rates
std::size_t Size
size of a container
void simplifyNotificationGraph(Instrument &instrument, const Leg &leg, bool unregisterCoupons)
Utility function to optimize the observability graph of an instrument.
static Date nextDate(const Date &d=Date(), bool mainCycle=true)
next ASX date following the given date
static bool isASXdate(const Date &d, bool mainCycle=true)
returns whether or not the given date is an ASX date
Type
Futures type enumeration.
static bool isIMMdate(const Date &d, bool mainCycle=true)
returns whether or not the given date is an IMM date
static Date nextDate(const Date &d=Date(), bool mainCycle=true)
next IMM date following the given date
Choice
Enumeration for pillar determination alternatives.
@ CustomDate
last date relevant for instrument pricing
@ LastRelevantDate
instruments maturity date