-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVanillaOption.cpp
More file actions
46 lines (35 loc) · 1.31 KB
/
VanillaOption.cpp
File metadata and controls
46 lines (35 loc) · 1.31 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
#include "VanillaOption.h"
#pragma region VanillaOption
//Constructor
VanillaOption::VanillaOption(double expiry, double strike) : Option(expiry)
{
if (strike <= 0)
throw std::invalid_argument("Strike should be nonnegative");
else
m_strike = strike;
}
// Destructor
VanillaOption::~VanillaOption() { }
// Overriden version returning the strike of the option
double VanillaOption::GetStrike() { return m_strike; }
#pragma endregion
#pragma region CallOption
//Constructor
CallOption::CallOption(double expiry, double strike) : VanillaOption(expiry, strike) { }
// Destructor
CallOption::~CallOption() { }
// Returns the type of the option, in this case a call
OptionType CallOption::GetOptionType() { return OptionType::Call; }
// Returns the payoff of a call option
double CallOption::payoff(double z) { return std::max(z - m_strike, 0.0); }
#pragma endregion
#pragma region PutOption
//Constructor
PutOption::PutOption(double expiry, double strike) : VanillaOption(expiry, strike) { }
// Destructor
PutOption::~PutOption() { }
// Returns the type of the option, in this case a put
OptionType PutOption::GetOptionType() { return OptionType::Put; }
// Returns the payoff of a put option
double PutOption::payoff(double z) { return std::max(m_strike - z, 0.0); }
#pragma endregion