Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fdmquantohelper.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
20
21#include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
22#include <ql/termstructures/yieldtermstructure.hpp>
23#include <ql/math/comparison.hpp>
24
25namespace QuantExt {
26
27FdmQuantoHelper::FdmQuantoHelper(const ext::shared_ptr<YieldTermStructure>& rTS,
28 const ext::shared_ptr<YieldTermStructure>& fTS,
29 const ext::shared_ptr<BlackVolTermStructure>& fxVolTS, const Real equityFxCorrelation,
30 const Real fxStrike, const Real initialFxSpot, const bool discounting,
31 const bool ensureNonNegativeForwardVariance)
32 : rTS_(rTS), fTS_(fTS), fxVolTS_(fxVolTS), equityFxCorrelation_(equityFxCorrelation), fxStrike_(fxStrike),
33 initialFxSpot_(initialFxSpot), discounting_(discounting),
34 ensureNonNegativeForwardVariance_(ensureNonNegativeForwardVariance) {
35 QL_REQUIRE(fxStrike_ != Null<Real>() || initialFxSpot != Null<Real>(),
36 "initialFxSpot must be given, if fxStrike is null (=atmf)");
37}
38
39Rate FdmQuantoHelper::quantoAdjustment(Volatility equityVol, Time t1, Time t2) const {
40 Rate rDomestic = 0.0, rForeign = 0.0;
41 if (fxStrike_ == Null<Real>() || discounting_) {
42 rDomestic = rTS_->forwardRate(t1, t2, Continuous).rate();
43 rForeign = fTS_->forwardRate(t1, t2, Continuous).rate();
44 }
45 Real k1, k2;
46 if (fxStrike_ == Null<Real>()) {
47 k1 = initialFxSpot_ * fTS_->discount(t1) / rTS_->discount(t1);
48 k2 = initialFxSpot_ * fTS_->discount(t2) / rTS_->discount(t2);
49 } else {
50 k1 = k2 = fxStrike_;
51 }
52 Real v = ((close_enough(t2, 0.0) ? 0.0 : fxVolTS_->blackVariance(t2, k2)) -
53 (close_enough(t1, 0.0) ? 0.0 : fxVolTS_->blackVariance(t1, k1))) /
54 (t2 - t1);
56 v = std::max(v, 0.0);
57 const Volatility fxVol = std::sqrt(v);
58 return (discounting_ ? (rDomestic - rForeign) : 0.0) + equityVol * fxVol * equityFxCorrelation_;
59}
60
61Array FdmQuantoHelper::quantoAdjustment(const Array& equityVol, Time t1, Time t2) const {
62 Rate rDomestic = 0.0, rForeign = 0.0;
63 if (fxStrike_ == Null<Real>() || discounting_) {
64 rDomestic = rTS_->forwardRate(t1, t2, Continuous).rate();
65 rForeign = fTS_->forwardRate(t1, t2, Continuous).rate();
66 }
67 Real k1, k2;
68 if (fxStrike_ == Null<Real>()) {
69 k1 = initialFxSpot_ * fTS_->discount(t1) / rTS_->discount(t1);
70 k2 = initialFxSpot_ * fTS_->discount(t2) / rTS_->discount(t2);
71 } else {
72 k1 = k2 = fxStrike_;
73 }
74 Real v = ((close_enough(t2, 0.0) ? 0.0 : fxVolTS_->blackVariance(t2, k2)) -
75 (close_enough(t1, 0.0) ? 0.0 : fxVolTS_->blackVariance(t1, k1))) /
76 (t2 - t1);
78 v = std::max(v, 0.0);
79 const Volatility fxVol = std::sqrt(v);
80 Array retVal(equityVol.size());
81 for (Size i = 0; i < retVal.size(); ++i) {
82 retVal[i] = (discounting_ ? (rDomestic - rForeign) : 0.0) + equityVol[i] * fxVol * equityFxCorrelation_;
83 }
84
85 return retVal;
86}
87
88} // namespace QuantExt
const bool ensureNonNegativeForwardVariance_
const ext::shared_ptr< YieldTermStructure > fTS_
const ext::shared_ptr< BlackVolTermStructure > fxVolTS_
FdmQuantoHelper(const ext::shared_ptr< YieldTermStructure > &rTS, const ext::shared_ptr< YieldTermStructure > &fTS, const ext::shared_ptr< BlackVolTermStructure > &fxVolTS, const Real equityFxCorrelation, const Real fxStrike, Real initialFxSpot=Null< Real >(), const bool discounting=true, const bool ensureNonNegativeForwardVariance=false)
const ext::shared_ptr< YieldTermStructure > rTS_
Rate quantoAdjustment(Volatility equityVol, Time t1, Time t2) const
extended version of the QuantLib class, see the documentation for details
Filter close_enough(const RandomVariable &x, const RandomVariable &y)