perf: reuse expression scope identifiers and dates
This commit is contained in:
@@ -4,7 +4,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use ahash::{AHashMap, AHashSet};
|
use ahash::{AHashMap, AHashSet};
|
||||||
use chrono::{Datelike, Duration, NaiveDate, NaiveDateTime, NaiveTime, Timelike};
|
use chrono::{Datelike, Duration, NaiveDate, NaiveDateTime, NaiveTime, Timelike};
|
||||||
use rhai::{AST, Dynamic, Engine, Map, Scope};
|
use rhai::{AST, Dynamic, Engine, ImmutableString, Map, Scope};
|
||||||
|
|
||||||
use crate::broker::{MatchingType, RebalanceCashMode, SlippageModel};
|
use crate::broker::{MatchingType, RebalanceCashMode, SlippageModel};
|
||||||
use crate::cost::ChinaAShareCostModel;
|
use crate::cost::ChinaAShareCostModel;
|
||||||
@@ -626,6 +626,9 @@ impl ProjectedOrderValueResult {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct DayExpressionState {
|
struct DayExpressionState {
|
||||||
date: NaiveDate,
|
date: NaiveDate,
|
||||||
|
trade_date_text: ImmutableString,
|
||||||
|
decision_date_text: ImmutableString,
|
||||||
|
execution_date_text: ImmutableString,
|
||||||
signal_open: f64,
|
signal_open: f64,
|
||||||
signal_close: f64,
|
signal_close: f64,
|
||||||
benchmark_open: f64,
|
benchmark_open: f64,
|
||||||
@@ -925,13 +928,13 @@ impl<'a> SelectiveExpressionScope<'a> {
|
|||||||
|
|
||||||
fn push<T: Into<Dynamic>>(&mut self, name: &str, value: T) -> &mut Self {
|
fn push<T: Into<Dynamic>>(&mut self, name: &str, value: T) -> &mut Self {
|
||||||
if self.requires(name) {
|
if self.requires(name) {
|
||||||
self.inner.push_dynamic(name.to_string(), value.into());
|
self.inner.push_dynamic(name, value.into());
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_required<T: Into<Dynamic>>(&mut self, name: &str, value: T) -> &mut Self {
|
fn push_required<T: Into<Dynamic>>(&mut self, name: &str, value: T) -> &mut Self {
|
||||||
self.inner.push_dynamic(name.to_string(), value.into());
|
self.inner.push_dynamic(name, value.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3895,6 +3898,9 @@ impl PlatformExprStrategy {
|
|||||||
|
|
||||||
Ok(DayExpressionState {
|
Ok(DayExpressionState {
|
||||||
date,
|
date,
|
||||||
|
trade_date_text: date.to_string().into(),
|
||||||
|
decision_date_text: ctx.decision_date.to_string().into(),
|
||||||
|
execution_date_text: ctx.execution_date.to_string().into(),
|
||||||
signal_open,
|
signal_open,
|
||||||
signal_close,
|
signal_close,
|
||||||
benchmark_open,
|
benchmark_open,
|
||||||
@@ -4541,14 +4547,11 @@ impl PlatformExprStrategy {
|
|||||||
include_process_event_counts: bool,
|
include_process_event_counts: bool,
|
||||||
) -> Scope<'static> {
|
) -> Scope<'static> {
|
||||||
let mut scope = SelectiveExpressionScope::new(scope_identifiers);
|
let mut scope = SelectiveExpressionScope::new(scope_identifiers);
|
||||||
let trade_date = day.date.format("%Y-%m-%d").to_string();
|
scope.push("trade_date", day.trade_date_text.clone());
|
||||||
let decision_date = ctx.decision_date.format("%Y-%m-%d").to_string();
|
scope.push("current_date", day.trade_date_text.clone());
|
||||||
let execution_date = ctx.execution_date.format("%Y-%m-%d").to_string();
|
scope.push("date", day.trade_date_text.clone());
|
||||||
scope.push("trade_date", trade_date.clone());
|
scope.push("decision_date", day.decision_date_text.clone());
|
||||||
scope.push("current_date", trade_date.clone());
|
scope.push("execution_date", day.execution_date_text.clone());
|
||||||
scope.push("date", trade_date);
|
|
||||||
scope.push("decision_date", decision_date);
|
|
||||||
scope.push("execution_date", execution_date);
|
|
||||||
scope.push("signal_open", day.signal_open);
|
scope.push("signal_open", day.signal_open);
|
||||||
scope.push("signal_close", day.signal_close);
|
scope.push("signal_close", day.signal_close);
|
||||||
scope.push("benchmark_open", day.benchmark_open);
|
scope.push("benchmark_open", day.benchmark_open);
|
||||||
|
|||||||
Reference in New Issue
Block a user