QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdmexpextouinnervaluecalculator.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2011 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
20/*! \file fdmexpextouinnervaluecalculator.hpp
21 \brief inner value calculator for an exponential extended
22 Ornstein Uhlenbeck grid
23*/
24
25#ifndef quantlib_fdm_exp_ext_ou_inner_value_calculator_hpp
26#define quantlib_fdm_exp_ext_ou_inner_value_calculator_hpp
27
30#include <ql/payoff.hpp>
31#include <utility>
32
33namespace QuantLib {
34
36 public:
37 typedef std::vector<std::pair<Time, Real> > Shape;
38
39 FdmExpExtOUInnerValueCalculator(ext::shared_ptr<Payoff> payoff,
40 ext::shared_ptr<FdmMesher> mesher,
41 ext::shared_ptr<Shape> shape = ext::shared_ptr<Shape>(),
42 Size direction = 0)
43 : direction_(direction), payoff_(std::move(payoff)), mesher_(std::move(mesher)),
44 shape_(std::move(shape)) {}
45
46 Real innerValue(const FdmLinearOpIterator& iter, Time t) override {
47 const Real u = mesher_->location(iter, direction_);
48
49 Real f = 0;
50 if (shape_ != nullptr) {
51 f = std::lower_bound(shape_->begin(), shape_->end(),
52 std::pair<Time, Real>(t-std::sqrt(QL_EPSILON), 0.0))->second;
53 }
54
55 return (*payoff_)(std::exp(f + u));
56 }
57 Real avgInnerValue(const FdmLinearOpIterator& iter, Time t) override {
58 return innerValue(iter, t);
59 }
60
61 private:
63 const ext::shared_ptr<Payoff> payoff_;
64 const ext::shared_ptr<FdmMesher> mesher_;
65 const ext::shared_ptr<Shape> shape_;
66 };
67
68}
69#endif
Real innerValue(const FdmLinearOpIterator &iter, Time t) override
FdmExpExtOUInnerValueCalculator(ext::shared_ptr< Payoff > payoff, ext::shared_ptr< FdmMesher > mesher, ext::shared_ptr< Shape > shape=ext::shared_ptr< Shape >(), Size direction=0)
Real avgInnerValue(const FdmLinearOpIterator &iter, Time t) override
const DefaultType & t
layer of abstraction to calculate the inner value
mesher for a fdm grid
#define QL_EPSILON
Definition: qldefines.hpp:178
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
ext::shared_ptr< QuantLib::Payoff > payoff
Definition: any.hpp:35
STL namespace.
Option payoff classes.