Add open auction matching mode
This commit is contained in:
@@ -40,6 +40,7 @@ struct TargetConstraint {
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum MatchingType {
|
||||
OpenAuction,
|
||||
CurrentBarClose,
|
||||
NextBarOpen,
|
||||
NextTickLast,
|
||||
@@ -1270,6 +1271,7 @@ where
|
||||
date,
|
||||
symbol: position.symbol.clone(),
|
||||
field: match field {
|
||||
PriceField::DayOpen => "day_open",
|
||||
PriceField::Open => "open",
|
||||
PriceField::Close => "close",
|
||||
PriceField::Last => "last",
|
||||
@@ -1611,6 +1613,7 @@ where
|
||||
|
||||
fn price_field_name(field: PriceField) -> &'static str {
|
||||
match field {
|
||||
PriceField::DayOpen => "day_open",
|
||||
PriceField::Open => "open",
|
||||
PriceField::Close => "close",
|
||||
PriceField::Last => "last",
|
||||
|
||||
@@ -81,6 +81,7 @@ pub enum DataSetError {
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum PriceField {
|
||||
DayOpen,
|
||||
Open,
|
||||
Close,
|
||||
Last,
|
||||
@@ -115,6 +116,7 @@ pub struct DailyMarketSnapshot {
|
||||
impl DailyMarketSnapshot {
|
||||
pub fn price(&self, field: PriceField) -> f64 {
|
||||
match field {
|
||||
PriceField::DayOpen => self.day_open,
|
||||
PriceField::Open => self.open,
|
||||
PriceField::Close => self.close,
|
||||
PriceField::Last => self.last_price,
|
||||
@@ -488,6 +490,7 @@ impl SymbolPriceSeries {
|
||||
|
||||
fn values_for(&self, field: PriceField) -> &[f64] {
|
||||
match field {
|
||||
PriceField::DayOpen => &self.opens,
|
||||
PriceField::Open => &self.opens,
|
||||
PriceField::Close => &self.closes,
|
||||
PriceField::Last => &self.last_prices,
|
||||
@@ -504,6 +507,7 @@ impl SymbolPriceSeries {
|
||||
|
||||
fn prefix_for(&self, field: PriceField) -> &[f64] {
|
||||
match field {
|
||||
PriceField::DayOpen => &self.open_prefix,
|
||||
PriceField::Open => &self.open_prefix,
|
||||
PriceField::Close => &self.close_prefix,
|
||||
PriceField::Last => &self.last_prefix,
|
||||
@@ -561,7 +565,7 @@ impl BenchmarkPriceSeries {
|
||||
}
|
||||
let start = end - lookback;
|
||||
let prefix = match field {
|
||||
PriceField::Open => &self.open_prefix,
|
||||
PriceField::DayOpen | PriceField::Open => &self.open_prefix,
|
||||
PriceField::Close | PriceField::Last => &self.close_prefix,
|
||||
};
|
||||
let sum = prefix[end] - prefix[start];
|
||||
@@ -959,6 +963,9 @@ impl DataSet {
|
||||
.market_series_by_symbol
|
||||
.get(symbol)
|
||||
.and_then(|series| series.decision_volume_rolling_average(date, lookback)),
|
||||
"day_open" | "dayopen" => {
|
||||
self.market_moving_average(date, symbol, lookback, PriceField::DayOpen)
|
||||
}
|
||||
"open" => self.market_moving_average(date, symbol, lookback, PriceField::Open),
|
||||
"last" | "last_price" => {
|
||||
self.market_moving_average(date, symbol, lookback, PriceField::Last)
|
||||
|
||||
@@ -264,6 +264,7 @@ impl PortfolioState {
|
||||
let price = data.price(date, &position.symbol, field).ok_or_else(|| {
|
||||
DataSetError::MissingSnapshot {
|
||||
kind: match field {
|
||||
PriceField::DayOpen => "day open price",
|
||||
PriceField::Open => "open price",
|
||||
PriceField::Close => "close price",
|
||||
PriceField::Last => "last price",
|
||||
|
||||
@@ -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\"),以及 execution.slippage(\"none\") / execution.slippage(\"price_ratio\", 0.001) / execution.slippage(\"tick_size\", 1)。".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(),
|
||||
},
|
||||
ManualSection {
|
||||
title: "when / unless / else".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user