| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2015 Peter Caspers |
| 5 | |
| 6 | This file is part of QuantLib, a free-software/open-source library |
| 7 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 8 | |
| 9 | QuantLib is free software: you can redistribute it and/or modify it |
| 10 | under the terms of the QuantLib license. You should have received a |
| 11 | copy of the license along with this program; if not, please email |
| 12 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 13 | <http://quantlib.org/license.shtml>. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 17 | FOR A PARTICULAR PURPOSE. See the license for more details. |
| 18 | */ |
| 19 | |
| 20 | #include <ql/cashflows/cashflowvectors.hpp> |
| 21 | #include <ql/experimental/coupons/digitalcmsspreadcoupon.hpp> |
| 22 | #include <utility> |
| 23 | |
| 24 | namespace QuantLib { |
| 25 | |
| 26 | DigitalCmsSpreadCoupon::DigitalCmsSpreadCoupon( |
| 27 | const ext::shared_ptr<CmsSpreadCoupon>& underlying, |
| 28 | Rate callStrike, |
| 29 | Position::Type callPosition, |
| 30 | bool isCallATMIncluded, |
| 31 | Rate callDigitalPayoff, |
| 32 | Rate putStrike, |
| 33 | Position::Type putPosition, |
| 34 | bool isPutATMIncluded, |
| 35 | Rate putDigitalPayoff, |
| 36 | const ext::shared_ptr<DigitalReplication>& replication, |
| 37 | bool nakedOption) |
| 38 | : DigitalCoupon(underlying, callStrike, callPosition, isCallATMIncluded, |
| 39 | callDigitalPayoff, putStrike, putPosition, |
| 40 | isPutATMIncluded, putDigitalPayoff, replication, nakedOption) {} |
| 41 | |
| 42 | void DigitalCmsSpreadCoupon::accept(AcyclicVisitor& v) { |
| 43 | typedef DigitalCoupon super; |
| 44 | auto* v1 = dynamic_cast<Visitor<DigitalCmsSpreadCoupon>*>(&v); |
| 45 | if (v1 != nullptr) |
| 46 | v1->visit(*this); |
| 47 | else |
| 48 | super::accept(v); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | DigitalCmsSpreadLeg::DigitalCmsSpreadLeg(Schedule schedule, |
| 53 | ext::shared_ptr<SwapSpreadIndex> index) |
| 54 | : schedule_(std::move(schedule)), index_(std::move(index)) {} |
| 55 | |
| 56 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withNotionals(Real notional) { |
| 57 | notionals_ = std::vector<Real>(1,notional); |
| 58 | return *this; |
| 59 | } |
| 60 | |
| 61 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withNotionals( |
| 62 | const std::vector<Real>& notionals) { |
| 63 | notionals_ = notionals; |
| 64 | return *this; |
| 65 | } |
| 66 | |
| 67 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPaymentDayCounter( |
| 68 | const DayCounter& dayCounter) { |
| 69 | paymentDayCounter_ = dayCounter; |
| 70 | return *this; |
| 71 | } |
| 72 | |
| 73 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPaymentAdjustment( |
| 74 | BusinessDayConvention convention) { |
| 75 | paymentAdjustment_ = convention; |
| 76 | return *this; |
| 77 | } |
| 78 | |
| 79 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withFixingDays(Natural fixingDays) { |
| 80 | fixingDays_ = std::vector<Natural>(1,fixingDays); |
| 81 | return *this; |
| 82 | } |
| 83 | |
| 84 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withFixingDays( |
| 85 | const std::vector<Natural>& fixingDays) { |
| 86 | fixingDays_ = fixingDays; |
| 87 | return *this; |
| 88 | } |
| 89 | |
| 90 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withGearings(Real gearing) { |
| 91 | gearings_ = std::vector<Real>(1,gearing); |
| 92 | return *this; |
| 93 | } |
| 94 | |
| 95 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withGearings( |
| 96 | const std::vector<Real>& gearings) { |
| 97 | gearings_ = gearings; |
| 98 | return *this; |
| 99 | } |
| 100 | |
| 101 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withSpreads(Spread spread) { |
| 102 | spreads_ = std::vector<Spread>(1,spread); |
| 103 | return *this; |
| 104 | } |
| 105 | |
| 106 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withSpreads( |
| 107 | const std::vector<Spread>& spreads) { |
| 108 | spreads_ = spreads; |
| 109 | return *this; |
| 110 | } |
| 111 | |
| 112 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::inArrears(bool flag) { |
| 113 | inArrears_ = flag; |
| 114 | return *this; |
| 115 | } |
| 116 | |
| 117 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withCallStrikes(Rate strike) { |
| 118 | callStrikes_ = std::vector<Rate>(1,strike); |
| 119 | return *this; |
| 120 | } |
| 121 | |
| 122 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withCallStrikes( |
| 123 | const std::vector<Rate>& strikes) { |
| 124 | callStrikes_ = strikes; |
| 125 | return *this; |
| 126 | } |
| 127 | |
| 128 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withLongCallOption(Position::Type type) { |
| 129 | longCallOption_ = type; |
| 130 | return *this; |
| 131 | } |
| 132 | |
| 133 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withCallATM(bool flag) { |
| 134 | callATM_ = flag; |
| 135 | return *this; |
| 136 | } |
| 137 | |
| 138 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withCallPayoffs(Rate payoff) { |
| 139 | callPayoffs_ = std::vector<Rate>(1,payoff); |
| 140 | return *this; |
| 141 | } |
| 142 | |
| 143 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withCallPayoffs( |
| 144 | const std::vector<Rate>& payoffs) { |
| 145 | callPayoffs_ = payoffs; |
| 146 | return *this; |
| 147 | } |
| 148 | |
| 149 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPutStrikes(Rate strike) { |
| 150 | putStrikes_ = std::vector<Rate>(1,strike); |
| 151 | return *this; |
| 152 | } |
| 153 | |
| 154 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPutStrikes( |
| 155 | const std::vector<Rate>& strikes) { |
| 156 | putStrikes_ = strikes; |
| 157 | return *this; |
| 158 | } |
| 159 | |
| 160 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withLongPutOption(Position::Type type) { |
| 161 | longPutOption_ = type; |
| 162 | return *this; |
| 163 | } |
| 164 | |
| 165 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPutATM(bool flag) { |
| 166 | putATM_ = flag; |
| 167 | return *this; |
| 168 | } |
| 169 | |
| 170 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPutPayoffs(Rate payoff) { |
| 171 | putPayoffs_ = std::vector<Rate>(1,payoff); |
| 172 | return *this; |
| 173 | } |
| 174 | |
| 175 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withPutPayoffs( |
| 176 | const std::vector<Rate>& payoffs) { |
| 177 | putPayoffs_ = payoffs; |
| 178 | return *this; |
| 179 | } |
| 180 | |
| 181 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withReplication( |
| 182 | const ext::shared_ptr<DigitalReplication>& replication) { |
| 183 | replication_ = replication; |
| 184 | return *this; |
| 185 | } |
| 186 | |
| 187 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withReplication() { |
| 188 | replication_ = ext::make_shared<DigitalReplication>(); |
| 189 | return *this; |
| 190 | } |
| 191 | |
| 192 | DigitalCmsSpreadLeg& DigitalCmsSpreadLeg::withNakedOption(bool nakedOption) { |
| 193 | nakedOption_ = nakedOption; |
| 194 | return *this; |
| 195 | } |
| 196 | |
| 197 | DigitalCmsSpreadLeg::operator Leg() const { |
| 198 | return FloatingDigitalLeg<SwapSpreadIndex, CmsSpreadCoupon, DigitalCmsSpreadCoupon>( |
| 199 | schedule: schedule_, nominals: notionals_, index: index_, paymentDayCounter: paymentDayCounter_, |
| 200 | paymentAdj: paymentAdjustment_, fixingDays: fixingDays_, |
| 201 | gearings: gearings_, spreads: spreads_, isInArrears: inArrears_, |
| 202 | callStrikes: callStrikes_, callPosition: longCallOption_, |
| 203 | isCallATMIncluded: callATM_, callDigitalPayoffs: callPayoffs_, |
| 204 | putStrikes: putStrikes_, putPosition: longPutOption_, |
| 205 | isPutATMIncluded: putATM_, putDigitalPayoffs: putPayoffs_, |
| 206 | replication: replication_, nakedOption: nakedOption_); |
| 207 | } |
| 208 | |
| 209 | } |
| 210 | |