#pragma once #include "spark/core/FMT_IMPL.h" #include #include #include namespace bts::md::py_interop { /** * Option contract expiration, strike, and call/put. */ 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::quiet_NaN()}; }; std::ostream &operator<<(std::ostream &out, const PyOption &opt) noexcept; } // namespace bts::md::py_interop ////////////////////////////////////////////////// // Definition ////////////////////////////////////////////////// FMT_IMPL( bts::md::py_interop::PyOption, f, R"({{ "exp" : "{}", "k": {}, "cp": "{}" }})", f.expiration(), f.strike(), f.is_call() ? 'C' : 'P'); namespace bts::md::py_interop { 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 { return fmt::format("{}", *this); } inline std::ostream &operator<<( std::ostream &out, const PyOption &opt) noexcept { out << fmt::format("{}", opt); return out; } } // namespace bts::md::py_interop