Files
spark/src/lib_python_md/python_md/py_option.h
T

69 lines
1.6 KiB
C++

#pragma once
#include <limits>
#include <sstream>
#include <string>
namespace bts::md::py_interop {
/**
* @brief Defines the expiration, strike, and call/put for an Option contract.
*/
class PyOption {
public:
constexpr PyOption() = default;
const std::string &expiration() const;
void set_expiration(std::string value);
constexpr bool is_call() const;
void set_is_call(bool value);
constexpr double strike() const;
void set_strike(double value);
std::string to_string() const;
private:
std::string expiration_;
bool is_call_{false};
double strike_{std::numeric_limits<double>::quiet_NaN()};
};
std::ostream &operator<<(std::ostream &out, const PyOption &opt) noexcept;
//////////////////////////////////////////////////
// Definition
//////////////////////////////////////////////////
inline const std::string &PyOption::expiration() const { return expiration_; }
inline void PyOption::set_expiration(std::string value) {
expiration_ = std::move(value);
}
constexpr bool PyOption::is_call() const { return is_call_; }
inline void PyOption::set_is_call(bool value) { is_call_ = value; }
constexpr double PyOption::strike() const { return strike_; }
inline void PyOption::set_strike(double value) { strike_ = value; }
inline std::string PyOption::to_string() const {
std::stringstream str;
str << *this;
return str.str();
}
inline std::ostream &operator<<(
std::ostream &out, const PyOption &opt) noexcept {
out << opt.expiration() << " ";
if (opt.is_call()) {
out << "CALL ";
} else {
out << "PUT ";
}
out << opt.strike();
return out;
}
} // namespace bts::md::py_interop