Add VWAP matching mode
This commit is contained in:
@@ -56,6 +56,7 @@ pub enum MatchingType {
|
||||
CurrentBarClose,
|
||||
NextBarOpen,
|
||||
NextTickLast,
|
||||
Vwap,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
@@ -69,6 +70,7 @@ pub struct BrokerSimulator<C, R> {
|
||||
cost_model: C,
|
||||
rules: R,
|
||||
board_lot_size: u32,
|
||||
matching_type: MatchingType,
|
||||
execution_price_field: PriceField,
|
||||
slippage_model: SlippageModel,
|
||||
volume_percent: f64,
|
||||
@@ -84,6 +86,7 @@ impl<C, R> BrokerSimulator<C, R> {
|
||||
cost_model,
|
||||
rules,
|
||||
board_lot_size: 100,
|
||||
matching_type: matching_type_from_price_field(PriceField::Open),
|
||||
execution_price_field: PriceField::Open,
|
||||
slippage_model: SlippageModel::None,
|
||||
volume_percent: 0.25,
|
||||
@@ -103,6 +106,7 @@ impl<C, R> BrokerSimulator<C, R> {
|
||||
cost_model,
|
||||
rules,
|
||||
board_lot_size: 100,
|
||||
matching_type: matching_type_from_price_field(execution_price_field),
|
||||
execution_price_field,
|
||||
slippage_model: SlippageModel::None,
|
||||
volume_percent: 0.25,
|
||||
@@ -138,6 +142,11 @@ impl<C, R> BrokerSimulator<C, R> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_matching_type(mut self, matching_type: MatchingType) -> Self {
|
||||
self.matching_type = matching_type;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_slippage_model(mut self, slippage_model: SlippageModel) -> Self {
|
||||
self.slippage_model = slippage_model;
|
||||
self
|
||||
@@ -2404,7 +2413,14 @@ where
|
||||
Some(ExecutionFill {
|
||||
quantity: filled_qty,
|
||||
next_cursor: last_timestamp.unwrap() + Duration::seconds(1),
|
||||
legs,
|
||||
legs: if self.matching_type == MatchingType::Vwap {
|
||||
vec![ExecutionLeg {
|
||||
price: gross_amount / filled_qty as f64,
|
||||
quantity: filled_qty,
|
||||
}]
|
||||
} else {
|
||||
legs
|
||||
},
|
||||
unfilled_reason: if filled_qty < requested_qty {
|
||||
budget_block_reason.or(if saw_quote_after_cursor {
|
||||
Some("intraday quote liquidity exhausted")
|
||||
@@ -2423,6 +2439,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn matching_type_from_price_field(field: PriceField) -> MatchingType {
|
||||
match field {
|
||||
PriceField::DayOpen => MatchingType::OpenAuction,
|
||||
PriceField::Open => MatchingType::NextBarOpen,
|
||||
PriceField::Close => MatchingType::CurrentBarClose,
|
||||
PriceField::Last => MatchingType::NextTickLast,
|
||||
}
|
||||
}
|
||||
|
||||
fn merge_partial_fill_reason(current: Option<String>, next: Option<&str>) -> Option<String> {
|
||||
match (current, next) {
|
||||
(Some(existing), Some(next_reason)) if !existing.contains(next_reason) => {
|
||||
|
||||
Reference in New Issue
Block a user