feat: Support python md plugins

This commit is contained in:
John Colvin committed 2025-06-13 20:50:29 +00:00
1 parent 8579c9fdc5
commit 7fa8e4ca47
48 files changed
+3411

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
#pragma once
#include "spark/core/FMT_IMPL.h"
#include <iostream>
#include <limits>
#include <string>
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<double>::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