QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
pathpayoff.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) 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
20/*! \file pathpayoff.hpp
21 \brief Option payoff classes
22*/
23
24#ifndef quantlib_path_payoff_hpp
25#define quantlib_path_payoff_hpp
26
27#include <ql/math/matrix.hpp>
30#include <ql/handle.hpp>
31#include <functional>
32
33namespace QuantLib {
34
35 //! Abstract base class for path-dependent option payoffs
36 class PathPayoff {
37 public:
38 virtual ~PathPayoff() = default;
39 //! \name Payoff interface
40 //@{
41 /*! \warning This method is used for output and comparison between
42 payoffs. It is <b>not</b> meant to be used for writing
43 switch-on-type code.
44 */
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
74 //@}
75 //! \name Visitability
76 //@{
77 virtual void accept(AcyclicVisitor&);
78 //@}
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
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
std::size_t Size
size of a container
Definition: types.hpp:58
Globally accessible relinkable pointer.
matrix used in linear algebra.
Definition: any.hpp:35
ext::shared_ptr< BlackVolTermStructure > v
degenerate base class for the Acyclic Visitor pattern
Interest-rate term structure.