6#include "../../internal/Conf.hpp"
10#include "../../internal/Common.hpp"
27
28
29
30
31
32
33
34
35template <
typename T>
class OptionSeries final {
38 std::int32_t expiration_ = 0;
39 std::int32_t lastTrade_ = 0;
40 double multiplier_ = 0.0;
42 std::string additionalUnderlyings_{};
44 std::string optionType_{};
45 std::string expirationStyle_{};
46 std::string settlementStyle_{};
49 std::map<
double, std::shared_ptr<T>> calls_{};
50 std::map<
double, std::shared_ptr<T>> puts_{};
52 mutable std::vector<
double> strikes_{};
56
57
58
59
63
64
65
66
67
73
74
75
76
77
83
84
85
86
87
93
94
95
96
97
103
104
105
106
107
108
109
110
111
112
113
114
116 return additionalUnderlyings_;
120
121
122
123
124
125
126
127
128
129
135
136
137
138
139
140
141
142
143
144
145
146
147
148
154
155
156
157
159 return expirationStyle_;
163
164
165
166
168 return settlementStyle_;
172
173
174
175
176
177
178
179
180
181
187
188
189
190
196
197
198
199
205
206
207
208
210 if (strikes_.empty()) {
211 std::set<
double> strikesSet{};
213 for (
const auto &call : calls_) {
214 strikesSet.insert(call.first);
217 for (
const auto &put : puts_) {
218 strikesSet.insert(put.first);
221 strikes_.assign(strikesSet.begin(), strikesSet.end());
228
229
230
231
232
233
235 const auto &strikesVector = getStrikes();
236 const auto it = std::lower_bound(strikesVector.begin(), strikesVector.end(), strike);
237 const std::size_t index = std::distance(strikesVector.begin(), it);
238 const std::size_t fromIndex = (index < n / 2) ? 0 : (index - n / 2);
239 const std::size_t toIndex = std::min(strikesVector.size(), fromIndex + n);
241 return std::vector<
double>(strikesVector.begin() + fromIndex, strikesVector.begin() + toIndex);
244 bool operator==(
const OptionSeries &other)
const {
245 return expiration_ == other.expiration_ && lastTrade_ == other.lastTrade_ &&
246 math::equals(multiplier_, other.multiplier_) && math::equals(spc_, other.spc_) &&
247 additionalUnderlyings_ == other.additionalUnderlyings_ && expirationStyle_ == other.expirationStyle_ &&
248 mmy_ == other.mmy_ && optionType_ == other.optionType_ && cfi_ == other.cfi_ &&
249 settlementStyle_ == other.settlementStyle_;
252 bool operator!=(
const OptionSeries &other)
const {
253 return !(*
this == other);
256 bool operator<(
const OptionSeries &other)
const {
257 if (expiration_ != other.expiration_) {
258 return expiration_ < other.expiration_;
261 if (lastTrade_ != other.lastTrade_) {
262 return lastTrade_ < other.lastTrade_;
265 if (multiplier_ != other.multiplier_) {
266 return multiplier_ < other.multiplier_;
269 if (spc_ != other.spc_) {
270 return spc_ < other.spc_;
273 if (additionalUnderlyings_ != other.additionalUnderlyings_) {
274 return additionalUnderlyings_ < other.additionalUnderlyings_;
277 if (mmy_ != other.mmy_) {
278 return mmy_ < other.mmy_;
281 if (optionType_ != other.optionType_) {
282 return optionType_ < other.optionType_;
285 if (expirationStyle_ != other.expirationStyle_) {
286 return expirationStyle_ < other.expirationStyle_;
289 if (settlementStyle_ != other.settlementStyle_) {
290 return settlementStyle_ < other.settlementStyle_;
293 return cfi_ < other.cfi_;
296 void addOption(
bool isCall,
double strike, std::shared_ptr<T> option) {
297 if (
auto &map = isCall ? calls_ : puts_; map.emplace(strike, option).second) {
303
304
305
306
308 std::ostringstream ss{};
310 ss <<
"expiration=" << expiration_;
312 if (lastTrade_ != 0) {
313 ss <<
", lastTrade=" << lastTrade_;
316 if (multiplier_ != 0) {
317 ss <<
", multiplier=" << multiplier_;
321 ss <<
", spc=" << spc_;
324 if (!additionalUnderlyings_.empty()) {
325 ss <<
", additionalUnderlyings=" << additionalUnderlyings_;
329 ss <<
", mmy=" << mmy_;
332 if (!optionType_.empty()) {
333 ss <<
", optionType=" << optionType_;
336 if (!expirationStyle_.empty()) {
337 ss <<
", expirationStyle=" << expirationStyle_;
340 if (!settlementStyle_.empty()) {
341 ss <<
", settlementStyle=" << settlementStyle_;
344 ss <<
", cfi=" << cfi_;
349 friend std::ostream &operator<<(std::ostream &os,
const OptionSeries &series) {
355 std::size_t hashCode()
const {
356 auto result =
static_cast<std::size_t>(expiration_);
358 hashCombine(result, lastTrade_);
359 hashCombine(result, multiplier_);
360 hashCombine(result, spc_);
361 hashCombine(result, additionalUnderlyings_);
362 hashCombine(result, mmy_);
363 hashCombine(result, optionType_);
364 hashCombine(result, expirationStyle_);
365 hashCombine(result, settlementStyle_);
366 hashCombine(result, cfi_);
374template <
typename T>
struct std::hash<dxfcpp::OptionSeries<T>> {
375 std::size_t operator()(
const dxfcpp::OptionSeries<T> &optionSeries)
const noexcept {
376 return optionSeries.hashCode();
#define DXFCXX_DISABLE_MSC_WARNINGS_POP()
Definition Conf.hpp:22
#define DXFCPP_END_NAMESPACE
Definition Conf.hpp:70
#define DXFCPP_BEGIN_NAMESPACE
Definition Conf.hpp:67
#define DXFCXX_DISABLE_MSC_WARNINGS_PUSH(warnings)
Definition Conf.hpp:21
Builder class for a set of option chains grouped by product or underlying symbol.
Definition OptionChainsBuilder.hpp:27
std::vector< double > getNStrikesAround(std::size_t n, double strike) const
Returns n strikes which are centered around a specified strike value.
Definition OptionSeries.hpp:234
const std::map< double, std::shared_ptr< T > > & getPuts() const
Returns a sorted map of all puts from strike to a corresponding option instrument.
Definition OptionSeries.hpp:200
const std::map< double, std::shared_ptr< T > > & getCalls() const
Returns a sorted map of all calls from strike to a corresponding option instrument.
Definition OptionSeries.hpp:191
const std::string & getCFI() const
Returns Classification of Financial Instruments code.
Definition OptionSeries.hpp:182
const std::string & getMMY() const
Returns maturity month-year as provided for corresponding FIX tag (200).
Definition OptionSeries.hpp:130
std::int32_t getExpiration() const
Returns day id of expiration.
Definition OptionSeries.hpp:68
std::string toString() const
Returns a string representation of the current object.
Definition OptionSeries.hpp:307
const std::string & getOptionType() const
Returns type of option.
Definition OptionSeries.hpp:149
const std::string & getExpirationStyle() const
Returns expiration cycle style, such as "Weeklys", "Quarterlys".
Definition OptionSeries.hpp:158
const std::string & getSettlementStyle() const
Returns settlement price determination style, such as "Open", "Close".
Definition OptionSeries.hpp:167
double getSPC() const
Returns shares per contract for options.
Definition OptionSeries.hpp:98
double getMultiplier() const
Returns market value multiplier.
Definition OptionSeries.hpp:88
const std::vector< double > & getStrikes() const
Returns a list of all strikes in ascending order.
Definition OptionSeries.hpp:209
OptionSeries()=default
Default constructor for the OptionSeries class.
std::int32_t getLastTrade() const
Returns day id of last trading day.
Definition OptionSeries.hpp:78
const std::string & getAdditionalUnderlyings() const
Returns additional underlyings for options, including additional cash.
Definition OptionSeries.hpp:115