| 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 | /*! \file digitalcmsspreadcoupon.hpp |
| 21 | \brief Cms-spread-rate coupon with digital call/put option |
| 22 | */ |
| 23 | |
| 24 | #ifndef quantlib_digital_cmsspread_coupon_hpp |
| 25 | #define quantlib_digital_cmsspread_coupon_hpp |
| 26 | |
| 27 | #include <ql/cashflows/digitalcoupon.hpp> |
| 28 | #include <ql/experimental/coupons/cmsspreadcoupon.hpp> |
| 29 | #include <ql/time/schedule.hpp> |
| 30 | |
| 31 | namespace QuantLib { |
| 32 | |
| 33 | //! Cms-spread-rate coupon with digital digital call/put option |
| 34 | class DigitalCmsSpreadCoupon : public DigitalCoupon { |
| 35 | public: |
| 36 | explicit DigitalCmsSpreadCoupon( |
| 37 | const ext::shared_ptr<CmsSpreadCoupon> &underlying, |
| 38 | Rate callStrike = Null<Rate>(), |
| 39 | Position::Type callPosition = Position::Long, |
| 40 | bool isCallATMIncluded = false, |
| 41 | Rate callDigitalPayoff = Null<Rate>(), |
| 42 | Rate putStrike = Null<Rate>(), |
| 43 | Position::Type putPosition = Position::Long, |
| 44 | bool isPutATMIncluded = false, |
| 45 | Rate putDigitalPayoff = Null<Rate>(), |
| 46 | const ext::shared_ptr<DigitalReplication> &replication = {}, |
| 47 | bool nakedOption = false); |
| 48 | |
| 49 | //! \name Visitability |
| 50 | //@{ |
| 51 | void accept(AcyclicVisitor&) override; |
| 52 | //@} |
| 53 | }; |
| 54 | |
| 55 | |
| 56 | //! helper class building a sequence of digital ibor-rate coupons |
| 57 | class DigitalCmsSpreadLeg { |
| 58 | public: |
| 59 | DigitalCmsSpreadLeg(Schedule schedule, ext::shared_ptr<SwapSpreadIndex> index); |
| 60 | DigitalCmsSpreadLeg& withNotionals(Real notional); |
| 61 | DigitalCmsSpreadLeg& withNotionals(const std::vector<Real>& notionals); |
| 62 | DigitalCmsSpreadLeg& withPaymentDayCounter(const DayCounter&); |
| 63 | DigitalCmsSpreadLeg& withPaymentAdjustment(BusinessDayConvention); |
| 64 | DigitalCmsSpreadLeg& withFixingDays(Natural fixingDays); |
| 65 | DigitalCmsSpreadLeg& withFixingDays(const std::vector<Natural>& fixingDays); |
| 66 | DigitalCmsSpreadLeg& withGearings(Real gearing); |
| 67 | DigitalCmsSpreadLeg& withGearings(const std::vector<Real>& gearings); |
| 68 | DigitalCmsSpreadLeg& withSpreads(Spread spread); |
| 69 | DigitalCmsSpreadLeg& withSpreads(const std::vector<Spread>& spreads); |
| 70 | DigitalCmsSpreadLeg& inArrears(bool flag = true); |
| 71 | DigitalCmsSpreadLeg& withCallStrikes(Rate strike); |
| 72 | DigitalCmsSpreadLeg& withCallStrikes(const std::vector<Rate>& strikes); |
| 73 | DigitalCmsSpreadLeg& withLongCallOption(Position::Type); |
| 74 | DigitalCmsSpreadLeg& withCallATM(bool flag = true); |
| 75 | DigitalCmsSpreadLeg& withCallPayoffs(Rate payoff); |
| 76 | DigitalCmsSpreadLeg& withCallPayoffs(const std::vector<Rate>& payoffs); |
| 77 | DigitalCmsSpreadLeg& withPutStrikes(Rate strike); |
| 78 | DigitalCmsSpreadLeg& withPutStrikes(const std::vector<Rate>& strikes); |
| 79 | DigitalCmsSpreadLeg& withLongPutOption(Position::Type); |
| 80 | DigitalCmsSpreadLeg& withPutATM(bool flag = true); |
| 81 | DigitalCmsSpreadLeg& withPutPayoffs(Rate payoff); |
| 82 | DigitalCmsSpreadLeg& withPutPayoffs(const std::vector<Rate>& payoffs); |
| 83 | DigitalCmsSpreadLeg& withReplication(const ext::shared_ptr<DigitalReplication>&); |
| 84 | /*! \deprecated Use the overload that passes a replication instead. |
| 85 | Deprecated in version 1.32. |
| 86 | */ |
| 87 | [[deprecated("Use the overload that passes a replication instead" )]] |
| 88 | DigitalCmsSpreadLeg& withReplication(); |
| 89 | DigitalCmsSpreadLeg& withNakedOption(bool nakedOption = true); |
| 90 | |
| 91 | operator Leg() const; |
| 92 | private: |
| 93 | Schedule schedule_; |
| 94 | ext::shared_ptr<SwapSpreadIndex> index_; |
| 95 | std::vector<Real> notionals_; |
| 96 | DayCounter paymentDayCounter_; |
| 97 | BusinessDayConvention paymentAdjustment_ = Following; |
| 98 | std::vector<Natural> fixingDays_; |
| 99 | std::vector<Real> gearings_; |
| 100 | std::vector<Spread> spreads_; |
| 101 | bool inArrears_ = false; |
| 102 | std::vector<Rate> callStrikes_, callPayoffs_; |
| 103 | Position::Type longCallOption_ = Position::Long; |
| 104 | bool callATM_ = false; |
| 105 | std::vector<Rate> putStrikes_, putPayoffs_; |
| 106 | Position::Type longPutOption_ = Position::Long; |
| 107 | bool putATM_ = false; |
| 108 | ext::shared_ptr<DigitalReplication> replication_; |
| 109 | bool nakedOption_; |
| 110 | }; |
| 111 | |
| 112 | } |
| 113 | |
| 114 | |
| 115 | #endif |
| 116 | |