| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2008 Toyin Akin |
| 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/experimental/coupons/quantocouponpricer.hpp> |
| 21 | #include <ql/cashflows/capflooredcoupon.hpp> |
| 22 | #include <ql/cashflows/digitalcoupon.hpp> |
| 23 | #include <ql/cashflows/digitalcmscoupon.hpp> |
| 24 | #include <ql/cashflows/digitaliborcoupon.hpp> |
| 25 | #include <ql/cashflows/rangeaccrual.hpp> |
| 26 | #include <ql/pricingengines/blackformula.hpp> |
| 27 | #include <ql/indexes/interestrateindex.hpp> |
| 28 | |
| 29 | namespace QuantLib { |
| 30 | |
| 31 | Rate BlackIborQuantoCouponPricer::adjustedFixing(Real fixing) const { |
| 32 | |
| 33 | if (fixing == Null<Rate>()) |
| 34 | fixing = coupon_->indexFixing(); |
| 35 | |
| 36 | // Here we apply the quanto adjustment first, then delegate to |
| 37 | // the parent class |
| 38 | Date d1 = coupon_->fixingDate(), |
| 39 | referenceDate = capletVolatility()->referenceDate(); |
| 40 | |
| 41 | if (d1 > referenceDate) { |
| 42 | Time t1 = |
| 43 | capletVolatility()->timeFromReference(d: d1); |
| 44 | Volatility fxsigma = |
| 45 | fxRateBlackVolatility_->blackVol(d: d1, strike: fixing, extrapolate: true); |
| 46 | Volatility sigma = capletVolatility()->volatility(optionDate: d1, strike: fixing); |
| 47 | Real rho = underlyingFxCorrelation_->value(); |
| 48 | |
| 49 | // Apply Quanto Adjustment. |
| 50 | // Hull 6th Edition, page 642, generalised to |
| 51 | // shifted lognormal and normal volatilities |
| 52 | if(capletVolatility()->volatilityType() == ShiftedLognormal) { |
| 53 | Real dQuantoAdj = std::exp(x: sigma*fxsigma*rho*t1); |
| 54 | Real shift = capletVolatility()->displacement(); |
| 55 | fixing = (fixing+shift)*dQuantoAdj-shift; |
| 56 | } |
| 57 | else { |
| 58 | Real dQuantoAdj = sigma*fxsigma*rho*t1; |
| 59 | fixing += dQuantoAdj; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return BlackIborCouponPricer::adjustedFixing(fixing); |
| 64 | } |
| 65 | |
| 66 | } |
| 67 | |
| 68 | |