algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::strategy::RiskLimits Struct Reference

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.

Detailed Description

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.

Definition at line 268 of file risk.hpp.

Member Data Documentation

◆ enforce_buying_power_

bool algotradelib::strategy::RiskLimits::enforce_buying_power_ {false}

Whether to refuse a buy that costs more than the broker's buying power.

Off by default. The figure is a reading: a fill since the broker answered can change it, so passing this check does not guarantee the broker accepts the order.

Definition at line 315 of file risk.hpp.

◆ enforce_sellable_quantity_

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.

Definition at line 308 of file risk.hpp.

◆ max_gross_exposure_

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.

Definition at line 291 of file risk.hpp.

◆ max_order_notional_

std::optional<Decimal64> algotradelib::strategy::RiskLimits::max_order_notional_

The largest value one order may have, in its own currency.

Definition at line 270 of file risk.hpp.

◆ max_orders_per_window_

std::optional<std::size_t> algotradelib::strategy::RiskLimits::max_orders_per_window_

The most orders that may be sent within rate_window_.

Definition at line 293 of file risk.hpp.

◆ max_position_quantity_

std::optional<Decimal64> algotradelib::strategy::RiskLimits::max_position_quantity_

The largest absolute position, in shares, any instrument may reach.

Checked against the net held quantity (all rows) plus everything working on the order's side plus the order, as if all of it filled.

Definition at line 277 of file risk.hpp.

◆ permitted_phases_

std::optional<std::vector<MarketPhase> > algotradelib::strategy::RiskLimits::permitted_phases_
Initial value:
{
std::vector<MarketPhase>{MarketPhase::OPEN}
}
@ OPEN
Inside the session.
Definition event.hpp:38

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.

Definition at line 331 of file risk.hpp.

◆ permitted_universe_

std::optional<std::vector<InstrumentId> > algotradelib::strategy::RiskLimits::permitted_universe_

The instruments that may be traded; absent means any.

Definition at line 317 of file risk.hpp.

◆ rate_window_

std::chrono::seconds algotradelib::strategy::RiskLimits::rate_window_ {60}

The window max_orders_per_window_ counts over.

Definition at line 295 of file risk.hpp.


The documentation for this struct was generated from the following file: