37 :
Swap(2), type_(fromVanilla.type()),
38 fixedNominal_(
std::vector<
Real>(fromVanilla.fixedLeg().size(),
39 fromVanilla.nominal())),
40 floatingNominal_(
std::vector<
Real>(fromVanilla.floatingLeg().size(),
41 fromVanilla.nominal())),
42 fixedSchedule_(fromVanilla.fixedSchedule()),
43 fixedRate_(
std::vector<
Real>(fromVanilla.fixedLeg().size(),
44 fromVanilla.fixedRate())),
45 fixedDayCount_(fromVanilla.fixedDayCount()),
46 floatingSchedule_(fromVanilla.floatingSchedule()),
47 iborIndex_(fromVanilla.iborIndex()),
48 spread_(
std::vector<
Real>(fromVanilla.floatingLeg().size(), fromVanilla.spread())),
49 gearing_(
std::vector<
Real>(fromVanilla.floatingLeg().size(), 1.0)),
50 singleSpreadAndGearing_(true),
51 floatingDayCount_(fromVanilla.floatingDayCount()),
52 paymentConvention_(fromVanilla.paymentConvention()),
53 intermediateCapitalExchange_(false), finalCapitalExchange_(false) {
59 std::vector<Real> fixedNominal,
60 const std::vector<Real>& floatingNominal,
62 std::vector<Real> fixedRate,
65 ext::shared_ptr<IborIndex> iborIndex,
69 const bool intermediateCapitalExchange,
70 const bool finalCapitalExchange,
71 ext::optional<BusinessDayConvention> paymentConvention)
72 :
Swap(2), type_(type), fixedNominal_(
std::move(fixedNominal)),
73 floatingNominal_(floatingNominal), fixedSchedule_(
std::move(fixedSchedule)),
74 fixedRate_(
std::move(fixedRate)), fixedDayCount_(
std::move(fixedDayCount)),
75 floatingSchedule_(
std::move(floatingSchedule)), iborIndex_(
std::move(iborIndex)),
76 spread_(
std::vector<
Real>(floatingNominal.size(), spread)),
77 gearing_(
std::vector<
Real>(floatingNominal.size(), gearing)), singleSpreadAndGearing_(true),
78 floatingDayCount_(
std::move(floatingDayCount)),
79 intermediateCapitalExchange_(intermediateCapitalExchange),
80 finalCapitalExchange_(finalCapitalExchange) {
90 std::vector<Real> fixedNominal,
91 std::vector<Real> floatingNominal,
93 std::vector<Real> fixedRate,
96 ext::shared_ptr<IborIndex> iborIndex,
97 std::vector<Real> gearing,
98 std::vector<Spread> spread,
100 const bool intermediateCapitalExchange,
101 const bool finalCapitalExchange,
102 ext::optional<BusinessDayConvention> paymentConvention)
103 :
Swap(2), type_(type), fixedNominal_(
std::move(fixedNominal)),
104 floatingNominal_(
std::move(floatingNominal)), fixedSchedule_(
std::move(fixedSchedule)),
105 fixedRate_(
std::move(fixedRate)), fixedDayCount_(
std::move(fixedDayCount)),
106 floatingSchedule_(
std::move(floatingSchedule)), iborIndex_(
std::move(iborIndex)),
107 spread_(
std::move(spread)), gearing_(
std::move(gearing)), singleSpreadAndGearing_(false),
108 floatingDayCount_(
std::move(floatingDayCount)),
109 intermediateCapitalExchange_(intermediateCapitalExchange),
110 finalCapitalExchange_(finalCapitalExchange) {
122 "Fixed nominal size ("
124 <<
") does not match fixed rate size ("
129 <<
") does not match schedule size ("
133 "Floating nominal size ("
135 <<
") does not match schedule size ("
140 <<
") does not match spread size ("
144 "Floating nominal size ("
146 <<
") does not match gearing size (" <<
gearing_.size()
170 for (
Size i = 0; i <
legs_[0].size() - 1; i++) {
172 if (!
close(cap, 0.0)) {
173 auto it1 =
legs_[0].begin();
174 std::advance(it1, i + 1);
176 it1, ext::shared_ptr<CashFlow>(
179 std::advance(it2, i + 1);
182 std::advance(it3, i + 1);
187 for (
Size i = 0; i <
legs_[1].size() - 1; i++) {
189 if (!
close(cap, 0.0)) {
190 auto it1 =
legs_[1].begin();
191 std::advance(it1, i + 1);
193 it1, ext::shared_ptr<CashFlow>(
196 std::advance(it2, i + 1);
204 legs_[0].push_back(ext::shared_ptr<CashFlow>(
213 for (Leg::const_iterator i =
legs_[1].begin(); i <
legs_[1].end(); ++i)
226 QL_FAIL(
"Unknown nonstandard-swap type");
247 std::vector<Date>(fixedCoupons.size());
250 std::vector<bool>(fixedCoupons.size(),
false);
252 for (
Size i = 0; i < fixedCoupons.size(); ++i) {
253 ext::shared_ptr<FixedRateCoupon> coupon =
254 ext::dynamic_pointer_cast<FixedRateCoupon>(fixedCoupons[i]);
255 if (coupon !=
nullptr) {
260 ext::shared_ptr<CashFlow> cashflow =
261 ext::dynamic_pointer_cast<CashFlow>(fixedCoupons[i]);
262 std::vector<Date>::const_iterator j =
266 "nominal redemption on "
268 <<
"has no corresponding coupon");
282 std::vector<Date>(floatingCoupons.size());
284 std::vector<Time>(floatingCoupons.size());
286 std::vector<Spread>(floatingCoupons.size());
290 std::vector<bool>(floatingCoupons.size(),
false);
292 for (
Size i = 0; i < floatingCoupons.size(); ++i) {
293 ext::shared_ptr<IborCoupon> coupon =
294 ext::dynamic_pointer_cast<IborCoupon>(floatingCoupons[i]);
295 if (coupon !=
nullptr) {
309 ext::shared_ptr<CashFlow> cashflow =
310 ext::dynamic_pointer_cast<CashFlow>(floatingCoupons[i]);
311 std::vector<Date>::const_iterator j = std::find(
315 "nominal redemption on "
317 <<
"has no corresponding coupon");
345 "number of fixed leg nominals plus redemption flows "
346 "different from number of payment dates");
348 "number of fixed rates plus redemption flows different from "
349 "number of payment dates");
351 "number of float leg nominals different from number of "
354 "number of fixed start dates different from "
355 "number of fixed payment dates");
357 "number of fixed payment dates different from "
358 "number of fixed coupon amounts");
360 "number of floating start dates different from "
361 "number of floating payment dates");
363 "number of floating fixing dates different from "
364 "number of floating payment dates");
366 "number of floating accrual Times different from "
367 "number of floating payment dates");
369 "number of floating spreads different from "
370 "number of floating payment dates");
372 "number of floating payment dates different from "
373 "number of floating coupon amounts");
Floating rate coupon with additional cap/floor.
Cash-flow analysis functions.
Cash flow vector builders.
helper class building a sequence of fixed rate coupons
FixedRateLeg & withNotionals(Real)
FixedRateLeg & withPaymentAdjustment(BusinessDayConvention)
FixedRateLeg & withCouponRates(Rate, const DayCounter &paymentDayCounter, Compounding comp=Simple, Frequency freq=Annual)
helper class building a sequence of capped/floored ibor-rate coupons
IborLeg & withSpreads(Spread spread)
IborLeg & withPaymentAdjustment(BusinessDayConvention)
IborLeg & withPaymentDayCounter(const DayCounter &)
IborLeg & withNotionals(Real notional)
IborLeg & withGearings(Real gearing)
Arguments for nonstandard swap calculation
std::vector< Date > floatingResetDates
std::vector< Spread > floatingSpreads
std::vector< Real > floatingGearings
ext::shared_ptr< IborIndex > iborIndex
std::vector< Date > floatingFixingDates
std::vector< Date > fixedPayDates
std::vector< bool > floatingIsRedemptionFlow
std::vector< Real > fixedNominal
std::vector< Date > fixedResetDates
std::vector< bool > fixedIsRedemptionFlow
std::vector< Real > floatingNominal
void validate() const override
std::vector< Real > floatingCoupons
std::vector< Real > fixedRate
std::vector< Time > floatingAccrualTimes
std::vector< Real > fixedCoupons
std::vector< Date > floatingPayDates
std::vector< Real > gearing_
DayCounter floatingDayCount_
std::vector< Real > fixedRate_
Schedule floatingSchedule_
BusinessDayConvention paymentConvention() const
std::vector< Real > fixedNominal_
DayCounter fixedDayCount_
const Leg & floatingLeg() const
std::vector< Real > floatingNominal_
ext::shared_ptr< IborIndex > iborIndex_
const bool finalCapitalExchange_
const bool intermediateCapitalExchange_
std::vector< Spread > spread_
const ext::shared_ptr< IborIndex > & iborIndex() const
NonstandardSwap(const FixedVsFloatingSwap &fromVanilla)
void setupArguments(PricingEngine::arguments *args) const override
BusinessDayConvention paymentConvention_
const Leg & fixedLeg() const
void setupExpired() const override
void fetchResults(const PricingEngine::results *) const override
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
BusinessDayConvention businessDayConvention() const
void validate() const override
void setupArguments(PricingEngine::arguments *) const override
void setupExpired() const override
void fetchResults(const PricingEngine::results *) const override
std::vector< Real > payer_
#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)
Real Spread
spreads on interest rates
std::size_t Size
size of a container
Coupon paying a Libor-type index.
base class for Inter-Bank-Offered-Rate indexes
bool close(const Quantity &m1, const Quantity &m2, Size n)
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
vanilla swap but possibly with period dependent nominal and strike
Maps optional to either the boost or std implementation.
ext::shared_ptr< YieldTermStructure > r
Interest-rate term structure.