允许运行态追加结算交易日历
This commit is contained in:
@@ -1188,6 +1188,16 @@ pub struct DataSet {
|
||||
}
|
||||
|
||||
impl DataSet {
|
||||
pub fn with_additional_trading_dates(
|
||||
mut self,
|
||||
dates: impl IntoIterator<Item = NaiveDate>,
|
||||
) -> Self {
|
||||
let mut calendar_dates = self.calendar.days().to_vec();
|
||||
calendar_dates.extend(dates);
|
||||
self.calendar = Arc::new(TradingCalendar::new(calendar_dates));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn from_components(
|
||||
instruments: Vec<Instrument>,
|
||||
market: Vec<DailyMarketSnapshot>,
|
||||
@@ -3869,6 +3879,37 @@ mod tests {
|
||||
assert_eq!(run_data.execution_quote_count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn additional_terminal_calendar_dates_are_isolated_from_shared_market_data() {
|
||||
let date = NaiveDate::parse_from_str("2025-01-02", "%Y-%m-%d").unwrap();
|
||||
let next_date = NaiveDate::parse_from_str("2025-01-03", "%Y-%m-%d").unwrap();
|
||||
let data = DataSet::from_components(
|
||||
vec![Instrument {
|
||||
symbol: "000001.SZ".to_string(),
|
||||
name: "平安银行".to_string(),
|
||||
board: "SZ".to_string(),
|
||||
round_lot: 100,
|
||||
listed_at: None,
|
||||
delisted_at: None,
|
||||
status: "active".to_string(),
|
||||
}],
|
||||
vec![market_row("2025-01-02", 10.0, 1_000_000)],
|
||||
Vec::new(),
|
||||
Vec::new(),
|
||||
vec![benchmark_row("2025-01-02", 12.0)],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let run_data = data
|
||||
.clone()
|
||||
.with_additional_trading_dates([next_date, next_date]);
|
||||
|
||||
assert_eq!(data.next_trading_date(date, 1), None);
|
||||
assert_eq!(run_data.next_trading_date(date, 1), Some(next_date));
|
||||
assert!(run_data.market(next_date, "000001.SZ").is_none());
|
||||
assert!(Arc::ptr_eq(&data.market_by_date, &run_data.market_by_date));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn execution_quotes_use_stable_k_way_merge_and_release_by_date() {
|
||||
let date = NaiveDate::parse_from_str("2025-01-02", "%Y-%m-%d").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user