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...
|
| | 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.
|
| NextBarFillModel | with_market_price (std::string name, MarketPriceFunction price) const |
| | Returns a copy of this model that prices market orders by a rule instead of the next bar's open.
|
| NextBarFillModel | with_market_price (MarketPrice price) const |
| | Returns a copy of this model that prices market orders by a rule the library ships.
|
| const std::string & | market_price_rule () const noexcept |
| | Returns the market-price rule's name.
|
| bool | has_market_price_rule () const noexcept |
| | Tests whether a market-price rule is set.
|
| const std::optional< MarketPrice > & | library_market_price () const noexcept |
| | Returns which of the library's market-price rules prices market orders.
|
| 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 std::optional< Decimal64 > &decision_price=std::nullopt, const std::optional< std::chrono::system_clock::time_point > &decision_price_at=std::nullopt, const std::optional< std::chrono::system_clock::time_point > &decided_at=std::nullopt) const |
| | Decides whether an order trades against a bar, and at what price and cost.
|
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).
Definition at line 142 of file fill.hpp.
| FillDecision algotradelib::backtest::NextBarFillModel::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 std::optional< Decimal64 > & | decision_price = std::nullopt, |
|
|
const std::optional< std::chrono::system_clock::time_point > & | decision_price_at = std::nullopt, |
|
|
const std::optional< std::chrono::system_clock::time_point > & | decided_at = std::nullopt ) const |
|
inline |
Decides whether an order trades against a bar, and at what price and cost.
- Market: the bar's open (its close if it has no open), or the market-price rule's price when one is set (with_market_price).
- Limit: only if the bar reached the limit (low at or below a buy limit, high at or above a sell limit). Credited the limit, or under AT_OPEN_IF_BETTER the open if better; the credit is kept within the bar's range and never through the limit, even after slippage.
- Stop-limit: dormant until the bar reaches the trigger (a sell stop when the low reaches it, a buy stop when the high does). Released at the open, it is priced as a limit. Released inside the bar, it fills only when the bar proves a price after the release: at the worst bar price the limit allows if the limit was marketable at the trigger, at the limit if the close is through the limit; otherwise it rests. No favourable slippage applies after an intrabar release.
Slippage, then commission and any sale tax, are applied to a fill. The execution is stamped at next.period_end_.
- Parameters
-
| 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. |
| decision_price | The instrument's last price when the order was decided, for a market-price rule. |
| decision_price_at | When that price was observed, for a market-price rule. |
| decided_at | When the order was decided, for a market-price rule. |
- Returns
- The decision. A market-price rule's price that is not positive is a costing error (code market_price_not_positive), so the replay halts. A stop-limit order not yet released without both a trigger and a limit price neither trades nor rests (a released stop must still have its limit price).
Definition at line 393 of file fill.hpp.
Returns a copy of this model that prices market orders by a rule instead of the next bar's open.
The rule is called for every order the model does not price against a limit (limit_priced false), with the order, the instrument's previous bar and the bar it fills against. Its price is then slipped, costed and taxed as an open would be, and the fill is stamped at next.period_end_ and charged on the fill bar's date. When it returns nothing, a DAY order rests for a later bar of its session and any other order is withdrawn. Limit and stop-limit orders are untouched.
The rule may look at next_ beyond its open (its close, high or low): that is a choice the rule makes, not one the model can check, and the report names the rule so a reader can judge it.
- Parameters
-
- Returns
- The new model.
- Exceptions
-
| std::invalid_argument | if the name is empty or the rule is empty. |
Definition at line 240 of file fill.hpp.