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

Slippage: how far a fill price moves against the order (a buy pays more, a sell gets less). More...

#include <algotradelib/src/backtest/cost.hpp>

Collaboration diagram for algotradelib::backtest::SlippageModel:

Public Member Functions

std::optional< std::pair< Decimal64, Decimal64 > > apply (const Decimal64 &price, OrderSide side, const PriceRule &rule) const
 Moves a price against the order.

Static Public Member Functions

static SlippageModel none ()
 Returns a model with no slippage (the report says so).
static SlippageModel of_basis_points (Decimal64 points)
 Returns a basis-point slippage model.
static SlippageModel of_ticks (int count)
 Returns a tick slippage model.

Public Attributes

Decimal64 basis_points_ {Decimal64::parse("0")}
 The price given up per execution, in ten-thousandths of the price.
int ticks_ {0}
 Grid steps given up per execution, each a step to the next grid price against the order.

Detailed Description

Slippage: how far a fill price moves against the order (a buy pays more, a sell gets less).

basis_points_ is a fraction of the price in ten-thousandths; ticks_ walks that many steps along the instrument's grid, one at a time, so a walk that crosses into another band takes that band's tick from there on. Both apply when both are set: the ticks are walked from the price before slippage, and the two amounts added.

Definition at line 425 of file cost.hpp.

Member Function Documentation

◆ apply()

std::optional< std::pair< Decimal64, Decimal64 > > algotradelib::backtest::SlippageModel::apply ( const Decimal64 & price,
OrderSide side,
const PriceRule & rule ) const
inline

Moves a price against the order.

Parameters
priceThe price before slippage.
sideThe order's side.
ruleThe instrument's grid. A buy steps up by the tick at each price; a sell steps down by the tick of the band below each price. From a price on the KRX grid each step reaches the next grid price; from a price off the grid, or with a custom table whose band starts are not multiples of both ticks, it may not (as with PriceRule::round_to_tick). A step the grid has no tick for (an unknown grid, a sell at the first band's start) or that would end at or below zero is not taken.
Returns
The slipped price and the amount given up, or std::nullopt if the arithmetic does not fit.

Definition at line 444 of file cost.hpp.

◆ none()

SlippageModel algotradelib::backtest::SlippageModel::none ( )
inlinestatic

Returns a model with no slippage (the report says so).

Returns
The model.

Definition at line 522 of file cost.hpp.

Referenced by algotradelib::backtest::NextBarFillModel::NextBarFillModel(), and algotradelib::backtest::NextBarFillModel::NextBarFillModel().

◆ of_basis_points()

SlippageModel algotradelib::backtest::SlippageModel::of_basis_points ( Decimal64 points)
inlinestatic

Returns a basis-point slippage model.

Parameters
pointsThe ten-thousandths of the price given up.
Returns
The model.

Definition at line 529 of file cost.hpp.

◆ of_ticks()

SlippageModel algotradelib::backtest::SlippageModel::of_ticks ( int count)
inlinestatic

Returns a tick slippage model.

Parameters
countThe ticks given up; zero or less applies none.
Returns
The model.

Definition at line 540 of file cost.hpp.

Member Data Documentation

◆ basis_points_

Decimal64 algotradelib::backtest::SlippageModel::basis_points_ {Decimal64::parse("0")}

The price given up per execution, in ten-thousandths of the price.

Definition at line 427 of file cost.hpp.

Referenced by apply(), and of_basis_points().

◆ ticks_

int algotradelib::backtest::SlippageModel::ticks_ {0}

Grid steps given up per execution, each a step to the next grid price against the order.

Definition at line 429 of file cost.hpp.

Referenced by apply(), and of_ticks().


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