24#include <ql/instruments/makevanillaswap.hpp>
25#include <ql/pricingengines/swap/discountingswapengine.hpp>
26#include <ql/time/daycounters/thirty360.hpp>
27#include <ql/time/daycounters/actual360.hpp>
28#include <ql/time/daycounters/actual365fixed.hpp>
29#include <ql/indexes/iborindex.hpp>
30#include <ql/time/schedule.hpp>
31#include <ql/currencies/america.hpp>
32#include <ql/currencies/asia.hpp>
33#include <ql/currencies/europe.hpp>
34#include <ql/currencies/oceania.hpp>
35#include <ql/utilities/null.hpp>
36#include <ql/optional.hpp>
41 const ext::shared_ptr<IborIndex>& index,
43 const Period& forwardStart)
44 : swapTenor_(swapTenor), iborIndex_(index), fixedRate_(fixedRate), forwardStart_(forwardStart),
45 settlementDays_(
Null<
Natural>()), fixedCalendar_(index->fixingCalendar()),
46 floatCalendar_(index->fixingCalendar()),
48 floatTenor_(index->tenor()),
50 floatConvention_(index->businessDayConvention()),
51 floatTerminationDateConvention_(index->businessDayConvention()),
53 floatDayCount_(index->dayCounter()) {}
56 ext::shared_ptr<VanillaSwap>
swap = *
this;
60 MakeVanillaSwap::operator ext::shared_ptr<VanillaSwap>()
const {
63 if (effectiveDate_ !=
Date())
64 startDate = effectiveDate_;
69 refDate = floatCalendar_.adjust(refDate);
74 spotDate = iborIndex_->valueDate(refDate);
76 spotDate = floatCalendar_.
advance(refDate, settlementDays_ *
Days);
77 startDate = spotDate+forwardStart_;
78 if (forwardStart_.length()<0)
79 startDate = floatCalendar_.adjust(startDate,
81 else if (forwardStart_.length()>0)
82 startDate = floatCalendar_.adjust(startDate,
87 Date endDate = terminationDate_;
88 if (endDate ==
Date()) {
90 endDate = floatCalendar_.
advance(startDate,
95 endDate = startDate + swapTenor_;
98 const Currency& curr = iborIndex_->currency();
100 if (fixedTenor_ !=
Period())
101 fixedTenor = fixedTenor_;
117 QL_FAIL(
"unknown fixed leg default tenor for " << curr);
120 Schedule fixedSchedule(startDate, endDate,
121 fixedTenor, fixedCalendar_,
123 fixedTerminationDateConvention_,
124 fixedRule_, fixedEndOfMonth_,
125 fixedFirstDate_, fixedNextToLastDate_);
127 Schedule floatSchedule(startDate, endDate,
128 floatTenor_, floatCalendar_,
130 floatTerminationDateConvention_,
131 floatRule_, floatEndOfMonth_,
132 floatFirstDate_, floatNextToLastDate_);
136 fixedDayCount = fixedDayCount_;
148 QL_FAIL(
"unknown fixed leg day counter for " << curr);
151 Rate usedFixedRate = fixedRate_;
155 fixedDayCount, floatSchedule, iborIndex_, floatSpread_, floatDayCount_,
157 if (engine_ ==
nullptr) {
159 iborIndex_->forwardingTermStructure();
160 QL_REQUIRE(!disc.
empty(),
161 "null term structure set to this instance of " <<
163 bool includeSettlementDateFlows =
false;
164 ext::shared_ptr<PricingEngine> engine(
new
174 type_, nominal_, fixedSchedule, usedFixedRate, fixedDayCount, floatSchedule, iborIndex_,
175 floatSpread_, floatDayCount_,
ext::nullopt, useIndexedCoupons_));
177 if (engine_ ==
nullptr) {
179 iborIndex_->forwardingTermStructure();
180 bool includeSettlementDateFlows =
false;
181 ext::shared_ptr<PricingEngine> engine(
new
183 swap->setPricingEngine(engine);
185 swap->setPricingEngine(engine_);
232 bool includeSettlementDateFlows =
false;
233 engine_ = ext::shared_ptr<PricingEngine>(
new
239 const ext::shared_ptr<PricingEngine>& engine) {
Actual/360 day count convention.
Actual/365 (Fixed) day count convention.
static Date advance(const Date &d, Integer units, TimeUnit)
Shared handle to an observable.
bool empty() const
checks if the contained shared pointer points to anything
void setPricingEngine(const ext::shared_ptr< PricingEngine > &)
set the pricing engine to be used.
MakeVanillaSwap & receiveFixed(bool flag=true)
MakeVanillaSwap & withFixedLegFirstDate(const Date &d)
MakeVanillaSwap & withEffectiveDate(const Date &)
MakeVanillaSwap & withFixedLegConvention(BusinessDayConvention bdc)
BusinessDayConvention fixedConvention_
MakeVanillaSwap & withFixedLegTerminationDateConvention(BusinessDayConvention bdc)
MakeVanillaSwap & withFloatingLegFirstDate(const Date &d)
MakeVanillaSwap & withFixedLegCalendar(const Calendar &cal)
MakeVanillaSwap & withFloatingLegTerminationDateConvention(BusinessDayConvention bdc)
Date fixedNextToLastDate_
Date floatNextToLastDate_
MakeVanillaSwap & withTerminationDate(const Date &)
MakeVanillaSwap & withAtParCoupons(bool b=true)
MakeVanillaSwap & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountCurve)
DateGeneration::Rule floatRule_
DayCounter fixedDayCount_
MakeVanillaSwap & withIndexedCoupons(const ext::optional< bool > &b=true)
MakeVanillaSwap & withPricingEngine(const ext::shared_ptr< PricingEngine > &engine)
MakeVanillaSwap & withSettlementDays(Natural settlementDays)
MakeVanillaSwap(const Period &swapTenor, const ext::shared_ptr< IborIndex > &iborIndex, Rate fixedRate=Null< Rate >(), const Period &forwardStart=0 *Days)
MakeVanillaSwap & withFixedLegDayCount(const DayCounter &dc)
DayCounter floatDayCount_
MakeVanillaSwap & withFixedLegEndOfMonth(bool flag=true)
MakeVanillaSwap & withFloatingLegDayCount(const DayCounter &dc)
ext::optional< bool > useIndexedCoupons_
BusinessDayConvention floatTerminationDateConvention_
MakeVanillaSwap & withRule(DateGeneration::Rule r)
MakeVanillaSwap & withFloatingLegSpread(Spread sp)
MakeVanillaSwap & withNominal(Real n)
MakeVanillaSwap & withFloatingLegCalendar(const Calendar &cal)
DateGeneration::Rule fixedRule_
ext::shared_ptr< PricingEngine > engine_
BusinessDayConvention fixedTerminationDateConvention_
MakeVanillaSwap & withFloatingLegRule(DateGeneration::Rule r)
MakeVanillaSwap & withFloatingLegTenor(const Period &t)
MakeVanillaSwap & withFixedLegRule(DateGeneration::Rule r)
MakeVanillaSwap & withType(Swap::Type type)
MakeVanillaSwap & withFloatingLegNextToLastDate(const Date &d)
MakeVanillaSwap & withFloatingLegEndOfMonth(bool flag=true)
MakeVanillaSwap & withFloatingLegConvention(BusinessDayConvention bdc)
BusinessDayConvention floatConvention_
MakeVanillaSwap & withFixedLegNextToLastDate(const Date &d)
MakeVanillaSwap & withFixedLegTenor(const Period &t)
template class providing a null value for a given type.
DateProxy & evaluationDate()
the date at which pricing is to be performed.
static Settings & instance()
access to the unique instance
30/360 day count convention
Plain-vanilla swap: fix vs ibor leg.
BusinessDayConvention
Business Day conventions.
unsigned QL_INTEGER Natural
positive integer
Real Spread
spreads on interest rates
const boost::none_t & nullopt
void swap(Array &v, Array &w) noexcept