-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPayoff.jl
143 lines (99 loc) · 3.57 KB
/
Payoff.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""
abstract type Payoff end
A `Payoff` is a random variable *X* in our stochastic model.
It represents a market object that can be evaluated in conjunction with a given path.
We are interested in realisations of a payoff *at* a given path, i.e. *X(omega)*. Moreover,
for risk-neutral valuation we are also interested in *discounted* payoffs *at* a given path.
We implement a `Payoff` as a root of a computational graph. The nodes of the computational
graph are itself `Payoff` objects which represent mathematical operations or use the path *omega*
to determine its realisations.
"""
abstract type Payoff end
"""
obs_time(p::Payoff)
A `Payoff` is typically observed at a particular time. In that sense, a `Payoff` is an
``F_t``-measurable random variable.
The observation time represents the time, after which the payoff *is known*.
"""
function obs_time(p::Payoff)
error("Payoff needs to implement obs_time method.")
end
"""
obs_times(p::Payoff)
A payoff is typically linked to other payoffs and forms a DAG. This function returns all
observation times associated with a given payoff.
This functionality is required to determine relevant simulation grid points.
"""
function obs_times(p::Payoff)
error("Payoff needs to implement obs_times method.")
end
"""
at(p::Payoff, path::AbstractPath)
Evaluate a `Payoff` at a given `path`, *X(omega)*.
Depending on the functionality associated with the `path`, this function typically
returns a vector of realisations.
This function is invoked when using call operator on a `Payoff`,
(p::Payoff)(path::AbstractPath) = at(p::Payoff, path::AbstractPath)
"""
function at(p::Payoff, path::AbstractPath)
error("Payoff needs to implement at method.")
end
"""
(p::Payoff)(path::AbstractPath)
Syntactic sugar for payoff evaluation
"""
(p::Payoff)(path::AbstractPath) = at(p::Payoff, path::AbstractPath)
"""
abstract type Leaf <: Payoff end
A Leaf is a particular Payoff which has no outgoing links to other Payoff objects. A Leaf
typically uses the path to determine its realisations.
We assume that a Leaf has a field obs_time.
"""
abstract type Leaf <: Payoff end
"""
obs_time(p::Leaf)
Return the observation time for a Leaf object.
"""
obs_time(p::Leaf) = p.obs_time
"""
obs_times(p::Leaf)
Derive the set of observation times from the single observation time of the Leaf object.
"""
obs_times(p::Leaf) = Set(obs_time(p))
"""
abstract type UnaryNode <: Payoff end
A UnaryNode is a particular Payoff which has exactly one outgoing link to another Payoff
object.
We assume that the reference to the outgoing Payoff object is a field denoted *x*.
A UnaryNode is typically a decorator of the linked Payoff.
"""
abstract type UnaryNode <: Payoff end
"""
obs_time(p::UnaryNode)
Return the observation time of the linked payoff.
"""
obs_time(p::UnaryNode) = obs_time(p.x)
"""
obs_times(p::UnaryNode)
Return all observation times of the linked payoff.
"""
obs_times(p::UnaryNode) = obs_times(p.x)
"""
abstract type BinaryNode <: Payoff end
A BinaryNode is a particular Payoff which has exactly two outgoing links to other
Payoff objects.
We assume that the references to the outgoing Payoff objects are fields denoted
*x* and *y*.
A BinaryNode is typically a mathematical operation.
"""
abstract type BinaryNode <: Payoff end
"""
obs_time(p::BinaryNode)
Derive the observation time from linked payoffs.
"""
obs_time(p::BinaryNode) = max(obs_time(p.x), obs_time(p.y))
"""
obs_times(p::BinaryNode)
Derive all observation times from linked payoff.
"""
obs_times(p::BinaryNode) = union(obs_times(p.x), obs_times(p.y))