Coverage Report

Created: 2025-08-05 06:45

/src/quantlib/ql/experimental/coupons/quantocouponpricer.cpp
Line
Count
Source (jump to first uncovered line)
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
0
    Rate BlackIborQuantoCouponPricer::adjustedFixing(Real fixing) const {
32
33
0
        if (fixing == Null<Rate>())
34
0
            fixing = coupon_->indexFixing();
35
36
        // Here we apply the quanto adjustment first, then delegate to
37
        // the parent class
38
0
        Date d1 = coupon_->fixingDate(),
39
0
             referenceDate = capletVolatility()->referenceDate();
40
41
0
        if (d1 > referenceDate) {
42
0
            Time t1 =
43
0
                capletVolatility()->timeFromReference(d1);
44
0
            Volatility fxsigma =
45
0
                fxRateBlackVolatility_->blackVol(d1, fixing, true);
46
0
            Volatility sigma = capletVolatility()->volatility(d1, fixing);
47
0
            Real rho = underlyingFxCorrelation_->value();
48
49
            // Apply Quanto Adjustment.
50
            // Hull 6th Edition, page 642, generalised to
51
            // shifted lognormal and normal volatilities
52
0
            if(capletVolatility()->volatilityType() == ShiftedLognormal) {
53
0
                Real dQuantoAdj = std::exp(sigma*fxsigma*rho*t1);
54
0
                Real shift = capletVolatility()->displacement();
55
0
                fixing = (fixing+shift)*dQuantoAdj-shift;
56
0
            }
57
0
            else {
58
0
                Real dQuantoAdj = sigma*fxsigma*rho*t1;
59
0
                fixing += dQuantoAdj;
60
0
            }
61
0
        }
62
63
0
        return BlackIborCouponPricer::adjustedFixing(fixing);
64
0
    }
65
66
}
67