Expose richer calendar fields to platform expressions
This commit is contained in:
@@ -126,8 +126,13 @@ struct DayExpressionState {
|
|||||||
refresh_rate: i64,
|
refresh_rate: i64,
|
||||||
year: i64,
|
year: i64,
|
||||||
month: i64,
|
month: i64,
|
||||||
|
quarter: i64,
|
||||||
day_of_month: i64,
|
day_of_month: i64,
|
||||||
|
day_of_year: i64,
|
||||||
|
week_of_year: i64,
|
||||||
weekday: i64,
|
weekday: i64,
|
||||||
|
is_month_start: bool,
|
||||||
|
is_month_end: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -574,6 +579,8 @@ impl PlatformExprStrategy {
|
|||||||
let market_value = ctx.portfolio.positions().values().map(|position| position.market_value()).sum::<f64>();
|
let market_value = ctx.portfolio.positions().values().map(|position| position.market_value()).sum::<f64>();
|
||||||
let total_equity = cash + market_value;
|
let total_equity = cash + market_value;
|
||||||
let current_exposure = if total_equity > 0.0 { market_value / total_equity } else { 0.0 };
|
let current_exposure = if total_equity > 0.0 { market_value / total_equity } else { 0.0 };
|
||||||
|
let next_day = date + Duration::days(1);
|
||||||
|
let is_month_end = next_day.month() != date.month();
|
||||||
|
|
||||||
Ok(DayExpressionState {
|
Ok(DayExpressionState {
|
||||||
signal_close,
|
signal_close,
|
||||||
@@ -595,8 +602,13 @@ impl PlatformExprStrategy {
|
|||||||
refresh_rate: self.config.refresh_rate as i64,
|
refresh_rate: self.config.refresh_rate as i64,
|
||||||
year: date.year() as i64,
|
year: date.year() as i64,
|
||||||
month: date.month() as i64,
|
month: date.month() as i64,
|
||||||
|
quarter: ((date.month0() / 3) + 1) as i64,
|
||||||
day_of_month: date.day() as i64,
|
day_of_month: date.day() as i64,
|
||||||
|
day_of_year: date.ordinal() as i64,
|
||||||
|
week_of_year: date.iso_week().week() as i64,
|
||||||
weekday: date.weekday().number_from_monday() as i64,
|
weekday: date.weekday().number_from_monday() as i64,
|
||||||
|
is_month_start: date.day() == 1,
|
||||||
|
is_month_end,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -694,8 +706,13 @@ impl PlatformExprStrategy {
|
|||||||
scope.push("refresh_rate", day.refresh_rate);
|
scope.push("refresh_rate", day.refresh_rate);
|
||||||
scope.push("year", day.year);
|
scope.push("year", day.year);
|
||||||
scope.push("month", day.month);
|
scope.push("month", day.month);
|
||||||
|
scope.push("quarter", day.quarter);
|
||||||
scope.push("day_of_month", day.day_of_month);
|
scope.push("day_of_month", day.day_of_month);
|
||||||
|
scope.push("day_of_year", day.day_of_year);
|
||||||
|
scope.push("week_of_year", day.week_of_year);
|
||||||
scope.push("weekday", day.weekday);
|
scope.push("weekday", day.weekday);
|
||||||
|
scope.push("is_month_start", day.is_month_start);
|
||||||
|
scope.push("is_month_end", day.is_month_end);
|
||||||
if let Some(stock) = stock {
|
if let Some(stock) = stock {
|
||||||
scope.push("symbol", stock.symbol.clone());
|
scope.push("symbol", stock.symbol.clone());
|
||||||
scope.push("market_cap", stock.market_cap);
|
scope.push("market_cap", stock.market_cap);
|
||||||
|
|||||||
Reference in New Issue
Block a user