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