-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigitalOption.cpp
More file actions
61 lines (49 loc) · 1.59 KB
/
DigitalOption.cpp
File metadata and controls
61 lines (49 loc) · 1.59 KB
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
#include "DigitalOption.h"
#pragma region DigitalOption
// Constructor
DigitalOption::DigitalOption(double expiry, double strike) : Option(expiry)
{
if (strike <= 0)
throw std::invalid_argument("Strike should be nonnegative");
else
m_strike = strike;
}
// Destructor
DigitalOption::~DigitalOption() { }
// Overriden version returning the strike of the option
double DigitalOption::GetStrike() { return m_strike; }
// Overriden version returning true to indicate that this option is digital
bool DigitalOption::isDigital() { return true; }
#pragma endregion
#pragma region DigitalCallOption
// Constructor
DigitalCallOption::DigitalCallOption(double expiry, double strike) : DigitalOption(expiry, strike) { }
// Destructor
DigitalCallOption::~DigitalCallOption() { }
// Returns the type of the option, in this case a call
OptionType DigitalCallOption::GetOptionType() { return OptionType::Call; }
// Returns the payoff of a digital call option
double DigitalCallOption::payoff(double z)
{
if (z >= m_strike)
return 1;
else
return 0;
}
#pragma endregion
#pragma region DigitalPutOption
// Constructor
DigitalPutOption::DigitalPutOption(double expiry, double strike) : DigitalOption(expiry, strike) { }
// Destructor
DigitalPutOption::~DigitalPutOption() { }
// Returns the type of the option, in this case a put
OptionType DigitalPutOption::GetOptionType() { return OptionType::Put; }
// Returns the payoff of a digital put option
double DigitalPutOption::payoff(double z)
{
if (z <= m_strike)
return 1;
else
return 0;
}
#pragma endregion