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) => {
|
||||
|
||||
@@ -108,7 +108,7 @@ pub fn built_in_strategy_manual() -> StrategyAiManual {
|
||||
},
|
||||
ManualSection {
|
||||
title: "execution.matching_type / execution.slippage".to_string(),
|
||||
detail: "设置撮合模式和滑点。支持 execution.matching_type(\"next_tick_last\" | \"current_bar_close\" | \"next_bar_open\" | \"open_auction\"),其中 open_auction 使用当日集合竞价开盘价 day_open 进行撮合,且不额外施加滑点,并按竞价成交量而不是盘口一档流动性限制成交;滑点支持 execution.slippage(\"none\") / execution.slippage(\"price_ratio\", 0.001) / execution.slippage(\"tick_size\", 1)。".to_string(),
|
||||
detail: "设置撮合模式和滑点。支持 execution.matching_type(\"next_tick_last\" | \"vwap\" | \"current_bar_close\" | \"next_bar_open\" | \"open_auction\")。其中 vwap 会在盘中执行价链路上聚合多笔成交为单条 VWAP 成交;open_auction 使用当日集合竞价开盘价 day_open 进行撮合,且不额外施加滑点,并按竞价成交量而不是盘口一档流动性限制成交;滑点支持 execution.slippage(\"none\") / execution.slippage(\"price_ratio\", 0.001) / execution.slippage(\"tick_size\", 1)。".to_string(),
|
||||
},
|
||||
ManualSection {
|
||||
title: "when / unless / else".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user