hftbacktest::backtest::proc

Struct PartialFillExchange

Source
pub struct PartialFillExchange<AT, LM, QM, MD, FM>
where AT: AssetType, LM: LatencyModel, QM: QueueModel<MD>, MD: MarketDepth, FM: FeeModel,
{ /* private fields */ }
Available on crate feature backtest only.
Expand description

The exchange model with partial fills.

Conditions for Full Execution Buy order in the order book

  • Your order price >= the best ask price
  • Your order price > sell trade price

Sell order in the order book

  • Your order price <= the best bid price
  • Your order price < buy trade price

Conditions for Partial Execution Buy order in the order book

  • Filled by (remaining) sell trade quantity: your order is at the front of the queue && your order price == sell trade price

Sell order in the order book

  • Filled by (remaining) buy trade quantity: your order is at the front of the queue && your order price == buy trade price

Liquidity-Taking Order Liquidity-taking orders will be executed based on the quantity of the order book, even though the best price and quantity do not change due to your execution. Be aware that this may cause unrealistic fill simulations if you attempt to execute a large quantity.

General Comment Simulating partial fills accurately can be challenging, as they may indicate potential market impact. The rule of thumb is to ensure that your backtesting results align with your live results. (more comment will be added…)

Implementations§

Source§

impl<AT, LM, QM, MD, FM> PartialFillExchange<AT, LM, QM, MD, FM>
where AT: AssetType, LM: LatencyModel, QM: QueueModel<MD>, MD: MarketDepth, FM: FeeModel,

Source

pub fn new( reader: Reader<Event>, depth: MD, state: State<AT, FM>, order_latency: LM, queue_model: QM, orders_to: OrderBus, orders_from: OrderBus, ) -> Self

Constructs an instance of PartialFillExchange.

Trait Implementations§

Source§

impl<AT, LM, QM, MD, FM> Processor for PartialFillExchange<AT, LM, QM, MD, FM>
where AT: AssetType, LM: LatencyModel, QM: QueueModel<MD>, MD: MarketDepth + L2MarketDepth, FM: FeeModel,

Source§

fn initialize_data(&mut self) -> Result<i64, BacktestError>

Prepares to process the data. This is invoked when the backtesting is initiated. If successful, returns the timestamp of the first event.
Source§

fn process_data(&mut self) -> Result<(i64, i64), BacktestError>

Processes the data. This is invoked when the backtesting time reaches the timestamp of the event to be processed in the data. If successful, returns the timestamp of the next event.
Source§

fn process_recv_order( &mut self, timestamp: i64, _wait_resp_order_id: Option<OrderId>, ) -> Result<bool, BacktestError>

Processes an order upon receipt. This is invoked when the backtesting time reaches the order receipt timestamp. Returns Ok(true) if the order with wait_resp_order_id is received and processed.
Source§

fn earliest_recv_order_timestamp(&self) -> i64

Returns the foremost timestamp at which an order is to be received by this processor.
Source§

fn earliest_send_order_timestamp(&self) -> i64

Returns the foremost timestamp at which an order sent by this processor is to be received by the corresponding processor.

Auto Trait Implementations§

§

impl<AT, LM, QM, MD, FM> Freeze for PartialFillExchange<AT, LM, QM, MD, FM>
where MD: Freeze, LM: Freeze, QM: Freeze, AT: Freeze, FM: Freeze,

§

impl<AT, LM, QM, MD, FM> !RefUnwindSafe for PartialFillExchange<AT, LM, QM, MD, FM>

§

impl<AT, LM, QM, MD, FM> !Send for PartialFillExchange<AT, LM, QM, MD, FM>

§

impl<AT, LM, QM, MD, FM> !Sync for PartialFillExchange<AT, LM, QM, MD, FM>

§

impl<AT, LM, QM, MD, FM> Unpin for PartialFillExchange<AT, LM, QM, MD, FM>
where MD: Unpin, LM: Unpin, QM: Unpin, AT: Unpin, FM: Unpin,

§

impl<AT, LM, QM, MD, FM> !UnwindSafe for PartialFillExchange<AT, LM, QM, MD, FM>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more