![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
The limits the operator sets for RiskGuard. More...
#include <algotradelib/src/strategy/risk.hpp>
Public Attributes | |
| std::optional< Decimal64 > | max_order_notional_ |
| The largest value one order may have, in its own currency. | |
| std::optional< Decimal64 > | max_position_quantity_ |
| The largest absolute position, in shares, any instrument may reach. | |
| std::optional< Decimal64 > | max_gross_exposure_ |
| The largest gross exposure the portfolio may reach, in the order's currency. | |
| std::optional< std::size_t > | max_orders_per_window_ |
| The most orders that may be sent within rate_window_. | |
| std::chrono::seconds | rate_window_ {60} |
| The window max_orders_per_window_ counts over. | |
| bool | enforce_sellable_quantity_ {true} |
| Whether to refuse a sell larger than the broker's sellable quantity. | |
| bool | enforce_buying_power_ {false} |
| Whether to refuse a buy that costs more than the broker's buying power. | |
| std::optional< std::vector< InstrumentId > > | permitted_universe_ |
| The instruments that may be traded; absent means any. | |
| std::optional< std::vector< MarketPhase > > | permitted_phases_ |
| The market phases in which a position may be opened or increased; absent means any. | |
The limits the operator sets for RiskGuard.
Every limit is optional and absent means unlimited, except permitted_phases_, which by default permits opening positions only while the market is OPEN, and enforce_sellable_quantity_, which is on by default. Holds (halts) are not limits; they are taken on the guard itself.
| bool algotradelib::strategy::RiskLimits::enforce_buying_power_ {false} |
| bool algotradelib::strategy::RiskLimits::enforce_sellable_quantity_ {true} |
Whether to refuse a sell larger than the broker's sellable quantity.
On by default: a sell is refused if the broker gave no sellable figure (the held quantity is not assumed sellable) or the figure's basis is not established. So an account that cannot sell what it does not hold never sends a sale that would open a short: every shipped adapter places cash orders, and a target below zero is refused here before it is sent.
Turn it off, where the replay or the dry run is configured, to simulate short positions; that models no borrow. Turning it off for a live account borrows nothing either: it only lets the sale reach the broker.
| std::optional<Decimal64> algotradelib::strategy::RiskLimits::max_gross_exposure_ |
The largest gross exposure the portfolio may reach, in the order's currency.
Checked against the exposure if this order and every outstanding order filled, each valued at the highest price that could apply (see projected_gross_exposure). The ceiling applies to each currency separately; there is no account-wide converted cap.
An order that does not raise this projection is permitted at any size, so an exit (a sell up to flat against a long) is allowed even when the account is over the ceiling. A sell that goes through flat into a short raises it and can be refused. To cap one order's size, use max_order_notional_. An order that cannot be valued, or an incomplete GuardInputs::exposure_basis_, is refused with GuardReason::VALUE_NOT_KNOWN.
| std::optional<Decimal64> algotradelib::strategy::RiskLimits::max_order_notional_ |
| std::optional<std::size_t> algotradelib::strategy::RiskLimits::max_orders_per_window_ |
The most orders that may be sent within rate_window_.
| std::optional<Decimal64> algotradelib::strategy::RiskLimits::max_position_quantity_ |
| std::optional<std::vector<MarketPhase> > algotradelib::strategy::RiskLimits::permitted_phases_ |
The market phases in which a position may be opened or increased; absent means any.
The default permits only OPEN, so UNKNOWN (an uncovered calendar date) is refused.
An order that only closes toward flat (it opposes the net held quantity and, with what is already working on the closing side, cannot carry it through flat) is permitted in any phase, so a flatten after the close can still be sent. The later checks (sellable, buying power, position and exposure ceilings) still apply to it, and the broker will likely reject it outside its session; max_orders_per_window_ limits how often such an order is resent, and runner::Runner::sends_outside_permitted_phase counts them. Cancellations are never checked against this.
| std::optional<std::vector<InstrumentId> > algotradelib::strategy::RiskLimits::permitted_universe_ |
| std::chrono::seconds algotradelib::strategy::RiskLimits::rate_window_ {60} |
The window max_orders_per_window_ counts over.