|
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
|
Strategy parameter schema (8.6, ADR-0012). More...
#include "fastmm/core/containers/static_vector.hpp"#include "fastmm/core/fixed_point.hpp"#include "fastmm/core/time.hpp"#include <bit>#include <charconv>#include <cmath>#include <cstddef>#include <cstdint>#include <limits>#include <map>#include <optional>#include <stdexcept>#include <string>#include <string_view>#include <type_traits>#include <utility>Go to the source code of this file.
Classes | |
| struct | fastmm::ParamDesc |
| class | fastmm::ParamSchema |
Namespaces | |
| namespace | fastmm |
Macros | |
| #define | FASTMM_PARAMS(Self) |
| #define | FASTMM_PARAM_IMPL(unit, type, name, def, lo, hi, doc) |
| Implementation of the FASTMM_PARAM* macros: the field, then a zero-size registrar whose constructor adds the schema entry while collect_schema() runs. | |
| #define | FASTMM_PARAM(type, name, def, lo, hi, doc) FASTMM_PARAM_IMPL(::fastmm::detail::PlainUnit, type, name, def, lo, hi, doc) |
| FASTMM_PARAM(type, name, default, min, max, doc): bool, integer, floating point, Price, Qty or Notional field. | |
| #define | FASTMM_PARAM_BPS(name, def, lo, hi, doc) FASTMM_PARAM_IMPL(::fastmm::detail::BpsUnit, ::fastmm::Ratio, name, def, lo, hi, doc) |
| FASTMM_PARAM_BPS(name, default, min, max, doc): Ratio field configured in basis points (5_bps, 0.25_bps; up to 4 decimals). | |
| #define | FASTMM_PARAM_MS(name, def, lo, hi, doc) FASTMM_PARAM_IMPL(::fastmm::detail::MsUnit, ::fastmm::Duration, name, def, lo, hi, doc) |
| FASTMM_PARAM_MS(name, default, min, max, doc): Duration field configured in whole milliseconds (bounds as Durations: milliseconds(2000)). | |
Typedefs | |
| using | fastmm::ParamMap = std::map< std::string, std::string > |
Enumerations | |
| enum class | fastmm::ParamType : std::uint8_t { fastmm::Int = 0 , fastmm::Double = 1 , fastmm::Bool = 2 , fastmm::Decimal = 3 , fastmm::Bps = 4 , fastmm::Millis = 5 } |
Functions | |
| constexpr std::string_view | fastmm::to_string (ParamType t) noexcept |
Variables | |
| constexpr std::size_t | fastmm::kMaxParams = 128 |
Strategy parameter schema (8.6, ADR-0012).
struct MyParams { FASTMM_PARAMS(MyParams) FASTMM_PARAM(double, gamma, 0.1, 0.0, 10.0, "risk aversion") FASTMM_PARAM(int, levels, 1, 1, 8, "quote levels per side") FASTMM_PARAM(bool, hedge, false, false, true, "hedge fills") FASTMM_PARAM(Qty, quote_qty, 0.01_qty, 0_qty, 1000_qty, "quantity per level, base units") FASTMM_PARAM_BPS(half_spread_bps, 5_bps, 0_bps, 1000_bps, "half spread around mid") FASTMM_PARAM_MS(stale_ms, milliseconds(2000), milliseconds(0), milliseconds(60000), "...")
// Optional cross-field check, run by StrategyBase::configure() after every key is applied. std::optional<std::string> validate() const { if (quote_qty > max_inventory) return "quote_qty must not exceed max_inventory"; return std::nullopt; } };
FASTMM_PARAM declares the field and a schema entry (name, type, default, range, doc, parser and formatter). Field types: bool, integers, floating point (schema types int, double, bool) and Price, Qty, Notional (schema type decimal, parsed exactly). FASTMM_PARAM_BPS declares a Ratio configured in basis points (type bps, up to 4 decimals) and FASTMM_PARAM_MS a Duration configured in whole milliseconds (type ms). Exact values accept exponent notation ("2e-05"), because TOML floats reach the parser formatted by fmt and Python floats by repr; a value is rejected only if more decimals remain after applying the exponent than the type holds. Range checks compare typed values; def, min and max in ParamDesc are doubles for display and Python only.
The schema is collected once by default-constructing the struct with a thread-local collector active, so registration is deterministic and needs no static initialisers. apply() maps string values (from TOML / CLI / Python) onto the fields. All of this is startup-only code (std::string and std::map are fine).
| #define FASTMM_PARAMS | ( | Self | ) |
| #define FASTMM_PARAM_IMPL | ( | unit, | |
| type, | |||
| name, | |||
| def, | |||
| lo, | |||
| hi, | |||
| doc | |||
| ) |
Implementation of the FASTMM_PARAM* macros: the field, then a zero-size registrar whose constructor adds the schema entry while collect_schema() runs.
| #define FASTMM_PARAM | ( | type, | |
| name, | |||
| def, | |||
| lo, | |||
| hi, | |||
| doc | |||
| ) | FASTMM_PARAM_IMPL(::fastmm::detail::PlainUnit, type, name, def, lo, hi, doc) |
FASTMM_PARAM(type, name, default, min, max, doc): bool, integer, floating point, Price, Qty or Notional field.
| #define FASTMM_PARAM_BPS | ( | name, | |
| def, | |||
| lo, | |||
| hi, | |||
| doc | |||
| ) | FASTMM_PARAM_IMPL(::fastmm::detail::BpsUnit, ::fastmm::Ratio, name, def, lo, hi, doc) |
FASTMM_PARAM_BPS(name, default, min, max, doc): Ratio field configured in basis points (5_bps, 0.25_bps; up to 4 decimals).
| #define FASTMM_PARAM_MS | ( | name, | |
| def, | |||
| lo, | |||
| hi, | |||
| doc | |||
| ) | FASTMM_PARAM_IMPL(::fastmm::detail::MsUnit, ::fastmm::Duration, name, def, lo, hi, doc) |
FASTMM_PARAM_MS(name, default, min, max, doc): Duration field configured in whole milliseconds (bounds as Durations: milliseconds(2000)).