-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayoff.cpp
97 lines (67 loc) · 2.56 KB
/
payoff.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef __PAY_OFF_CPP
#define __PAY_OFF_CPP
#include "payoff.h"
#include "PseudoFactory.h"
PayOff::PayOff() {}
// ==========
// PayOffCall
// ==========
// Constructor with single strike parameter
PayOffEuroCall::PayOffEuroCall(PseudoFactory & fac) : K_(fac.GetK()),
E_(fac.GetE()),T_(fac.GetT()),r_(fac.Getr()), J_(fac.GetJ()),early_(false) {}
// Over-ridden operator() method, which turns PayOffCall into a function object
double PayOffEuroCall::operator() (const double& S) const {
return std::max(S - K_, 0.0); // Standard European call pay-off
}
double PayOffEuroCall::calculate_Call_value(const double& S,std::vector<double>& P,long j) const {
return S + P[j] - K_*exp(-r_*T_); //from put-call parity
}
// =========
// PayOffPut
// =========
// Constructor with single strike parameter
PayOffEuroPut::PayOffEuroPut(PseudoFactory & fac)
: K_(fac.GetK()),early_(false)
{}
// Over-ridden operator() method, which turns PayOffPut into a function object
double PayOffEuroPut::operator() (const double& S) const {
return std::max(K_ - S, 0.0); // Standard European put pay-off
}
// =========
// PayOffAmericanPut
// =========
// Constructor with single strike parameter
PayOffAmericanPut::PayOffAmericanPut(PseudoFactory & fac)
: K_(fac.GetK()),early_(true)
{}
// Over-ridden operator() method, which turns PayOffPut into a function object
double PayOffAmericanPut::operator() (const double& S) const {
return std::max(K_ - S, 0.0); // Standard European put pay-off
}
// =========
// PayOffCallSpread
// =========
PayOffCallSpread::PayOffCallSpread(PseudoFactory & fac)
: K_(fac.GetK()),E_(fac.GetE()),early_(false)
{}
// Over-ridden operator() method, which turns PayOffCallSpread into a function object
double PayOffCallSpread::operator() (const double& S) const {
return (std::max(S - E_, 0.0) - std::max(S - K_,0.0));//
}
// =========
// PayOffPutSpread
// =========
PayOffPutSpread::PayOffPutSpread(PseudoFactory & fac)
: K_(fac.GetK()),E_(fac.GetE()),early_(false)
{}
// Over-ridden operator() method, which turns PayOffPutSpread into a function object
double PayOffPutSpread::operator() (const double& S) const {
return (std::max(K_ - S, 0.0) - std::max(E_ - S,0.0)); //
}
// =========
// PayOff Max of Twoassets
// =========
#endif
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// end
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX