QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
pathpayoff.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Andrea Odetti
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#ifndef quantlib_path_payoff_hpp
25#define quantlib_path_payoff_hpp
26
27#include <ql/math/matrix.hpp>
28#include <ql/patterns/visitor.hpp>
29#include <ql/termstructures/yieldtermstructure.hpp>
30#include <ql/handle.hpp>
31#include <functional>
32
33namespace QuantLib {
34
36 class PathPayoff {
37 public:
38 virtual ~PathPayoff() = default;
40
41
45 virtual std::string name() const = 0;
46 virtual std::string description() const = 0;
47
48
49 /*
50 This function returns all the payoff and early termination payments
51 for a single path. If the option is cancelled at time i, all payments
52 on and before i are taken into account + the value of exercises[i].
53 i.e.: cancellation at i does not cancel payments[i]!
54
55 forwardTermStructures contains the yield term structure at each fixing date
56
57 leave states empty to signal exercise is not possible
58 in that case, exercises[] will not be accessed.
59 */
60
61 virtual void value(const Matrix & path,
62 const std::vector<Handle<YieldTermStructure> > & forwardTermStructures,
63 Array & payments,
64 Array & exercises,
65 std::vector<Array> & states) const = 0;
66
67 /*
68 Dimension of the basis functions.
69 It must be the same as the size of every element of states in value().
70 */
71
72 virtual Size basisSystemDimension() const = 0;
73
75
77 virtual void accept(AcyclicVisitor&);
79 };
80
81
82 // inline definitions
83
85 auto* v1 = dynamic_cast<Visitor<PathPayoff>*>(&v);
86 if (v1 != nullptr)
87 v1->visit(*this);
88 else
89 QL_FAIL("not a path-payoff visitor");
90 }
91}
92
93
94#endif
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
1-D array used in linear algebra.
Definition: array.hpp:52
Shared handle to an observable.
Definition: handle.hpp:41
Matrix used in linear algebra.
Definition: matrix.hpp:41
Abstract base class for path-dependent option payoffs.
Definition: pathpayoff.hpp:36
virtual Size basisSystemDimension() const =0
virtual void accept(AcyclicVisitor &)
Definition: pathpayoff.hpp:84
virtual ~PathPayoff()=default
virtual std::string description() const =0
virtual std::string name() const =0
virtual void value(const Matrix &path, const std::vector< Handle< YieldTermStructure > > &forwardTermStructures, Array &payments, Array &exercises, std::vector< Array > &states) const =0
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35