/src/quantlib/ql/methods/finitedifferences/utilities/fdmshoutloginnervaluecalculator.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2021 Klaus Spanderen |
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 | | <https://www.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 | | /*! \file fdmshoutinnervaluecalculator.cpp |
21 | | \brief inner value for a shout option |
22 | | */ |
23 | | |
24 | | #include <ql/instruments/payoffs.hpp> |
25 | | #include <ql/methods/finitedifferences/meshers/fdmmesher.hpp> |
26 | | #include <ql/methods/finitedifferences/utilities/fdmshoutloginnervaluecalculator.hpp> |
27 | | #include <ql/pricingengines/blackformula.hpp> |
28 | | #include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp> |
29 | | |
30 | | #include <utility> |
31 | | |
32 | | namespace QuantLib { |
33 | | |
34 | | FdmShoutLogInnerValueCalculator::FdmShoutLogInnerValueCalculator( |
35 | | Handle<BlackVolTermStructure> blackVolatility, |
36 | | ext::shared_ptr<EscrowedDividendAdjustment> escrowedDividendAdj, |
37 | | Time maturity, |
38 | | ext::shared_ptr<PlainVanillaPayoff> payoff, |
39 | | ext::shared_ptr<FdmMesher> mesher, |
40 | | Size direction) |
41 | 0 | : blackVolatility_(std::move(blackVolatility)), |
42 | 0 | escrowedDividendAdj_(std::move(escrowedDividendAdj)), |
43 | 0 | maturity_(maturity), payoff_(std::move(payoff)), |
44 | 0 | mesher_(std::move(mesher)), direction_(direction) {} |
45 | | |
46 | | |
47 | | Real FdmShoutLogInnerValueCalculator::innerValue( |
48 | 0 | const FdmLinearOpIterator& iter, Time t) { |
49 | |
|
50 | 0 | const Real s_t = std::exp(mesher_->location(iter, direction_)); |
51 | |
|
52 | 0 | const DiscountFactor qf = |
53 | 0 | escrowedDividendAdj_->dividendYield()->discount(maturity_)/ |
54 | 0 | escrowedDividendAdj_->dividendYield()->discount(t); |
55 | |
|
56 | 0 | const DiscountFactor df = |
57 | 0 | escrowedDividendAdj_->riskFreeRate()->discount(maturity_)/ |
58 | 0 | escrowedDividendAdj_->riskFreeRate()->discount(t); |
59 | |
|
60 | 0 | const Real fwd = s_t*qf/df; |
61 | 0 | const Volatility stdDev = blackVolatility_->blackForwardVol( |
62 | 0 | t, maturity_, s_t)*std::sqrt(maturity_-t); |
63 | |
|
64 | 0 | const Real npv = blackFormula( |
65 | 0 | payoff_->optionType(), s_t, fwd, stdDev, df); |
66 | |
|
67 | 0 | const Real spot = s_t - escrowedDividendAdj_->dividendAdjustment(t); |
68 | |
|
69 | 0 | const Real intrinsic = (payoff_->optionType() == Option::Call) |
70 | 0 | ? spot - payoff_->strike() : payoff_->strike() - spot; |
71 | |
|
72 | 0 | return std::max(0.0, npv + intrinsic*df); |
73 | 0 | } |
74 | | |
75 | | Real FdmShoutLogInnerValueCalculator::avgInnerValue( |
76 | 0 | const FdmLinearOpIterator& iter, Time t) { |
77 | 0 | return innerValue(iter, t); |
78 | 0 | } |
79 | | } |