FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
risk_limits.hpp
Go to the documentation of this file.
1#pragma once
2// RiskLimits: the pre-trade limits a session runs with ([risk] in the configuration), and
3// RiskHeadroom, what they still admit (RiskEngine::headroom, StrategyContext::risk_headroom).
4// Separate from risk.hpp so a message can carry them (core/messages.hpp: ControlLimitsMsg, the
5// operator's `limits` command) without pulling in the whole risk engine.
8
9#include <cstdint>
10#include <limits>
11#include <type_traits>
12
13namespace fastmm {
14
15struct RiskLimits {
16 Qty max_order_qty{}; // 0 = unlimited
17 Notional max_order_notional{}; // 0 = unlimited
18 Qty max_position{}; // absolute, predicted (position + same-side open); 0 = unlimited
19 std::uint32_t max_open_orders = 0; // per instrument; 0 = unlimited
20 std::int64_t price_collar_bps = 0; // vs mid; 0 = disabled
21 std::int64_t fat_finger_bps = 0; // vs last trade; 0 = disabled
22 Duration stale_md{}; // reject if book older than this; 0 = disabled
23 // Portfolio exposure at the last marks, over every instrument; 0 = unlimited. Gross is the sum
24 // of |position|, net the signed sum: a hedged pair is small in net and large in gross.
27 Notional max_loss{}; // trip when net pnl <= -max_loss; 0 = disabled
28 std::uint32_t orders_per_sec = 0; // token bucket rate; 0 = unlimited
29 std::uint32_t burst = 0; // bucket capacity (defaults to orders_per_sec)
30 bool stp = true; // self-trade prevention against our own resting orders
31 // Feed-lag gate (core/venue_health.hpp): while a venue's market data arrives more than this
32 // much later than its baseline, its quotes are pulled and orders that could rest there without
33 // reducing the position are refused (FeedLag); 0 = off.
34 std::uint32_t max_feed_lag_ms = 0;
35
36 // A limit that reads the portfolio totals ([accounting] converts them).
37 [[nodiscard]] constexpr bool reads_totals() const noexcept {
40 }
41};
42static_assert(std::is_trivially_copyable_v<RiskLimits> && sizeof(RiskLimits) == 96);
43
44// How much more each limit admits for one instrument now: the largest order (or number of orders)
45// that passes that limit's check at this instant, the others aside. What check_new would use next:
46// a request of exactly a room passes that check and one lot more is refused. kUnlimited where the
47// limit is off. Notionals are in the reporting currency ([accounting]) where the check converts.
48struct RiskHeadroom {
49 static constexpr std::int64_t kUnlimited = std::numeric_limits<std::int64_t>::max();
50 std::int64_t order_tokens = kUnlimited; // orders the rate limiter admits now (orders_per_sec)
51 std::int64_t open_orders = kUnlimited; // more open orders on the instrument (max_open_orders)
52 Qty max_order_qty = Qty::max(); // per order (max_order_qty)
53 Notional max_order_notional = Notional::max(); // per order (max_order_notional)
54 // Largest buy / sell passing max_position (position plus open orders on that side), rounded
55 // down to the lot.
58 // Largest buy / sell of this instrument passing [risk.underlying] max_net (the underlying's net
59 // plus its open orders on that side, over every instrument), in this instrument's contracts,
60 // rounded down to the lot; zero while an inverse contract of the underlying has no mark.
63 // Exposure an order that does not reduce its position may add: max_gross_notional minus the
64 // gross exposure, and per direction the net room of max_net_notional.
68 // The same two caps as the notional of one order on this instrument, in its settlement
69 // currency (the engine converts with the rate the check uses): the largest buy / sell notional
70 // that passes both. max() when neither cap is on and for the side that reduces the position
71 // (the caps never refuse that); zero while the currency's rate is unknown, where an order that
72 // adds exposure is refused (FxRateUnknown).
75 // max_loss plus the net PnL it is measured against; the kill switch trips at zero or below.
77 // Largest buy / sell at the book's mid the account's balance on the venue covers ([risk]
78 // check_balance, core/balance_book.hpp), rounded down to the lot; unlimited until the venue
79 // reports the balance the side draws on.
82};
84} // namespace fastmm
Fixed<Tag>: int64 fixed point with a global 1e-8 scale (ADR-0001).
Definition strategy.hpp:16
Fixed< struct QtyTag > Qty
Definition fixed_point.hpp:333
Definition time.hpp:22
static constexpr Fixed max() noexcept
Definition fixed_point.hpp:165
constexpr bool is_positive() const noexcept
Definition fixed_point.hpp:302
Qty buy_qty
Largest buy / sell passing max_position (position plus open orders on that side), rounded down to the...
Definition risk_limits.hpp:58
Qty balance_buy_qty
Largest buy / sell at the book's mid the account's balance on the venue covers ([risk] check_balance,...
Definition risk_limits.hpp:82
Notional net_sell_notional
Definition risk_limits.hpp:69
Notional exposure_sell_notional
Definition risk_limits.hpp:76
Notional max_order_notional
per order (max_order_notional)
Definition risk_limits.hpp:55
Notional exposure_buy_notional
The same two caps as the notional of one order on this instrument, in its settlement currency (the en...
Definition risk_limits.hpp:75
Qty balance_sell_qty
Definition risk_limits.hpp:83
Notional loss_budget
max_loss plus the net PnL it is measured against; the kill switch trips at zero or below.
Definition risk_limits.hpp:78
Qty underlying_buy_qty
Largest buy / sell of this instrument passing [risk.underlying] max_net (the underlying's net plus it...
Definition risk_limits.hpp:63
Notional net_buy_notional
Definition risk_limits.hpp:68
Qty max_order_qty
per order (max_order_qty)
Definition risk_limits.hpp:54
static constexpr std::int64_t kUnlimited
Definition risk_limits.hpp:51
Notional gross_notional
Exposure an order that does not reduce its position may add: max_gross_notional minus the gross expos...
Definition risk_limits.hpp:67
Qty underlying_sell_qty
Definition risk_limits.hpp:64
Qty sell_qty
Definition risk_limits.hpp:59
std::int64_t order_tokens
orders the rate limiter admits now (orders_per_sec)
Definition risk_limits.hpp:52
std::int64_t open_orders
more open orders on the instrument (max_open_orders)
Definition risk_limits.hpp:53
Notional max_loss
trip when net pnl <= -max_loss; 0 = disabled
Definition risk_limits.hpp:29
std::uint32_t burst
bucket capacity (defaults to orders_per_sec)
Definition risk_limits.hpp:31
Qty max_order_qty
0 = unlimited
Definition risk_limits.hpp:18
Notional max_net_notional
Definition risk_limits.hpp:28
std::int64_t price_collar_bps
vs mid; 0 = disabled
Definition risk_limits.hpp:22
Notional max_order_notional
0 = unlimited
Definition risk_limits.hpp:19
Qty max_position
absolute, predicted (position + same-side open); 0 = unlimited
Definition risk_limits.hpp:20
Notional max_gross_notional
Portfolio exposure at the last marks, over every instrument; 0 = unlimited.
Definition risk_limits.hpp:27
std::uint32_t max_feed_lag_ms
Feed-lag gate (core/venue_health.hpp): while a venue's market data arrives more than this much later ...
Definition risk_limits.hpp:36
bool stp
self-trade prevention against our own resting orders
Definition risk_limits.hpp:32
std::int64_t fat_finger_bps
vs last trade; 0 = disabled
Definition risk_limits.hpp:23
Duration stale_md
reject if book older than this; 0 = disabled
Definition risk_limits.hpp:24
constexpr bool reads_totals() const noexcept
A limit that reads the portfolio totals ([accounting] converts them).
Definition risk_limits.hpp:39
std::uint32_t orders_per_sec
token bucket rate; 0 = unlimited
Definition risk_limits.hpp:30
std::uint32_t max_open_orders
per instrument; 0 = unlimited
Definition risk_limits.hpp:21
Time primitives.