Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 71 variants Data { name: String, }, Const { value: f64, }, Average { of: Box<Expr>, n: usize, }, Ema { of: Box<Expr>, n: usize, }, Std { of: Box<Expr>, n: usize, }, Rsi { of: Box<Expr>, n: usize, }, PctChange { of: Box<Expr>, n: usize, }, Rise { of: Box<Expr>, n: usize, }, Shift { of: Box<Expr>, n: usize, }, RollingMax { of: Box<Expr>, n: usize, }, RollingMin { of: Box<Expr>, n: usize, }, BollingerMid { of: Box<Expr>, n: usize, }, BollingerUpper { of: Box<Expr>, n: usize, k: f64, }, BollingerLower { of: Box<Expr>, n: usize, k: f64, }, Macd { of: Box<Expr>, fast: usize, slow: usize, }, MacdSignal { of: Box<Expr>, fast: usize, slow: usize, signal: usize, }, MacdHist { of: Box<Expr>, fast: usize, slow: usize, signal: usize, }, DonchianHigh { of: Box<Expr>, n: usize, }, DonchianLow { of: Box<Expr>, n: usize, }, DonchianMid { of: Box<Expr>, n: usize, }, Atr { high: Box<Expr>, low: Box<Expr>, close: Box<Expr>, n: usize, }, Natr { high: Box<Expr>, low: Box<Expr>, close: Box<Expr>, n: usize, }, WillR { high: Box<Expr>, low: Box<Expr>, close: Box<Expr>, n: usize, }, Cci { high: Box<Expr>, low: Box<Expr>, close: Box<Expr>, n: usize, }, StochK { high: Box<Expr>, low: Box<Expr>, close: Box<Expr>, n: usize, }, StochD { high: Box<Expr>, low: Box<Expr>, close: Box<Expr>, n: usize, d: usize, }, AroonUp { high: Box<Expr>, n: usize, }, AroonDown { low: Box<Expr>, n: usize, }, Adx { high: Box<Expr>, low: Box<Expr>, close: Box<Expr>, n: usize, }, PlusDi { high: Box<Expr>, low: Box<Expr>, close: Box<Expr>, n: usize, }, MinusDi { high: Box<Expr>, low: Box<Expr>, close: Box<Expr>, n: usize, }, Obv { close: Box<Expr>, volume: Box<Expr>, }, Mfi { high: Box<Expr>, low: Box<Expr>, close: Box<Expr>, volume: Box<Expr>, n: usize, }, Vwap { high: Box<Expr>, low: Box<Expr>, close: Box<Expr>, volume: Box<Expr>, n: usize, }, Fall { of: Box<Expr>, n: usize, }, IsLargest { of: Box<Expr>, n: usize, }, IsSmallest { of: Box<Expr>, n: usize, }, Sustain { of: Box<Expr>, nwindow: usize, nsatisfy: Option<usize>, }, IsEntry { of: Box<Expr>, }, IsExit { of: Box<Expr>, }, ExitWhen { entry: Box<Expr>, exit: Box<Expr>, }, QuantileRow { of: Box<Expr>, c: f64, }, Winsorize { of: Box<Expr>, lower: f64, upper: f64, }, Zscore { of: Box<Expr>, }, Bucket { of: Box<Expr>, n: usize, }, Demean { of: Box<Expr>, }, Gt { l: Box<Expr>, r: Box<Expr>, }, Lt { l: Box<Expr>, r: Box<Expr>, }, Ge { l: Box<Expr>, r: Box<Expr>, }, Le { l: Box<Expr>, r: Box<Expr>, }, And { l: Box<Expr>, r: Box<Expr>, }, Or { l: Box<Expr>, r: Box<Expr>, }, Not { of: Box<Expr>, }, Add { l: Box<Expr>, r: Box<Expr>, }, Sub { l: Box<Expr>, r: Box<Expr>, }, Mul { l: Box<Expr>, r: Box<Expr>, }, Div { l: Box<Expr>, r: Box<Expr>, }, Neg { of: Box<Expr>, }, Ceil { of: Box<Expr>, }, Rank { of: Box<Expr>, pct: bool, ascending: bool, }, Mask { of: Box<Expr>, by: Box<Expr>, }, NormalizeRow { of: Box<Expr>, }, VolTarget { of: Box<Expr>, prices: Box<Expr>, target: f64, n: usize, }, HoldUntil { entry: Box<Expr>, exit: Box<Expr>, nstocks_limit: Option<usize>, rank: Option<Box<Expr>>, }, Rebalance { of: Box<Expr>, freq: Option<String>, on: Option<Box<Expr>>, }, Neutralize { of: Box<Expr>, by: Vec<Expr>, add_const: bool, }, NeutralizeIndustry { of: Box<Expr>, add_const: bool, }, IndustryRank { of: Box<Expr>, categories: Option<Vec<String>>, }, CapIndustry { of: Box<Expr>, max_weight: f64, }, GroupbyCategory { of: Box<Expr>, agg: String, }, InSector { of: Box<Expr>, name: String, },
}

Variants§

§

Data

A raw input series by name (e.g. close, pe, revenue_growth).

Fields

§name: String
§

Const

A constant scalar value, broadcast across the panel.

Fields

§value: f64
§

Average

Simple moving average of of over n days.

Fields

§of: Box<Expr>
§

Ema

Exponential moving average of of over n days.

Fields

§of: Box<Expr>
§

Std

Rolling standard deviation of of over n days.

Fields

§of: Box<Expr>
§

Rsi

Relative Strength Index of of over n days.

Fields

§of: Box<Expr>
§

PctChange

Percentage change of of over n days.

Fields

§of: Box<Expr>
§

Rise

1 where of rose for n consecutive days, else 0.

Fields

§of: Box<Expr>
§

Shift

of lagged forward by n days.

Fields

§of: Box<Expr>
§

RollingMax

Rolling maximum of of over n days.

Fields

§of: Box<Expr>
§

RollingMin

Rolling minimum of of over n days.

Fields

§of: Box<Expr>
§

BollingerMid

Bollinger mid band: the n-day simple moving average of of.

Fields

§of: Box<Expr>
§

BollingerUpper

Bollinger upper band: sma(of, n) + k * std(of, n) (k defaults to 2).

Fields

§of: Box<Expr>
§

BollingerLower

Bollinger lower band: sma(of, n) - k * std(of, n) (k defaults to 2).

Fields

§of: Box<Expr>
§

Macd

MACD line: ema(of, fast) - ema(of, slow) (defaults 12/26).

Fields

§of: Box<Expr>
§fast: usize
§slow: usize
§

MacdSignal

MACD signal line: signal-day EMA of the MACD line (defaults 12/26/9).

Fields

§of: Box<Expr>
§fast: usize
§slow: usize
§signal: usize
§

MacdHist

MACD histogram: MACD line minus its signal line (defaults 12/26/9).

Fields

§of: Box<Expr>
§fast: usize
§slow: usize
§signal: usize
§

DonchianHigh

Donchian channel upper band: rolling n-day high of of.

Fields

§of: Box<Expr>
§

DonchianLow

Donchian channel lower band: rolling n-day low of of.

Fields

§of: Box<Expr>
§

DonchianMid

Donchian channel mid-line: (rolling_max + rolling_min) / 2 over n days.

Fields

§of: Box<Expr>
§

Atr

Average True Range over n days from high/low/close.

Fields

§high: Box<Expr>
§low: Box<Expr>
§close: Box<Expr>
§

Natr

Normalized ATR (percent) over n days.

Fields

§high: Box<Expr>
§low: Box<Expr>
§close: Box<Expr>
§

WillR

Williams %R over n days.

Fields

§high: Box<Expr>
§low: Box<Expr>
§close: Box<Expr>
§

Cci

Commodity Channel Index over n days.

Fields

§high: Box<Expr>
§low: Box<Expr>
§close: Box<Expr>
§

StochK

Stochastic %K over n days.

Fields

§high: Box<Expr>
§low: Box<Expr>
§close: Box<Expr>
§

StochD

Stochastic %D: d-day average of %K over n days.

Fields

§high: Box<Expr>
§low: Box<Expr>
§close: Box<Expr>
§

AroonUp

Aroon Up over n days from high.

Fields

§high: Box<Expr>
§

AroonDown

Aroon Down over n days from low.

Fields

§low: Box<Expr>
§

Adx

Average Directional Index over n days.

Fields

§high: Box<Expr>
§low: Box<Expr>
§close: Box<Expr>
§

PlusDi

Plus Directional Indicator (+DI) over n days.

Fields

§high: Box<Expr>
§low: Box<Expr>
§close: Box<Expr>
§

MinusDi

Minus Directional Indicator (−DI) over n days.

Fields

§high: Box<Expr>
§low: Box<Expr>
§close: Box<Expr>
§

Obv

On-Balance Volume from close and volume.

Fields

§close: Box<Expr>
§volume: Box<Expr>
§

Mfi

Money Flow Index over n days.

Fields

§high: Box<Expr>
§low: Box<Expr>
§close: Box<Expr>
§volume: Box<Expr>
§

Vwap

Volume-Weighted Average Price over n days from high/low/close/volume.

Fields

§high: Box<Expr>
§low: Box<Expr>
§close: Box<Expr>
§volume: Box<Expr>
§

Fall

1 where of fell for n consecutive days, else 0.

Fields

§of: Box<Expr>
§

IsLargest

1 for the n highest values per row (cross-section), else 0.

Fields

§of: Box<Expr>
§

IsSmallest

1 for the n lowest values per row (cross-section), else 0.

Fields

§of: Box<Expr>
§

Sustain

1 where of held true at least nsatisfy times within the last nwindow rows.

Fields

§of: Box<Expr>
§nwindow: usize
§nsatisfy: Option<usize>
§

IsEntry

1 on the row where of turns false→true (rising edge).

Fields

§of: Box<Expr>
§

IsExit

1 on the row where of turns true→false (falling edge).

Fields

§of: Box<Expr>
§

ExitWhen

Hold true from an entry edge until an exit edge (or the exit panel is true).

Fields

§entry: Box<Expr>
§exit: Box<Expr>
§

QuantileRow

Per-row quantile of of across symbols; collapses to one column (quantile).

Fields

§of: Box<Expr>
§

Winsorize

Per-row winsorize: clip to empirical quantiles lower/upper in [0, 1].

Fields

§of: Box<Expr>
§lower: f64
§upper: f64
§

Zscore

Per-row z-score (x − mean) / std (population std); constant rows → 0.

Fields

§of: Box<Expr>
§

Bucket

Per-row quantile buckets labeled 1..=n (NaN preserved).

Fields

§of: Box<Expr>
§

Demean

Per-row demean: subtract the cross-sectional mean of non-NaN cells.

Fields

§of: Box<Expr>
§

Gt

1 where l is greater than r, else 0.

Fields

§

Lt

1 where l is less than r, else 0.

Fields

§

Ge

1 where l is greater than or equal to r, else 0.

Fields

§

Le

1 where l is less than or equal to r, else 0.

Fields

§

And

Logical AND of two boolean panels.

Fields

§

Or

Logical OR of two boolean panels.

Fields

§

Not

Logical NOT of a boolean panel (NaN is falsy, so not of NaN is 1).

Fields

§of: Box<Expr>
§

Add

Element-wise l + r.

Fields

§

Sub

Element-wise lr.

Fields

§

Mul

Element-wise l × r.

Fields

§

Div

Element-wise l ÷ r.

Fields

§

Neg

Negation (−of).

Fields

§of: Box<Expr>
§

Ceil

Ceiling of of.

Fields

§of: Box<Expr>
§

Rank

Cross-sectional rank of of per row; pct for 0..1 percentile, ascending sets direction.

Fields

§of: Box<Expr>
§pct: bool
§ascending: bool
§

Mask

of kept only where by is true; elsewhere dropped.

Fields

§of: Box<Expr>
§by: Box<Expr>
§

NormalizeRow

Scale each row so gross weight (Σ|w|) is 1; NaN preserved, zero rows unchanged.

Fields

§of: Box<Expr>
§

VolTarget

Scale each row of the weight panel of toward an annualized portfolio-vol target (default 0.1) over a trailing n-return window (default 63) of prices; deleverage only (scale capped at 1).

Fields

§of: Box<Expr>
§prices: Box<Expr>
§target: f64
§

HoldUntil

Stateful rotation: enter on entry, exit on exit, hold up to nstocks_limit (prioritised by rank). Price stops live in the backtest config, not here.

Fields

§entry: Box<Expr>
§exit: Box<Expr>
§nstocks_limit: Option<usize>
§rank: Option<Box<Expr>>
§

Rebalance

Hold of, refreshing on calendar freq (W/ME/QE) or on dates where on is true.

Fields

§of: Box<Expr>
§

Neutralize

Cross-sectionally regress of against the by factors, optionally adding a constant.

Fields

§of: Box<Expr>
§by: Vec<Expr>
§add_const: bool
§

NeutralizeIndustry

Neutralize of within each industry/sector.

Fields

§of: Box<Expr>
§add_const: bool
§

IndustryRank

Rank of within each industry, optionally limited to categories.

Fields

§of: Box<Expr>
§categories: Option<Vec<String>>
§

CapIndustry

Cap each industry’s gross weight in the weight panel of at max_weight (scale that industry’s names down proportionally; max_weight defaults to 0.3).

Fields

§of: Box<Expr>
§max_weight: f64
§

GroupbyCategory

Aggregate of within each industry using agg (e.g. mean).

Fields

§of: Box<Expr>
§

InSector

Boolean mask: 1 where the symbol’s industry equals name (exact, case-sensitive). Shape follows of; symbols missing from the industry map are 0.

Fields

§of: Box<Expr>
§name: String

Trait Implementations§

Source§

impl Debug for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Expr

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnsafeUnpin for Expr

§

impl UnwindSafe for Expr

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.