56 QL_FAIL(
"unknown futures type (" << type <<
')');
60 Time DetermineYearFraction(
const Date& earliestDate,
61 const Date& maturityDate,
62 const DayCounter& dayCounter) {
63 return dayCounter.yearFraction(earliestDate, maturityDate,
64 earliestDate, maturityDate);
70 const Date& iborStartDate,
79 CheckDate(iborStartDate, type);
83 calendar.
advance(iborStartDate, lengthInMonths *
Months, convention, endOfMonth);
91 const Date& iborStartDate,
103 const Date& iborStartDate,
104 const Date& iborEndDate,
109 CheckDate(iborStartDate, type);
111 const auto determineMaturityDate =
112 [&iborStartDate, &iborEndDate](
const auto nextDateCalculator) ->
Date {
114 if (iborEndDate ==
Date()) {
121 "end date (" << iborEndDate <<
") must be greater than start date ("
122 << iborStartDate <<
')');
141 QL_FAIL(
"unsupported futures type (" << type <<
')');
151 const Date& iborStartDate,
152 const Date& iborEndDate,
160 const Date& iborStartDate,
161 const ext::shared_ptr<IborIndex>& index,
165 CheckDate(iborStartDate, type);
168 const Calendar& cal = index->fixingCalendar();
170 cal.
advance(iborStartDate, index->tenor(), index->businessDayConvention());
178 const Date& iborStartDate,
179 const ext::shared_ptr<IborIndex>& index,
192 return 100.0 * (1.0 - futureRate);
215 iborIndex_ = ext::make_shared<IborIndex>(
"no-fix",
230 endOfMonth, dayCounter) {}
233 const ext::shared_ptr<IborIndex>& i)
240 const ext::shared_ptr<IborIndex>& i)
253 bool observer =
false;
290 Date customPillarDate,
291 bool useIndexedCoupon)
292 :
FraRateHelper(rate, monthsToStart*
Months, monthsToEnd-monthsToStart, fixingDays, calendar,
293 convention, endOfMonth, dayCounter, pillarChoice, customPillarDate, useIndexedCoupon) {
295 "monthsToEnd (" << monthsToEnd <<
296 ") must be grater than monthsToStart (" << monthsToStart <<
309 Date customPillarDate,
310 bool useIndexedCoupon)
312 convention, endOfMonth, dayCounter, pillarChoice, customPillarDate, useIndexedCoupon) {}
316 const ext::shared_ptr<IborIndex>& i,
318 Date customPillarDate,
319 bool useIndexedCoupon)
320 :
FraRateHelper(rate, monthsToStart*
Months, i, pillarChoice, customPillarDate, useIndexedCoupon)
325 const ext::shared_ptr<IborIndex>& i,
327 Date customPillarDate,
328 bool useIndexedCoupon)
340 Date customPillarDate,
341 bool useIndexedCoupon)
343 pillarChoice_(pillarChoice), useIndexedCoupon_(useIndexedCoupon) {
346 iborIndex_ = ext::make_shared<IborIndex>(
"no-fix",
364 Date customPillarDate,
365 bool useIndexedCoupon)
367 convention, endOfMonth, dayCounter, pillarChoice, customPillarDate, useIndexedCoupon) {}
371 const ext::shared_ptr<IborIndex>& i,
373 Date customPillarDate,
374 bool useIndexedCoupon)
376 pillarChoice_(pillarChoice), useIndexedCoupon_(useIndexedCoupon) {
390 const ext::shared_ptr<IborIndex>& i,
392 Date customPillarDate,
393 bool useIndexedCoupon)
399 const ext::shared_ptr<IborIndex>& i,
401 Date customPillarDate,
402 bool useIndexedCoupon)
404 pillarChoice_(pillarChoice), useIndexedCoupon_(useIndexedCoupon) {
417 const ext::shared_ptr<IborIndex>& i,
419 Date customPillarDate,
420 bool useIndexedCoupon)
422 customPillarDate, useIndexedCoupon) {}
438 bool observer =
false;
449 for (
Size i = 0; i <
n; ++i) {
476 QL_FAIL(
"neither periodToStart nor immOffsetStart/End given");
497 "pillar date (" <<
pillarDate_ <<
") must be later "
498 "than or equal to the instrument's earliest date (" <<
501 "pillar date (" <<
pillarDate_ <<
") must be before "
502 "or equal to the instrument's latest relevant date (" <<
524 const ext::shared_ptr<SwapIndex>& swapIndex,
529 Date customPillarDate,
531 const ext::optional<bool>& useIndexedCoupons)
532 :
SwapRateHelper(rate, swapIndex->tenor(), swapIndex->fixingCalendar(),
533 swapIndex->fixedLegTenor().frequency(), swapIndex->fixedLegConvention(),
534 swapIndex->dayCounter(), swapIndex->iborIndex(),
std::move(spread), fwdStart,
535 std::move(discount),
Null<
Natural>(), pillarChoice, customPillarDate, endOfMonth,
536 useIndexedCoupons) {}
544 const ext::shared_ptr<IborIndex>& iborIndex,
550 Date customPillarDate,
552 const ext::optional<bool>& useIndexedCoupons)
554 pillarChoice_(pillarChoice), calendar_(
std::move(calendar)),
555 fixedConvention_(fixedConvention), fixedFrequency_(fixedFrequency),
556 fixedDayCount_(
std::move(fixedDayCount)), spread_(
std::move(spread)), endOfMonth_(endOfMonth),
557 fwdStart_(fwdStart), discountHandle_(
std::move(discount)),
558 useIndexedCoupons_(useIndexedCoupons) {
576 const ext::shared_ptr<SwapIndex>& swapIndex,
581 Date customPillarDate,
583 const ext::optional<bool>& useIndexedCoupons)
585 std::move(discount), pillarChoice, customPillarDate, endOfMonth, useIndexedCoupons) {}
593 const ext::shared_ptr<IborIndex>& iborIndex,
599 Date customPillarDate,
601 const ext::optional<bool>& useIndexedCoupons)
603 std::move(fixedDayCount), iborIndex,
std::move(spread), fwdStart,
std::move(discount), settlementDays,
604 pillarChoice, customPillarDate, endOfMonth, useIndexedCoupons) {}
630 ext::shared_ptr<IborCoupon> lastCoupon =
631 ext::dynamic_pointer_cast<IborCoupon>(
swap_->floatingLeg().back());
644 "pillar date (" <<
pillarDate_ <<
") must be later "
645 "than or equal to the instrument's earliest date (" <<
648 "pillar date (" <<
pillarDate_ <<
") must be before "
649 "or equal to the instrument's latest relevant date (" <<
663 bool observer =
false;
681 static const Spread basisPoint = 1.0e-4;
682 Real floatingLegNPV =
swap_->floatingLegNPV();
685 Real totNPV = - (floatingLegNPV+spreadNPV);
686 Real result = totNPV/(
swap_->fixedLegBPS()/basisPoint);
706 ext::shared_ptr<BMAIndex> bmaIndex,
708 ext::shared_ptr<IborIndex> iborIndex)
710 calendar_(
std::move(calendar)), bmaPeriod_(bmaPeriod), bmaConvention_(bmaConvention),
711 bmaDayCount_(
std::move(bmaDayCount)), bmaIndex_(
std::move(bmaIndex)),
712 iborIndex_(
std::move(iborIndex)) {
756 swap_->setPricingEngine(ext::shared_ptr<PricingEngine>(
new
761 Date nextWednesday = (w >= 4) ?
762 d + (11 - w) *
Days :
765 clonedIndex->fixingCalendar().adjust(nextWednesday));
771 bool observer =
false;
783 return swap_->fairLiborFraction();
801 bool isFxBaseCurrencyCollateralCurrency,
805 fixingDays_(fixingDays), cal_(
std::move(calendar)), conv_(convention), eom_(endOfMonth),
806 isFxBaseCurrencyCollateralCurrency_(isFxBaseCurrencyCollateralCurrency),
807 collHandle_(
std::move(coll)), tradingCalendar_(
std::move(tradingCalendar)) {
842 Real collRatio = d1 / d2;
845 Real ratio = d1 / d2;
848 return (ratio/collRatio-1)*
spot;
850 return (collRatio/ratio-1)*
spot;
857 bool observer =
false;
ASX-related date functions.
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 Date maturityDate() const
instrument's maturity date
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
Rate helper for bootstrapping over deposit rates.
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)
Discounting engine for swaps.
Rate helper for bootstrapping over FRA rates.
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
Rate helper for bootstrapping over IborIndex futures prices.
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 > &)
Bootstrap helper with date schedule relative to global evaluation date.
Rate helper for bootstrapping over swap rates.
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.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Frequency
Frequency of events.
BusinessDayConvention
Business Day conventions.
Real Time
continuous quantity with 1-year units
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
Coupon paying a Libor-type index.
IMM-related date functions.
Helper class to instantiate standard market swaps.
RelinkableHandle< Quote > makeQuoteHandle(Real value)
void simplifyNotificationGraph(Instrument &instrument, const Leg &leg, bool unregisterCoupons)
Utility function to optimize the observability graph of an instrument.
empty deleter for shared_ptr
Maps optional to either the boost or std implementation.
ext::shared_ptr< BlackVolTermStructure > v
purely virtual base class for market observables
deposit, FRA, futures, and various swap rate helpers
utility functions to reduce number of notifications sent by observables
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