-
Notifications
You must be signed in to change notification settings - Fork 0
/
Payoff1.cpp
45 lines (36 loc) · 956 Bytes
/
Payoff1.cpp
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
#include "Payoff1.h"
#include <MinMax.h>
VanillaPayoff::VanillaPayoff(double Strike_, OptionType TheOptionsType_)
:
Strike(Strike_), TheOptionsType(TheOptionsType_)
{
}
double VanillaPayoff::operator()(double spot) const
{
switch (TheOptionsType)
{
case call:
return max(spot - Strike, 0.0);
case put:
return max(Strike - spot, 0.0);
default:
throw("Unknown option type found.");
}
}
DoubleBarrierPayoff::DoubleBarrierPayoff(double BarrierLower_, double BarrierUpper_, OptionType TheOptionsType_)
:
BarrierLower(BarrierLower_), BarrierUpper(BarrierUpper_), TheOptionsType(TheOptionsType_)
{
}
double DoubleBarrierPayoff::operator()(double spot) const
{
switch (TheOptionsType)
{
case inside:
return (BarrierUpper > spot && spot > BarrierLower) ? 1 : 0;
case outside:
return (BarrierUpper < spot || spot < BarrierLower) ? 1 : 0;
default:
throw("Unknown option type found.");
}
}