/src/quantlib/ql/instruments/vanillaswap.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl |
5 | | Copyright (C) 2003, 2004, 2005, 2006, 2007 StatPro Italia srl |
6 | | Copyright (C) 2007 Ferdinando Ametrano |
7 | | |
8 | | This file is part of QuantLib, a free-software/open-source library |
9 | | for financial quantitative analysts and developers - http://quantlib.org/ |
10 | | |
11 | | QuantLib is free software: you can redistribute it and/or modify it |
12 | | under the terms of the QuantLib license. You should have received a |
13 | | copy of the license along with this program; if not, please email |
14 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
15 | | <https://www.quantlib.org/license.shtml>. |
16 | | |
17 | | This program is distributed in the hope that it will be useful, but WITHOUT |
18 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
19 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
20 | | */ |
21 | | |
22 | | #include <ql/cashflows/iborcoupon.hpp> |
23 | | #include <ql/indexes/iborindex.hpp> |
24 | | #include <ql/instruments/vanillaswap.hpp> |
25 | | #include <ql/termstructures/yieldtermstructure.hpp> |
26 | | #include <utility> |
27 | | |
28 | | namespace QuantLib { |
29 | | |
30 | | VanillaSwap::VanillaSwap(Type type, |
31 | | Real nominal, |
32 | | Schedule fixedSchedule, |
33 | | Rate fixedRate, |
34 | | DayCounter fixedDayCount, |
35 | | Schedule floatSchedule, |
36 | | ext::shared_ptr<IborIndex> index, |
37 | | Spread spread, |
38 | | DayCounter floatingDayCount, |
39 | | ext::optional<BusinessDayConvention> paymentConvention, |
40 | | ext::optional<bool> useIndexedCoupons) |
41 | 0 | : FixedVsFloatingSwap(type, {nominal}, std::move(fixedSchedule), fixedRate, std::move(fixedDayCount), |
42 | 0 | {nominal}, std::move(floatSchedule), std::move(index), spread, std::move(floatingDayCount), |
43 | 0 | paymentConvention) { |
44 | |
|
45 | 0 | legs_[1] = IborLeg(floatingSchedule(), iborIndex()) |
46 | 0 | .withNotionals(this->floatingNominals()) |
47 | 0 | .withPaymentDayCounter(this->floatingDayCount()) |
48 | 0 | .withPaymentAdjustment(this->paymentConvention()) |
49 | 0 | .withSpreads(this->spread()) |
50 | 0 | .withIndexedCoupons(useIndexedCoupons); |
51 | 0 | for (const auto& c : legs_[1]) |
52 | 0 | registerWith(c); |
53 | 0 | } Unexecuted instantiation: QuantLib::VanillaSwap::VanillaSwap(QuantLib::Swap::Type, double, QuantLib::Schedule, double, QuantLib::DayCounter, QuantLib::Schedule, boost::shared_ptr<QuantLib::IborIndex>, double, QuantLib::DayCounter, std::__1::optional<QuantLib::BusinessDayConvention>, std::__1::optional<bool>) Unexecuted instantiation: QuantLib::VanillaSwap::VanillaSwap(QuantLib::Swap::Type, double, QuantLib::Schedule, double, QuantLib::DayCounter, QuantLib::Schedule, boost::shared_ptr<QuantLib::IborIndex>, double, QuantLib::DayCounter, std::__1::optional<QuantLib::BusinessDayConvention>, std::__1::optional<bool>) |
54 | | |
55 | 0 | void VanillaSwap::setupFloatingArguments(arguments* args) const { |
56 | 0 | const Leg& floatingCoupons = floatingLeg(); |
57 | 0 | Size n = floatingCoupons.size(); |
58 | |
|
59 | 0 | args->floatingResetDates = args->floatingPayDates = args->floatingFixingDates = std::vector<Date>(n); |
60 | 0 | args->floatingAccrualTimes = std::vector<Time>(n); |
61 | 0 | args->floatingSpreads = std::vector<Spread>(n); |
62 | 0 | args->floatingCoupons = args->floatingNominals = std::vector<Real>(n); |
63 | |
|
64 | 0 | for (Size i=0; i<n; ++i) { |
65 | 0 | auto coupon = ext::dynamic_pointer_cast<IborCoupon>(floatingCoupons[i]); |
66 | |
|
67 | 0 | args->floatingResetDates[i] = coupon->accrualStartDate(); |
68 | 0 | args->floatingPayDates[i] = coupon->date(); |
69 | 0 | args->floatingNominals[i] = coupon->nominal(); |
70 | |
|
71 | 0 | args->floatingFixingDates[i] = coupon->fixingDate(); |
72 | 0 | args->floatingAccrualTimes[i] = coupon->accrualPeriod(); |
73 | 0 | args->floatingSpreads[i] = coupon->spread(); |
74 | 0 | try { |
75 | 0 | args->floatingCoupons[i] = coupon->amount(); |
76 | 0 | } catch (Error&) { |
77 | 0 | args->floatingCoupons[i] = Null<Real>(); |
78 | 0 | } |
79 | 0 | } |
80 | 0 | } |
81 | | |
82 | | } |