| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2014, 2015, 2018 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 | |
| 16 | This program is distributed in the hope that it will be useful, but |
| 17 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 18 | or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ |
| 19 | |
| 20 | /*! \file lognormalcmsspreadpricer.hpp |
| 21 | \brief cms spread coupon pricer as in Brigo, Mercurio, 13.6.2, with |
| 22 | extensions for shifted lognormal and normal dynamics as |
| 23 | described in http://ssrn.com/abstract=2686998 |
| 24 | */ |
| 25 | |
| 26 | #ifndef quantlib_lognormal_cmsspread_pricer_hpp |
| 27 | #define quantlib_lognormal_cmsspread_pricer_hpp |
| 28 | |
| 29 | #include <ql/cashflows/cmscoupon.hpp> |
| 30 | #include <ql/experimental/coupons/cmsspreadcoupon.hpp> |
| 31 | #include <ql/experimental/coupons/swapspreadindex.hpp> |
| 32 | #include <ql/math/integrals/gaussianquadratures.hpp> |
| 33 | #include <ql/math/distributions/normaldistribution.hpp> |
| 34 | #include <ql/optional.hpp> |
| 35 | |
| 36 | namespace QuantLib { |
| 37 | |
| 38 | class CmsSpreadCoupon; |
| 39 | class YieldTermStructure; |
| 40 | |
| 41 | //! CMS spread - coupon pricer |
| 42 | /*! The swap rate adjustments are computed using the given |
| 43 | volatility structures for the underlyings in every case |
| 44 | (w.r.t. volatility type and shift). |
| 45 | |
| 46 | For the bivariate spread model, the volatility type and |
| 47 | the shifts can be inherited (default), or explicitly |
| 48 | specified. In the latter case the type, and (if lognormal) |
| 49 | the shifts must be given (or are defaulted to zero, if not |
| 50 | given). |
| 51 | |
| 52 | References: |
| 53 | |
| 54 | Brigo, Mercurio: Interst Rate Models - Theory and Practice, |
| 55 | 2nd Edition, Springer, 2006, chapter 13.6.2 |
| 56 | |
| 57 | http://ssrn.com/abstract=2686998 |
| 58 | */ |
| 59 | |
| 60 | class LognormalCmsSpreadPricer : public CmsSpreadCouponPricer { |
| 61 | |
| 62 | public: |
| 63 | LognormalCmsSpreadPricer( |
| 64 | const ext::shared_ptr<CmsCouponPricer>& cmsPricer, |
| 65 | const Handle<Quote>& correlation, |
| 66 | Handle<YieldTermStructure> couponDiscountCurve = Handle<YieldTermStructure>(), |
| 67 | Size IntegrationPoints = 16, |
| 68 | const ext::optional<VolatilityType>& volatilityType = ext::nullopt, |
| 69 | Real shift1 = Null<Real>(), |
| 70 | Real shift2 = Null<Real>()); |
| 71 | |
| 72 | /* */ |
| 73 | Real swapletPrice() const override; |
| 74 | Rate swapletRate() const override; |
| 75 | Real capletPrice(Rate effectiveCap) const override; |
| 76 | Rate capletRate(Rate effectiveCap) const override; |
| 77 | Real floorletPrice(Rate effectiveFloor) const override; |
| 78 | Rate floorletRate(Rate effectiveFloor) const override; |
| 79 | |
| 80 | private: |
| 81 | void initialize(const FloatingRateCoupon& coupon) override; |
| 82 | Real optionletPrice(Option::Type optionType, Real strike) const; |
| 83 | |
| 84 | Real integrand(Real) const; |
| 85 | Real integrand_normal(Real) const; |
| 86 | |
| 87 | class integrand_f; |
| 88 | |
| 89 | ext::shared_ptr<CmsCouponPricer> cmsPricer_; |
| 90 | |
| 91 | Handle<YieldTermStructure> couponDiscountCurve_; |
| 92 | |
| 93 | const CmsSpreadCoupon *coupon_; |
| 94 | |
| 95 | Date today_, fixingDate_, paymentDate_; |
| 96 | |
| 97 | Real fixingTime_; |
| 98 | |
| 99 | Real gearing_, spread_; |
| 100 | Real spreadLegValue_; |
| 101 | Real discount_; |
| 102 | |
| 103 | ext::shared_ptr<SwapSpreadIndex> index_; |
| 104 | |
| 105 | ext::shared_ptr<CumulativeNormalDistribution> cnd_; |
| 106 | ext::shared_ptr<GaussianQuadrature> integrator_; |
| 107 | |
| 108 | Real swapRate1_, swapRate2_, gearing1_, gearing2_; |
| 109 | Real adjustedRate1_, adjustedRate2_; |
| 110 | Real vol1_, vol2_; |
| 111 | Real mu1_, mu2_; |
| 112 | Real rho_; |
| 113 | |
| 114 | bool inheritedVolatilityType_; |
| 115 | VolatilityType volType_; |
| 116 | Real shift1_, shift2_; |
| 117 | |
| 118 | mutable Real phi_, a_, b_, s1_, s2_, m1_, m2_, v1_, v2_, k_; |
| 119 | mutable Real alpha_, psi_; |
| 120 | mutable Option::Type optionType_; |
| 121 | |
| 122 | ext::shared_ptr<CmsCoupon> c1_, c2_; |
| 123 | }; |
| 124 | } |
| 125 | |
| 126 | #endif |
| 127 | |