19#include <ql/cashflows/fixedratecoupon.hpp>
20#include <ql/time/schedule.hpp>
21#include <ql/pricingengines/swap/discountingswapengine.hpp>
24#include <ql/currencies/america.hpp>
25#include <ql/currencies/asia.hpp>
26#include <ql/currencies/europe.hpp>
27#include <ql/currencies/oceania.hpp>
28#include <ql/time/daycounters/thirty360.hpp>
29#include <ql/time/daycounters/actual360.hpp>
30#include <ql/time/daycounters/actual365fixed.hpp>
37 const Period& fixedTenor, Rate fixedRate,
const Calendar& fixedCalendar,
38 const DayCounter& fixedDayCount, BusinessDayConvention fixedConvention,
39 const Period& floatPayTenor,
const QuantLib::ext::shared_ptr<IborIndex>& iborIndex,
40 const DayCounter& floatingDayCount, DateGeneration::Rule rule,
43 : Swap(2), nominal_(nominal), isPayer_(isPayer), fixedRate_(fixedRate), fixedDayCount_(fixedDayCount),
44 floatIndex_(iborIndex), floatDayCount_(floatingDayCount), floatPayTenor_(floatPayTenor), type_(type) {
46 Date terminationDate = effectiveDate + swapTenor;
52 .withTenor(fixedTenor)
53 .withCalendar(fixedCalendar)
54 .withConvention(fixedConvention)
55 .withTerminationDateConvention(fixedConvention)
61 .withPaymentAdjustment(fixedConvention);
64 BusinessDayConvention floatPmtConvention = iborIndex->businessDayConvention();
65 Calendar floatPmtCalendar = iborIndex->fixingCalendar();
70 .withCalendar(floatPmtCalendar)
71 .withConvention(floatPmtConvention)
72 .withTerminationDateConvention(floatPmtConvention)
88 Leg::const_iterator it;
89 for (it = legs_[0].begin(); it != legs_[0].end(); ++it)
91 for (it = legs_[1].begin(); it != legs_[1].end(); ++it)
96 static const Spread basisPoint = 1.0e-4;
98 QL_REQUIRE(legBPS_[0] != Null<Real>(),
"result not available");
99 return fixedRate_ - NPV_ / (legBPS_[0] / basisPoint);
104 const Period& floatPayTenor,
const Period& forwardStart)
105 : swapTenor_(swapTenor), index_(index), fixedRate_(fixedRate), floatPayTenor_(floatPayTenor), forwardStart_(forwardStart),
106 nominal_(1.0), isPayer_(true), settlementDays_(index->fixingDays()), fixedCalendar_(index->fixingCalendar()),
107 fixedConvention_(ModifiedFollowing), fixedRule_(DateGeneration::Backward), floatDayCounter_(index->dayCounter()),
111 QuantLib::ext::shared_ptr<SubPeriodsSwap> swap = *
this;
115MakeSubPeriodsSwap::operator QuantLib::ext::shared_ptr<SubPeriodsSwap>()
const {
120 if (effectiveDate_ != Date())
121 startDate = effectiveDate_;
123 Date refDate = Settings::instance().evaluationDate();
126 refDate = index_->fixingCalendar().adjust(refDate);
127 Date spotDate = index_->fixingCalendar().advance(refDate, settlementDays_ * Days);
128 startDate = spotDate + forwardStart_;
129 if (forwardStart_.length() < 0)
130 startDate = index_->fixingCalendar().adjust(startDate, Preceding);
132 startDate = index_->fixingCalendar().adjust(startDate, Following);
136 const Currency& curr = index_->currency();
138 if (fixedTenor_ != Period())
139 fixedTenor = fixedTenor_;
141 if ((curr == EURCurrency()) ||
142 (curr == USDCurrency()) ||
143 (curr == CHFCurrency()) ||
144 (curr == SEKCurrency()) ||
145 (curr == GBPCurrency() && swapTenor_ <= 1 * Years))
146 fixedTenor = Period(1, Years);
147 else if ((curr == GBPCurrency() && swapTenor_ > 1 * Years) ||
148 (curr == JPYCurrency()) ||
149 (curr == AUDCurrency() && swapTenor_ >= 4 * Years))
150 fixedTenor = Period(6, Months);
151 else if ((curr == HKDCurrency() ||
152 (curr == AUDCurrency() && swapTenor_ < 4 * Years)))
153 fixedTenor = Period(3, Months);
155 QL_FAIL(
"unknown fixed leg default tenor for " << curr);
159 DayCounter fixedDayCount;
160 if (fixedDayCount_ != DayCounter())
161 fixedDayCount = fixedDayCount_;
163 if (curr == USDCurrency())
164 fixedDayCount = Actual360();
165 else if (curr == EURCurrency() || curr == CHFCurrency() ||
166 curr == SEKCurrency())
167 fixedDayCount = Thirty360(Thirty360::BondBasis);
168 else if (curr == GBPCurrency() || curr == JPYCurrency() ||
169 curr == AUDCurrency() || curr == HKDCurrency() ||
170 curr == THBCurrency())
171 fixedDayCount = Actual365Fixed();
173 QL_FAIL(
"unknown fixed leg day counter for " << curr);
176 QuantLib::ext::shared_ptr<SubPeriodsSwap> swap(
new SubPeriodsSwap(startDate, nominal_, swapTenor_, isPayer_,
177 fixedTenor, fixedRate_, fixedCalendar_, fixedDayCount, fixedConvention_, floatPayTenor_, index_,
178 floatDayCounter_, fixedRule_, subCouponsType_));
181 swap->setPricingEngine(
engine_);
238 bool includeSettlementDateFlows =
false;
239 engine_ = QuantLib::ext::shared_ptr<PricingEngine>(
new DiscountingSwapEngine(d, includeSettlementDateFlows));
QuantLib::ext::shared_ptr< PricingEngine > engine_
MakeSubPeriodsSwap & withFixedLegTenor(const Period &t)
MakeSubPeriodsSwap & withNominal(Real n)
MakeSubPeriodsSwap & withSettlementDays(Natural settlementDays)
BusinessDayConvention fixedConvention_
QuantExt::SubPeriodsCoupon1::Type subCouponsType_
DayCounter fixedDayCount_
MakeSubPeriodsSwap & withEffectiveDate(const Date &)
MakeSubPeriodsSwap & withFixedLegConvention(BusinessDayConvention bdc)
MakeSubPeriodsSwap & withFixedLegRule(DateGeneration::Rule r)
MakeSubPeriodsSwap & withIsPayer(bool p)
QuantLib::ext::shared_ptr< PricingEngine > engine_
DateGeneration::Rule fixedRule_
MakeSubPeriodsSwap & withSubCouponsType(const QuantExt::SubPeriodsCoupon1::Type &st)
MakeSubPeriodsSwap & withPricingEngine(const QuantLib::ext::shared_ptr< PricingEngine > &engine)
MakeSubPeriodsSwap(const Period &swapTenor, const QuantLib::ext::shared_ptr< IborIndex > &index, Rate fixedRate, const Period &floatPayTenor, const Period &forwardStart=0 *Days)
MakeSubPeriodsSwap & withFixedLegDayCount(const DayCounter &dc)
MakeSubPeriodsSwap & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountCurve)
MakeSubPeriodsSwap & withFixedLegCalendar(const Calendar &cal)
helper class building a sequence of sub-period coupons
SubPeriodsLeg1 & withPaymentDayCounter(const DayCounter &dayCounter)
SubPeriodsLeg1 & withType(SubPeriodsCoupon1::Type type)
SubPeriodsLeg1 & includeSpread(bool includeSpread)
SubPeriodsLeg1 & withPaymentCalendar(const Calendar &calendar)
SubPeriodsLeg1 & withNotional(Real notional)
SubPeriodsLeg1 & withPaymentAdjustment(BusinessDayConvention convention)
Single currency sub periods swap.
SubPeriodsSwap(const Date &effectiveDate, Real nominal, const Period &swapTenor, bool isPayer, const Period &fixedTenor, Rate fixedRate, const Calendar &fixedCalendar, const DayCounter &fixedDayCount, BusinessDayConvention fixedConvention, const Period &floatPayTenor, const QuantLib::ext::shared_ptr< IborIndex > &iborIndex, const DayCounter &floatingDayCount, DateGeneration::Rule rule=DateGeneration::Backward, QuantExt::SubPeriodsCoupon1::Type type=QuantExt::SubPeriodsCoupon1::Compounding)
Constructor with conventions deduced from the index.
QuantLib::ext::shared_ptr< IborIndex > floatIndex_
DayCounter fixedDayCount_
const Period & floatPayTenor() const
DayCounter floatDayCount_
QuantExt::SubPeriodsCoupon1::Type type_
Coupon with a number of sub-periods.
Single currency sub periods swap instrument.