Struct TradeFeatures

Source
pub struct TradeFeatures {
Show 52 fields pub tick_price: Decimal, pub tick_qty: Decimal, pub tick_direction: i8, pub signed_tick_price: Decimal, pub plus_tick_price: Decimal, pub minus_tick_price: Decimal, pub signed_tick_qty: Decimal, pub plus_tick_qty: Decimal, pub minus_tick_qty: Decimal, pub weighted_tick_price: Decimal, pub log_tick_price: Decimal, pub tick_price_ratio: Decimal, pub tick_price_power: Decimal, pub relative_tick_price: Decimal, pub log_return: Decimal, pub percent_return: Decimal, pub volume_weighted_tick_price: Decimal, pub tick_price_acceleration: Decimal, pub tick_price_momentum: Decimal, pub relative_strength: Decimal, pub tick_price_skewness: Decimal, pub tick_price_kurtosis: Decimal, pub tick_price_volatility: Decimal, pub tick_price_entropy: Decimal, pub tick_size: Decimal, pub tick_type: i8, pub tick_volume: Decimal, pub tick_value: Decimal, pub tick_efficiency: Decimal, pub tick_impact: Decimal, pub tick_aggressiveness: i8, pub tick_frequency: Decimal, pub tick_duration: Decimal, pub tick_intensity: Decimal, pub tick_persistence: Decimal, pub tick_reversion: Decimal, pub tick_momentum: Decimal, pub tick_trend: Decimal, pub tick_signal: Decimal, pub tick_noise: Decimal, pub tick_correlation: Decimal, pub tick_beta: Decimal, pub tick_alpha: Decimal, pub tick_sharpe_ratio: Decimal, pub tick_sortino_ratio: Decimal, pub tick_information_ratio: Decimal, pub tick_treynor_ratio: Decimal, pub tick_jensen_alpha: Decimal, pub tick_max_drawdown: Decimal, pub tick_calmar_ratio: Decimal, pub tick_sterling_ratio: Decimal, pub tick_burke_ratio: Decimal,
}
Expand description

Trade-based features for tick data analysis

This struct contains comprehensive microstructure features for high-frequency trading analysis. Features are organized by implementation status and complexity:

§Implementation Status (67 total fields)

§✅ Fully Implemented (16 fields)

Basic Trade Data (5 fields):

  • tick_price, tick_qty, tick_direction, tick_value, tick_volume

Immediate Calculations (8 fields):

  • signed_tick_price, plus_tick_price, minus_tick_price
  • signed_tick_qty, plus_tick_qty, minus_tick_qty
  • weighted_tick_price, log_tick_price

Priority 1 - Immediate Features (3 fields):

  • tick_price_power, tick_efficiency, tick_impact

§🔶 Partially Implemented (14 fields)

Requires with_previous_trade() (11 fields):

  • tick_price_ratio, relative_tick_price, log_return, percent_return
  • tick_size, tick_type, tick_frequency, tick_duration, tick_intensity
  • volume_weighted_tick_price, relative_strength

Requires with_trade_history() (4 fields):

  • tick_price_volatility, tick_price_momentum, tick_trend, tick_price_acceleration

§❌ Not Implemented (37 fields)

Priority 3 - Requires Rolling Windows (13 fields):

  • tick_price_skewness, tick_price_kurtosis, tick_price_entropy
  • tick_persistence, tick_reversion, tick_momentum
  • tick_signal, tick_noise, tick_correlation, tick_beta, tick_alpha
  • tick_aggressiveness (basic version implemented)

Priority 4 - Portfolio-Level Metrics (9 fields):

  • tick_sharpe_ratio, tick_sortino_ratio, tick_information_ratio
  • tick_treynor_ratio, tick_jensen_alpha, tick_max_drawdown
  • tick_calmar_ratio, tick_sterling_ratio, tick_burke_ratio

§Usage Patterns

use rust_decimal_macros::dec;

// Basic usage - immediate calculations only
let basic = TradeFeatures::new(dec!(100.5), dec!(10), OrderSide::Buy);

// With previous trade data
let enhanced = TradeFeatures::new(dec!(100.5), dec!(10), OrderSide::Buy)
    .with_previous_trade(dec!(100.0), dec!(8), 1000000000, 1000001000);

// With full historical data
let prices = vec![dec!(99.5), dec!(100.0), dec!(100.2), dec!(100.5)];
let qtys = vec![dec!(5), dec!(8), dec!(12), dec!(10)];
let full = TradeFeatures::new(dec!(100.5), dec!(10), OrderSide::Buy)
    .with_previous_trade(dec!(100.0), dec!(8), 1000000000, 1000001000)
    .with_trade_history(&prices, &qtys);

§Memory Usage

Current: 67 × 16 bytes = ~1KB per instance (many fields are zeros) Proposed: Split into focused structs to reduce memory waste

Consider splitting into specialized structs:

  • CoreTradeFeatures (basic trade data + immediate calculations)
  • TradeStatistics (requires historical data)
  • TradePerformanceMetrics (portfolio-level metrics)
  • TradeMicrostructure (advanced market structure features)

Fields§

§tick_price: Decimal

The price of the tick.

§tick_qty: Decimal

The quantity of the tick.

§tick_direction: i8

The direction of the tick (1 for buy, -1 for sell).

§signed_tick_price: Decimal

The signed price of the tick.

§plus_tick_price: Decimal

The price of the tick if it was a buy.

§minus_tick_price: Decimal

The price of the tick if it was a sell.

§signed_tick_qty: Decimal

The signed quantity of the tick.

§plus_tick_qty: Decimal

The quantity of the tick if it was a buy.

§minus_tick_qty: Decimal

The quantity of the tick if it was a sell.

§weighted_tick_price: Decimal

The weighted price of the tick.

§log_tick_price: Decimal

The logarithm of the tick price.

§tick_price_ratio: Decimal

The ratio of the tick price to the previous tick price.

§tick_price_power: Decimal

The power of the tick price.

§relative_tick_price: Decimal

The relative tick price.

§log_return: Decimal

The log return of the tick price.

§percent_return: Decimal

The percent return of the tick price.

§volume_weighted_tick_price: Decimal

The volume-weighted tick price.

§tick_price_acceleration: Decimal

The acceleration of the tick price.

§tick_price_momentum: Decimal

The momentum of the tick price.

§relative_strength: Decimal

The relative strength of the tick price.

§tick_price_skewness: Decimal

The skewness of the tick price.

§tick_price_kurtosis: Decimal

The kurtosis of the tick price.

§tick_price_volatility: Decimal

The volatility of the tick price.

§tick_price_entropy: Decimal

The entropy of the tick price.

§tick_size: Decimal

The tick size.

§tick_type: i8

The tick type (1 for uptick, -1 for downtick, 0 for no change).

§tick_volume: Decimal

The tick volume.

§tick_value: Decimal

The tick value.

§tick_efficiency: Decimal

The tick efficiency.

§tick_impact: Decimal

The tick impact.

§tick_aggressiveness: i8

The aggressiveness of the tick (1 for aggressive, 0 for passive).

§tick_frequency: Decimal

The tick frequency.

§tick_duration: Decimal

The tick duration.

§tick_intensity: Decimal

The tick intensity.

§tick_persistence: Decimal

The tick persistence.

§tick_reversion: Decimal

The tick reversion.

§tick_momentum: Decimal

The tick momentum.

§tick_trend: Decimal

The tick trend.

§tick_signal: Decimal

The tick signal.

§tick_noise: Decimal

The tick noise.

§tick_correlation: Decimal

The tick correlation.

§tick_beta: Decimal

The tick beta.

§tick_alpha: Decimal

The tick alpha.

§tick_sharpe_ratio: Decimal

The tick sharpe ratio.

§tick_sortino_ratio: Decimal

The tick sortino ratio.

§tick_information_ratio: Decimal

The tick information ratio.

§tick_treynor_ratio: Decimal

The tick treynor ratio.

§tick_jensen_alpha: Decimal

The tick jensen alpha.

§tick_max_drawdown: Decimal

The tick maximum drawdown.

§tick_calmar_ratio: Decimal

The tick calmar ratio.

§tick_sterling_ratio: Decimal

The tick sterling ratio.

§tick_burke_ratio: Decimal

The tick burke ratio.

Implementations§

Source§

impl TradeFeatures

Source

pub fn new(price: Decimal, qty: Decimal, side: OrderSide) -> Self

Create a new TradeFeatures instance with calculated trade features

Source

pub fn with_previous_trade( self, prev_price: Decimal, prev_qty: Decimal, prev_timestamp_ns: u64, current_timestamp_ns: u64, ) -> Self

Update features that require historical data

This method should be called when previous trade data is available to calculate features that depend on price history, trade patterns, etc.

Implemented features:

  • tick_price_ratio, relative_tick_price, log_return, percent_return
  • tick_size, tick_type (price movement direction)
  • tick_frequency, tick_duration, tick_intensity (time-based)
  • volume_weighted_tick_price
  • relative_strength (price momentum)
Source

pub fn with_trade_history( self, price_history: &[Decimal], qty_history: &[Decimal], ) -> Self

Update features with a rolling window of historical trades

This method calculates statistical features that require multiple data points such as volatility, skewness, kurtosis, and various risk metrics.

Implemented features:

  • tick_price_volatility (standard deviation of prices)
  • tick_price_momentum (price change over window)
  • tick_trend (linear regression slope approximation)
  • tick_price_acceleration (second derivative of price changes)

Minimum requirements:

  • price_history.len() >= 2 for basic calculations
  • price_history.len() >= 3 for trend and acceleration

Trait Implementations§

Source§

impl Clone for TradeFeatures

Source§

fn clone(&self) -> TradeFeatures

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TradeFeatures

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,