![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
The price grid (tick sizes) an instrument's order prices must sit on. More...
#include <algotradelib/src/core/instrument.hpp>
Public Types | |
| enum class | Kind { STATED , UNCONSTRAINED , UNKNOWN } |
| Whether the rule states a grid, imposes none, or does not know it. More... | |
Public Member Functions | |
| constexpr bool | grid_known () const noexcept |
| Tests whether the rule says anything about the grid: a stated one, or none at all. | |
| std::optional< Decimal64 > | tick_at (const Decimal64 &price) const |
| Returns the tick size at a price. | |
| std::optional< bool > | on_tick (const Decimal64 &price) const |
| Tests whether a price is on the grid. | |
| std::optional< Decimal64 > | round_to_tick (const Decimal64 &price, OrderSide side) const |
| Rounds a price to its band's tick in the order's favour: a buy rounds down, a sell up. | |
Static Public Member Functions | |
| static PriceRule | krx_equity () |
| Returns the KRX cash-equity tick table (January 2023 revision). | |
| static PriceRule | unconstrained () |
| Returns a rule with no grid, for a market quoted in free decimals. | |
| static PriceRule | unknown (std::string reason) |
| Returns a rule that knows no grid and refuses to round. | |
Public Attributes | |
| Kind | kind_ {Kind::UNKNOWN} |
| The kind of rule; UNKNOWN by default, so an unset rule refuses to round. | |
| std::vector< TickBand > | bands_ |
| The bands, ascending by from_; empty unless kind_ is STATED. | |
| std::string | source_ |
| Where the table came from and its revision, or why there is none. | |
The price grid (tick sizes) an instrument's order prices must sit on.
A broker states at most the tick at one price, not the ladder, so the library maintains these tables (source_ names the table and its revision); replace a rule if the exchange revises its grid. A rule of kind UNKNOWN refuses to check or round a price. A custom table needs positive ticks and bands sorted by from_.
Definition at line 150 of file instrument.hpp.
|
strong |
Whether the rule states a grid, imposes none, or does not know it.
| Enumerator | |
|---|---|
| STATED | bands_ describe the market's grid. |
| UNCONSTRAINED | The market imposes no grid (free decimals). |
| UNKNOWN | The library has no grid for this instrument (for example a KRX ETF or ETN) and will not guess one. |
Definition at line 152 of file instrument.hpp.
|
inlineconstexprnoexcept |
Tests whether the rule says anything about the grid: a stated one, or none at all.
Definition at line 175 of file instrument.hpp.
Referenced by on_tick(), and round_to_tick().
|
inlinestatic |
Returns the KRX cash-equity tick table (January 2023 revision).
Definition at line 266 of file instrument.hpp.
Referenced by algotradelib::price_rule_for().
|
inline |
Tests whether a price is on the grid.
| price | The price. |
Definition at line 210 of file instrument.hpp.
Referenced by algotradelib::strategy::Price::checked(), and algotradelib::strategy::reconcile().
|
inline |
Rounds a price to its band's tick in the order's favour: a buy rounds down, a sell up.
The tick is the one at price; a rounded price that crosses into the next band is not re-rounded. That is correct for the KRX table; with a custom table whose band boundaries are not multiples of both ticks, check the result with on_tick.
| price | The price. |
| side | The side of the order. |
Definition at line 237 of file instrument.hpp.
Referenced by algotradelib::analytics::round_scalar_to_tick(), and algotradelib::strategy::Price::rounded().
Returns the tick size at a price.
| price | The price. |
Definition at line 192 of file instrument.hpp.
Referenced by algotradelib::backtest::SlippageModel::apply(), on_tick(), and round_to_tick().
|
inlinestatic |
Returns a rule with no grid, for a market quoted in free decimals.
Definition at line 286 of file instrument.hpp.
Referenced by algotradelib::price_rule_for().
|
inlinestatic |
Returns a rule that knows no grid and refuses to round.
| reason | Why there is no grid; stored in source_. |
Definition at line 298 of file instrument.hpp.
Referenced by algotradelib::price_rule_for().
| std::vector<TickBand> algotradelib::PriceRule::bands_ |
The bands, ascending by from_; empty unless kind_ is STATED.
Definition at line 167 of file instrument.hpp.
Referenced by krx_equity(), and tick_at().
| Kind algotradelib::PriceRule::kind_ {Kind::UNKNOWN} |
The kind of rule; UNKNOWN by default, so an unset rule refuses to round.
Definition at line 165 of file instrument.hpp.
Referenced by grid_known(), krx_equity(), unconstrained(), and unknown().
| std::string algotradelib::PriceRule::source_ |
Where the table came from and its revision, or why there is none.
Definition at line 169 of file instrument.hpp.
Referenced by krx_equity(), unconstrained(), and unknown().