![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
The fill model: market orders at the next bar's open, limit orders when the next bar's range reaches them, stop-limit orders once released. More...
#include <algotradelib/src/backtest/fill.hpp>
Public Member Functions | |
| NextBarFillModel (CommissionModel commission=CommissionModel::none(), SlippageModel slippage=SlippageModel::none(), LimitFillPrice limit_price=LimitFillPrice::AT_LIMIT) | |
| Constructs a model with a flat commission. | |
| NextBarFillModel (CommissionPolicy commission, SlippageModel slippage=SlippageModel::none(), LimitFillPrice limit_price=LimitFillPrice::AT_LIMIT) | |
| Constructs a model with a commission policy, which may resolve a schedule per execution. | |
| const CommissionPolicy & | commission () const noexcept |
| Returns the commission policy. | |
| const SlippageModel & | slippage () const noexcept |
| Returns the slippage model. | |
| LimitFillPrice | limit_price () const noexcept |
| Returns which price a filled limit order is credited. | |
| NextBarFillModel | with_sell_tax (SellTax tax) const |
| Returns a copy of this model that charges a tax on sales. | |
| const std::optional< SellTax > & | sell_tax () const noexcept |
| Returns the tax on sales. | |
| FillDecision | decide (const strategy::PlannedOrder &order, const strategy::BarEvent &next, const PriceRule &rule, const Date &date, const std::optional< Date > &open_date=std::nullopt, bool released=false) const |
| Decides whether an order trades against a bar, and at what price and cost. | |
Static Public Member Functions | |
| static constexpr bool | limit_priced (OrderType type) noexcept |
| Tests whether the model prices an order type against its limit (a limit order, and a stop-limit once released). | |
| static bool | rests_unfilled (const strategy::PlannedOrder &order) noexcept |
| Tests whether an order that did not fill stays queued for a later bar of its session. | |
The fill model: market orders at the next bar's open, limit orders when the next bar's range reaches them, stop-limit orders once released.
Works the same for any bar interval. Volume is not consulted: a fill is never partial or capped by what traded (the report states this).
|
inlineexplicit |
Constructs a model with a flat commission.
| commission | The commission model, charged on every execution. |
| slippage | The slippage model. |
| limit_price | Which price a filled limit order is credited. |
Definition at line 76 of file fill.hpp.
Referenced by with_sell_tax().
|
inlineexplicit |
|
inlinenoexcept |
Returns the commission policy.
Definition at line 104 of file fill.hpp.
Referenced by NextBarFillModel(), and NextBarFillModel().
|
inline |
Decides whether an order trades against a bar, and at what price and cost.
Slippage, then commission and any sale tax, are applied to a fill. The execution is stamped at next.period_end_.
| order | The queued order. |
| next | The bar after the one the order was decided on. |
| rule | The instrument's price grid, for tick slippage. |
| date | The market-local trading date of the fill, for the commission rate (see SessionWindow::local_date). |
| open_date | The market-local date of the bar's open, if known; used instead of date for a fill priced at the open. For a fill inside a multi-day bar date is used, which can be a later day than the fill. |
| released | Whether an earlier bar already released this stop-limit order. |
|
inlinenoexcept |
Returns which price a filled limit order is credited.
Definition at line 116 of file fill.hpp.
Referenced by NextBarFillModel(), and NextBarFillModel().
|
inlinestaticconstexprnoexcept |
Tests whether the model prices an order type against its limit (a limit order, and a stop-limit once released).
| type | The order type. |
Definition at line 151 of file fill.hpp.
Referenced by decide(), and rests_unfilled().
|
inlinestaticnoexcept |
Tests whether an order that did not fill stays queued for a later bar of its session.
Only DAY limit and stop-limit orders rest; immediate-or-cancel, fill-or-kill and market orders do not. Backtester withdraws a resting DAY order when its session ends (on daily bars, after one bar).
| order | The order. |
Definition at line 178 of file fill.hpp.
Referenced by decide().
|
inlinenoexcept |
|
inlinenoexcept |
Returns the slippage model.
Definition at line 110 of file fill.hpp.
Referenced by NextBarFillModel(), and NextBarFillModel().
|
inline |
Returns a copy of this model that charges a tax on sales.
The library has no tax rate of its own (Korean securities transaction tax changes yearly); one rate applies to the whole replay. The tax is truncated to whole currency units and reported apart from commission (Execution::tax_, Report::tax_paid_). Only sales of instruments in tax.country_ pay it; exempt instruments (Korean ETFs and ETNs) need a replay without it.
| tax | The rate and market. |
| std::invalid_argument | if the rate is below 0 or not below 1. |