| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2003 Ferdinando Ametrano |
| 5 | Copyright (C) 2008 StatPro Italia srl |
| 6 | |
| 7 | This file is part of QuantLib, a free-software/open-source library |
| 8 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 9 | |
| 10 | QuantLib is free software: you can redistribute it and/or modify it |
| 11 | under the terms of the QuantLib license. You should have received a |
| 12 | copy of the license along with this program; if not, please email |
| 13 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 14 | <http://quantlib.org/license.shtml>. |
| 15 | |
| 16 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 18 | FOR A PARTICULAR PURPOSE. See the license for more details. |
| 19 | */ |
| 20 | |
| 21 | /*! \file quantotermstructure.hpp |
| 22 | \brief Quanto term structure |
| 23 | */ |
| 24 | |
| 25 | #ifndef quantlib_quanto_term_structure_hpp |
| 26 | #define quantlib_quanto_term_structure_hpp |
| 27 | |
| 28 | #include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp> |
| 29 | #include <ql/termstructures/yield/zeroyieldstructure.hpp> |
| 30 | #include <utility> |
| 31 | |
| 32 | namespace QuantLib { |
| 33 | |
| 34 | //! Quanto term structure |
| 35 | /*! Quanto term structure for modelling quanto effect in |
| 36 | option pricing. |
| 37 | |
| 38 | \note This term structure will remain linked to the original |
| 39 | structures, i.e., any changes in the latters will be |
| 40 | reflected in this structure as well. |
| 41 | */ |
| 42 | class QuantoTermStructure : public ZeroYieldStructure { |
| 43 | public: |
| 44 | QuantoTermStructure(const Handle<YieldTermStructure>& underlyingDividendTS, |
| 45 | Handle<YieldTermStructure> riskFreeTS, |
| 46 | Handle<YieldTermStructure> foreignRiskFreeTS, |
| 47 | Handle<BlackVolTermStructure> underlyingBlackVolTS, |
| 48 | Real strike, |
| 49 | Handle<BlackVolTermStructure> exchRateBlackVolTS, |
| 50 | Real exchRateATMlevel, |
| 51 | Real underlyingExchRateCorrelation); |
| 52 | //! \name YieldTermStructure interface |
| 53 | //@{ |
| 54 | DayCounter dayCounter() const override; |
| 55 | Calendar calendar() const override; |
| 56 | Natural settlementDays() const override; |
| 57 | const Date& referenceDate() const override; |
| 58 | Date maxDate() const override; |
| 59 | //@} |
| 60 | protected: |
| 61 | //! returns the zero yield as seen from the evaluation date |
| 62 | Rate zeroYieldImpl(Time) const override; |
| 63 | |
| 64 | private: |
| 65 | Handle<YieldTermStructure> underlyingDividendTS_, riskFreeTS_, |
| 66 | foreignRiskFreeTS_; |
| 67 | Handle<BlackVolTermStructure> underlyingBlackVolTS_, |
| 68 | exchRateBlackVolTS_; |
| 69 | Real underlyingExchRateCorrelation_, strike_, exchRateATMlevel_; |
| 70 | }; |
| 71 | |
| 72 | |
| 73 | // inline definitions |
| 74 | |
| 75 | inline QuantoTermStructure::QuantoTermStructure( |
| 76 | const Handle<YieldTermStructure>& underlyingDividendTS, |
| 77 | Handle<YieldTermStructure> riskFreeTS, |
| 78 | Handle<YieldTermStructure> foreignRiskFreeTS, |
| 79 | Handle<BlackVolTermStructure> underlyingBlackVolTS, |
| 80 | Real strike, |
| 81 | Handle<BlackVolTermStructure> exchRateBlackVolTS, |
| 82 | Real exchRateATMlevel, |
| 83 | Real underlyingExchRateCorrelation) |
| 84 | : ZeroYieldStructure(underlyingDividendTS->dayCounter()), |
| 85 | underlyingDividendTS_(underlyingDividendTS), riskFreeTS_(std::move(riskFreeTS)), |
| 86 | foreignRiskFreeTS_(std::move(foreignRiskFreeTS)), |
| 87 | underlyingBlackVolTS_(std::move(underlyingBlackVolTS)), |
| 88 | exchRateBlackVolTS_(std::move(exchRateBlackVolTS)), |
| 89 | underlyingExchRateCorrelation_(underlyingExchRateCorrelation), strike_(strike), |
| 90 | exchRateATMlevel_(exchRateATMlevel) { |
| 91 | registerWith(h: underlyingDividendTS_); |
| 92 | registerWith(h: riskFreeTS_); |
| 93 | registerWith(h: foreignRiskFreeTS_); |
| 94 | registerWith(h: underlyingBlackVolTS_); |
| 95 | registerWith(h: exchRateBlackVolTS_); |
| 96 | } |
| 97 | |
| 98 | inline DayCounter QuantoTermStructure::dayCounter() const { |
| 99 | return underlyingDividendTS_->dayCounter(); |
| 100 | } |
| 101 | |
| 102 | inline Calendar QuantoTermStructure::calendar() const { |
| 103 | return underlyingDividendTS_->calendar(); |
| 104 | } |
| 105 | |
| 106 | inline Natural QuantoTermStructure::settlementDays() const { |
| 107 | return underlyingDividendTS_->settlementDays(); |
| 108 | } |
| 109 | |
| 110 | inline const Date& QuantoTermStructure::referenceDate() const { |
| 111 | return underlyingDividendTS_->referenceDate(); |
| 112 | } |
| 113 | |
| 114 | inline Date QuantoTermStructure::maxDate() const { |
| 115 | Date maxDate = std::min(a: underlyingDividendTS_->maxDate(), |
| 116 | b: riskFreeTS_->maxDate()); |
| 117 | maxDate = std::min(a: maxDate, b: foreignRiskFreeTS_->maxDate()); |
| 118 | maxDate = std::min(a: maxDate, b: underlyingBlackVolTS_->maxDate()); |
| 119 | maxDate = std::min(a: maxDate, b: exchRateBlackVolTS_->maxDate()); |
| 120 | return maxDate; |
| 121 | } |
| 122 | |
| 123 | inline Rate QuantoTermStructure::zeroYieldImpl(Time t) const { |
| 124 | // warning: here it is assumed that all TS have the same daycount. |
| 125 | // It should be QL_REQUIREd |
| 126 | return underlyingDividendTS_->zeroRate(t, comp: Continuous, freq: NoFrequency, extrapolate: true).rate() |
| 127 | + riskFreeTS_->zeroRate(t, comp: Continuous, freq: NoFrequency, extrapolate: true).rate() |
| 128 | - foreignRiskFreeTS_->zeroRate(t, comp: Continuous, freq: NoFrequency, extrapolate: true).rate() |
| 129 | + underlyingExchRateCorrelation_ |
| 130 | * underlyingBlackVolTS_->blackVol(t, strike: strike_, extrapolate: true) |
| 131 | * exchRateBlackVolTS_->blackVol(t, strike: exchRateATMlevel_, extrapolate: true); |
| 132 | } |
| 133 | |
| 134 | } |
| 135 | |
| 136 | |
| 137 | #endif |
| 138 | |