-
Notifications
You must be signed in to change notification settings - Fork 0
/
lattice_product_builder.h
200 lines (143 loc) · 7.13 KB
/
lattice_product_builder.h
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#pragma once
#if !defined(_LATTICE_PRODUCT_BUILDER)
#define _LATTICE_PRODUCT_BUILDER
#include"lattice_product.h"
#include"lattice_types.h"
namespace lattice_product_builder {
using lattice_product::Option;
using lattice_product::SpreadOption;
using lattice_product::BarrierOption;
using lattice_product::PureDiscountBond;
using lattice_product::CouponBond;
using lattice_product::OptionOnPureDiscountBond;
using lattice_product::OptionOnCouponBond;
using lattice_types::BarrierType;
// ===========================================================================
// =========================== OptionBuilder =================================
// ===========================================================================
template<typename T>
class OptionBuilder {
private:
typedef OptionBuilder<T> &self;
Option<T> option_;
public:
~OptionBuilder() {}
Option<T> build() { return std::move(option_); }
self withName(std::string const &name) { option_.setName(name); return *this; }
self withStrike(T value) { option_.setStrike(value); return *this;}
self withSpot(T value) { option_.setSpot(value); return *this;}
self withRate(T value) { option_.setRate(value); return *this;}
self withDividend(T value) { option_.setDividend(value); return *this;}
self withPeriods(std::size_t periods) { option_.setPeriods(periods); return *this;}
self withVolatility(T value) { option_.setVolatility(value); return *this;}
};
// ===========================================================================
// ======================= SpreadOptionBuilder ===============================
// ===========================================================================
template<typename T>
class SpreadOptionBuilder {
private:
typedef SpreadOptionBuilder<T> &self;
SpreadOption<T> option_;
public:
~SpreadOptionBuilder() {}
SpreadOption<T> build() { return std::move(option_); }
self withName(std::string const &name) { option_.setName(name); return *this; }
self withStrike(T value) { option_.setStrike(value); return *this; }
self withSpot1(T value) { option_.setSpot1(value); return *this; }
self withSpot2(T value) { option_.setSpot2(value); return *this; }
self withRate(T value) { option_.setRate(value); return *this; }
self withDividend1(T value) { option_.setDividend1(value); return *this; }
self withDividend2(T value) { option_.setDividend2(value); return *this; }
self withPeriods(std::size_t periods) { option_.setPeriods(periods); return *this; }
self withVolatility1(T value) { option_.setVolatility1(value); return *this; }
self withVolatility2(T value) { option_.setVolatility2(value); return *this; }
self withCorrelation(T value) { option_.setCorrelation(value); return *this; }
};
// ===========================================================================
// ======================== BarrierOptionBuilder =============================
// ===========================================================================
template<typename T>
class BarrierOptionBuilder {
private:
typedef BarrierOptionBuilder<T> &self;
BarrierOption<T> option_;
public:
~BarrierOptionBuilder() {}
BarrierOption<T> build() { return std::move(option_); }
self withName(std::string const &name) { option_.setName(name); return *this;}
self withStrike(T value) { option_.setStrike(value); return *this;}
self withBarrier(T value) { option_.setBarrier(value); return *this;}
self withSpot(T value) { option_.setSpot(value); return *this;}
self withRate(T value) { option_.setRate(value); return *this;}
self withDividend(T value) { option_.setDividend(value); return *this;}
self withPeriods(std::size_t periods) { option_.setPeriods(periods); return *this;}
self withVolatility(T value) { option_.setVolatility(value); return *this;}
self withRebate(T value) { option_.setRebate(value); return *this; }
self withBarrierType(BarrierType barrier) { option_.setBarrierType(barrier); return *this; }
};
// ===========================================================================
// ============================ PureDiscountBondBuilder ======================
// ===========================================================================
template<typename T>
class PureDiscountBondBuilder {
private:
typedef PureDiscountBondBuilder<T> &self;
PureDiscountBond<T> bond_;
public:
~PureDiscountBondBuilder() {}
PureDiscountBond<T> build() { return std::move(bond_); }
self withName(std::string const &name) { bond_.setName(name); return *this;}
self withNominal(T value) { bond_.setNominal(value); return *this;}
self withPeriods(std::size_t periods) { bond_.setPeriods(periods); return *this; }
};
// ===========================================================================
// =============================== CouponBondBuilder =========================
// ===========================================================================
template<typename T, typename TimeAxis>
class CouponBondBuilder {
private:
typedef CouponBondBuilder<T, TimeAxis> &self;
CouponBond<T, TimeAxis> bond_;
public:
~CouponBondBuilder() {}
CouponBond<T, TimeAxis> build() { return std::move(bond_); }
self withName(std::string const &name) { bond_.setName(name); return *this;}
self withPeriods(std::size_t periods) { bond_.setPeriods(periods); return *this; }
self withNominal(T value) { bond_.setNominal(value); return *this;}
self withLastCoupon(T value) { bond_.setLastCoupon(value); return *this;}
self withCouponPair(TimeAxis time, T value) { bond_.addCoupon(time, value); return *this;}
self withCouponData(std::map<TimeAxis, T> const &data) { bond_.setCouponData(data); return *this; }
};
// ===========================================================================
// ========================= OptionOnPureDiscountBondBuilder =================
// ===========================================================================
template<typename T>
class OptionOnPureDiscountBondBuilder {
private:
typedef OptionOnPureDiscountBondBuilder<T> &self;
OptionOnPureDiscountBond<T> option_;
public:
~OptionOnPureDiscountBondBuilder() {}
OptionOnPureDiscountBond<T> build() { return std::move(option_); }
self withName(std::string const &name) { option_.setName(name); return *this;}
self withStrike(T value) { option_.setStrike(value); return *this;}
self withPeriods(std::size_t periods) { option_.setPeriods(periods); return *this; }
};
// ===========================================================================
// ========================= OptionOnCouponBondBuilder =======================
// ===========================================================================
template<typename T>
class OptionOnCouponBondBuilder {
private:
typedef OptionOnCouponBondBuilder<T> &self;
OptionOnCouponBond<T> option_;
public:
~OptionOnCouponBondBuilder() {}
OptionOnCouponBond<T> build() { return std::move(option_); }
self withName(std::string const &name) { option_.setName(name); return *this; }
self withStrike(T value) { option_.setStrike(value); return *this; }
self withPeriods(std::size_t periods) { option_.setPeriods(periods); return *this; }
};
}
#endif ///_LATTICE_PRODUCT_BUILDER