-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptionData.hpp
84 lines (68 loc) · 2.11 KB
/
OptionData.hpp
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
// OptionData.hpp
//
// Encapsulate option data.
//
// (C) Datasim Education BV 2008-2016
#ifndef OptionData_HPP
#define OptionData_HPP
#include <algorithm> // for max()
#include <iostream>
#include <boost/parameter.hpp>
namespace OptionParams
{
BOOST_PARAMETER_KEYWORD(Tag, strike)
BOOST_PARAMETER_KEYWORD(Tag, expiration)
BOOST_PARAMETER_KEYWORD(Tag, interestRate)
BOOST_PARAMETER_KEYWORD(Tag, volatility)
BOOST_PARAMETER_KEYWORD(Tag, spotPrice)
BOOST_PARAMETER_KEYWORD(Tag, NSIM)
BOOST_PARAMETER_KEYWORD(Tag, dividend)
BOOST_PARAMETER_KEYWORD(Tag, optionType)
}
// Encapsulate all data in one place
struct OptionData
{ // Option data + behaviour
double K; // Strike price
double T; // Time to expiry in years
double r; // Interest rate
double sig; // Volatility
double S; // Spot price
// Extra data
unsigned long NSIM; // Number of simulations
double D; // dividend
int type; // 1 == call, -1 == put
explicit constexpr OptionData(double strike, double expiration, double interestRate, double volatility,
double spotPrice, unsigned long NSIM, double dividend, int PC)
: K{strike}, T{expiration}, r{interestRate}, sig{volatility}, S{spotPrice}, NSIM{NSIM}, D{dividend}, type{PC}
{
}
template <typename ArgPack>
explicit OptionData(const ArgPack& args)
{
K = args[OptionParams::strike];
T = args[OptionParams::expiration];
r = args[OptionParams::interestRate];
sig = args[OptionParams::volatility];
S = args[OptionParams::spotPrice];
NSIM = args[OptionParams::NSIM];
D = args[OptionParams::dividend];
type = args[OptionParams::optionType];
std::cout << "K=" << K << ", T=" << T << ", r=" << r << std::endl;
std::cout << "vol=" << sig << "S=" << S << "NSIM=" << NSIM << std::endl;
std::cout << ", div=" << D << ",type=" << type << std::endl;
}
double myPayOffFunction(double S) const
{ // Payoff function
if (type == 1)
{
// Call
return std::max(S - K, 0.0);
}
else
{
// Put
return std::max (K - S, 0.0);
}
}
};
#endif