FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
params.hpp File Reference

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
 

Detailed Description

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).

Macro Definition Documentation

◆ FASTMM_PARAMS

#define FASTMM_PARAMS (   Self)
Value:
using FastmmParamsSelf = Self; \
static const ::fastmm::ParamSchema& schema() { \
static const ::fastmm::ParamSchema s = ::fastmm::detail::collect_schema<Self>(); \
return s; \
} \
std::optional<std::string> apply(const ::fastmm::ParamMap& m) { \
return ::fastmm::detail::apply_params(schema(), this, m); \
} \
[[nodiscard]] std::string describe() const { \
return ::fastmm::detail::describe_params(schema(), this); \
}

◆ FASTMM_PARAM_IMPL

#define FASTMM_PARAM_IMPL (   unit,
  type,
  name,
  def,
  lo,
  hi,
  doc 
)
Value:
type name = def; \
struct FastmmReg_##name { \
FastmmReg_##name() noexcept { \
using FastmmCodec = ::fastmm::detail::ParamCodec<type, unit>; \
::fastmm::detail::register_param(::fastmm::ParamDesc{ \
#name, \
FastmmCodec::kType, \
FastmmCodec::display(::fastmm::detail::param_cast<type>(def)), \
FastmmCodec::display(::fastmm::detail::param_cast<type>(lo)), \
FastmmCodec::display(::fastmm::detail::param_cast<type>(hi)), \
doc, \
+[](void* fastmm_obj, std::string_view fastmm_value) { \
return ::fastmm::detail::assign_param<FastmmCodec, type>( \
static_cast<FastmmParamsSelf*>(fastmm_obj)->name, \
fastmm_value, \
::fastmm::detail::param_cast<type>(lo), \
::fastmm::detail::param_cast<type>(hi)); \
}, \
+[](const void* fastmm_obj) { \
return FastmmCodec::format(static_cast<const FastmmParamsSelf*>(fastmm_obj)->name); \
}, \
+[](const void* fastmm_obj) noexcept -> std::int64_t { \
return FastmmCodec::to_raw(static_cast<const FastmmParamsSelf*>(fastmm_obj)->name); \
}, \
+[](void* fastmm_obj, std::int64_t fastmm_raw) noexcept { \
static_cast<FastmmParamsSelf*>(fastmm_obj)->name = FastmmCodec::from_raw(fastmm_raw); \
}}); \
} \
}; \
[[no_unique_address]] FastmmReg_##name fastmm_reg_##name{};
Definition params.hpp:81

Implementation of the FASTMM_PARAM* macros: the field, then a zero-size registrar whose constructor adds the schema entry while collect_schema() runs.

◆ FASTMM_PARAM

#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.

◆ FASTMM_PARAM_BPS

#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).

◆ FASTMM_PARAM_MS

#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)).