共享回测分钟报价索引
This commit is contained in:
@@ -1173,7 +1173,7 @@ pub struct DataSet {
|
|||||||
candidate_by_date: Arc<BTreeMap<NaiveDate, Vec<CandidateEligibility>>>,
|
candidate_by_date: Arc<BTreeMap<NaiveDate, Vec<CandidateEligibility>>>,
|
||||||
candidate_symbol_ids_by_date: Arc<BTreeMap<NaiveDate, Vec<u32>>>,
|
candidate_symbol_ids_by_date: Arc<BTreeMap<NaiveDate, Vec<u32>>>,
|
||||||
corporate_actions_by_date: Arc<BTreeMap<NaiveDate, Vec<CorporateAction>>>,
|
corporate_actions_by_date: Arc<BTreeMap<NaiveDate, Vec<CorporateAction>>>,
|
||||||
execution_quotes_by_date: HashMap<NaiveDate, HashMap<String, Vec<IntradayExecutionQuote>>>,
|
execution_quotes_by_date: Arc<HashMap<NaiveDate, HashMap<String, Vec<IntradayExecutionQuote>>>>,
|
||||||
order_book_depth_index: Arc<HashMap<(NaiveDate, String), Vec<IntradayOrderBookDepthLevel>>>,
|
order_book_depth_index: Arc<HashMap<(NaiveDate, String), Vec<IntradayOrderBookDepthLevel>>>,
|
||||||
benchmark_by_date: Arc<BTreeMap<NaiveDate, BenchmarkSnapshot>>,
|
benchmark_by_date: Arc<BTreeMap<NaiveDate, BenchmarkSnapshot>>,
|
||||||
market_series_by_symbol: Arc<AHashMap<String, Arc<SymbolPriceSeries>>>,
|
market_series_by_symbol: Arc<AHashMap<String, Arc<SymbolPriceSeries>>>,
|
||||||
@@ -1463,7 +1463,7 @@ impl DataSet {
|
|||||||
candidate_by_date: Arc::new(candidate_by_date),
|
candidate_by_date: Arc::new(candidate_by_date),
|
||||||
candidate_symbol_ids_by_date: Arc::new(candidate_symbol_ids_by_date),
|
candidate_symbol_ids_by_date: Arc::new(candidate_symbol_ids_by_date),
|
||||||
corporate_actions_by_date: Arc::new(corporate_actions_by_date),
|
corporate_actions_by_date: Arc::new(corporate_actions_by_date),
|
||||||
execution_quotes_by_date,
|
execution_quotes_by_date: Arc::new(execution_quotes_by_date),
|
||||||
order_book_depth_index: Arc::new(order_book_depth_index),
|
order_book_depth_index: Arc::new(order_book_depth_index),
|
||||||
benchmark_by_date: Arc::new(benchmark_by_date),
|
benchmark_by_date: Arc::new(benchmark_by_date),
|
||||||
market_series_by_symbol: Arc::new(market_series_by_symbol),
|
market_series_by_symbol: Arc::new(market_series_by_symbol),
|
||||||
@@ -1648,8 +1648,9 @@ impl DataSet {
|
|||||||
.push(quote);
|
.push(quote);
|
||||||
}
|
}
|
||||||
let mut added = 0usize;
|
let mut added = 0usize;
|
||||||
|
let execution_quotes_by_date = Arc::make_mut(&mut self.execution_quotes_by_date);
|
||||||
for (date, rows_by_symbol) in grouped {
|
for (date, rows_by_symbol) in grouped {
|
||||||
let target_by_symbol = self.execution_quotes_by_date.entry(date).or_default();
|
let target_by_symbol = execution_quotes_by_date.entry(date).or_default();
|
||||||
for (symbol, mut incoming) in rows_by_symbol {
|
for (symbol, mut incoming) in rows_by_symbol {
|
||||||
incoming.sort_by_key(|quote| quote.timestamp);
|
incoming.sort_by_key(|quote| quote.timestamp);
|
||||||
incoming.dedup_by(|left, right| left.timestamp == right.timestamp);
|
incoming.dedup_by(|left, right| left.timestamp == right.timestamp);
|
||||||
@@ -1743,7 +1744,7 @@ impl DataSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_execution_quotes_on_date(&mut self, date: NaiveDate) -> usize {
|
pub fn remove_execution_quotes_on_date(&mut self, date: NaiveDate) -> usize {
|
||||||
self.execution_quotes_by_date
|
Arc::make_mut(&mut self.execution_quotes_by_date)
|
||||||
.remove(&date)
|
.remove(&date)
|
||||||
.map(|rows_by_symbol| rows_by_symbol.into_values().map(|rows| rows.len()).sum())
|
.map(|rows_by_symbol| rows_by_symbol.into_values().map(|rows| rows.len()).sum())
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@@ -3859,6 +3860,10 @@ mod tests {
|
|||||||
&data.benchmark_by_date,
|
&data.benchmark_by_date,
|
||||||
&run_data.benchmark_by_date
|
&run_data.benchmark_by_date
|
||||||
));
|
));
|
||||||
|
assert!(Arc::ptr_eq(
|
||||||
|
&data.execution_quotes_by_date,
|
||||||
|
&run_data.execution_quotes_by_date
|
||||||
|
));
|
||||||
|
|
||||||
run_data.add_execution_quotes(vec![IntradayExecutionQuote {
|
run_data.add_execution_quotes(vec![IntradayExecutionQuote {
|
||||||
date,
|
date,
|
||||||
@@ -3877,6 +3882,10 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(data.execution_quote_count(), 0);
|
assert_eq!(data.execution_quote_count(), 0);
|
||||||
assert_eq!(run_data.execution_quote_count(), 1);
|
assert_eq!(run_data.execution_quote_count(), 1);
|
||||||
|
assert!(!Arc::ptr_eq(
|
||||||
|
&data.execution_quotes_by_date,
|
||||||
|
&run_data.execution_quotes_by_date
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user