QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdmshoutloginnervaluecalculator.cpp
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 <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
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
32namespace QuantLib {
33
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 : blackVolatility_(std::move(blackVolatility)),
42 escrowedDividendAdj_(std::move(escrowedDividendAdj)),
43 maturity_(maturity), payoff_(std::move(payoff)),
44 mesher_(std::move(mesher)), direction_(direction) {}
45
46
48 const FdmLinearOpIterator& iter, Time t) {
49
50 const Real s_t = std::exp(mesher_->location(iter, direction_));
51
52 const DiscountFactor qf =
53 escrowedDividendAdj_->dividendYield()->discount(maturity_)/
54 escrowedDividendAdj_->dividendYield()->discount(t);
55
56 const DiscountFactor df =
57 escrowedDividendAdj_->riskFreeRate()->discount(maturity_)/
58 escrowedDividendAdj_->riskFreeRate()->discount(t);
59
60 const Real fwd = s_t*qf/df;
61 const Volatility stdDev = blackVolatility_->blackForwardVol(
62 t, maturity_, s_t)*std::sqrt(maturity_-t);
63
64 const Real npv = blackFormula(
65 payoff_->optionType(), s_t, fwd, stdDev, df);
66
67 const Real spot = s_t - escrowedDividendAdj_->dividendAdjustment(t);
68
69 const Real intrinsic = (payoff_->optionType() == Option::Call)
70 ? spot - payoff_->strike() : payoff_->strike() - spot;
71
72 return std::max(0.0, npv + intrinsic*df);
73 }
74
76 const FdmLinearOpIterator& iter, Time t) {
77 return innerValue(iter, t);
78 }
79}
Real innerValue(const FdmLinearOpIterator &iter, Time t) override
FdmShoutLogInnerValueCalculator(Handle< BlackVolTermStructure > blackVolatility, ext::shared_ptr< EscrowedDividendAdjustment > escrowedDividendAdj, Time maturity, ext::shared_ptr< PlainVanillaPayoff > payoff, ext::shared_ptr< FdmMesher > mesher, Size direction)
Real avgInnerValue(const FdmLinearOpIterator &iter, Time t) override
const ext::shared_ptr< PlainVanillaPayoff > payoff_
const ext::shared_ptr< EscrowedDividendAdjustment > escrowedDividendAdj_
const Handle< BlackVolTermStructure > blackVolatility_
Shared handle to an observable.
Definition: handle.hpp:41
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
Real Volatility
volatility
Definition: types.hpp:78
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
Real blackFormula(Option::Type optionType, Real strike, Real forward, Real stdDev, Real discount, Real displacement)
STL namespace.