Skip to main content

VolumeProfileEngine

Struct VolumeProfileEngine 

Source
pub struct VolumeProfileEngine { /* private fields */ }
Expand description

Volume Profile over the last lookback bars: volume by price, Point of Control and a 70 % value area.

The window’s own range [min low, max high] is split into num_bins equal bins of width step. Each bar’s volume — its range when it carries no volume — is spread evenly over the bins from floor((low - min) / step) to floor((high - min) / step), both clamped to the last bin. The POC is the first bin with the largest volume, priced at its centre. The value area grows from the POC one bin at a time towards the larger neighbour (upwards on a tie) until it holds 70 % of the window’s volume; VAH is the upper edge of its top bin, VAL the lower edge of its bottom bin.

value and extra["vpoc"]: the POC; further extra["vah"], extra["val"], extra["total_volume"], extra["vpoc_density"] (POC volume over total), extra["current_density"] (the close’s bin over total) and extra["lvn_width"] (2 * step). A window without range publishes the close.

First output: with the lookback-th bar. Indicator::reset clears the window.

Implementations§

Source§

impl VolumeProfileEngine

Source

pub fn new(lookback: usize, num_bins: usize) -> Self

Constructs a profile engine, clamping lookback and num_bins to a minimum of 1 each (matching ExtendedVolumeProfileEngine’s and PersistentVolumeProfileEngine’s existing contract). 0 would otherwise leave on_bar with an empty bin vector (panicking on the first non-flat window) or a warmup that can never complete. Prefer VolumeProfileEngine::try_new for configuration-driven construction, where silently substituting 1 would compute a different profile than requested.

Source

pub fn try_new( lookback: usize, num_bins: usize, ) -> Result<Self, VolumeProfileConfigError>

Like VolumeProfileEngine::new, but rejects a zero lookback/num_bins with VolumeProfileConfigError instead of silently clamping it to 1.

Source

pub fn on_bar_with_boundary( &mut self, bar: &Bar, is_contract_boundary: bool, ) -> Option<IndicatorOutput>

Feeds a bar into the volume profile engine, resetting internal state if is_contract_boundary is true.

This prevents volume and distribution bins from previous contracts or expirations from distorting the profile across commodity or futures roll boundaries.

Trait Implementations§

Source§

impl Indicator for VolumeProfileEngine

Source§

fn name(&self) -> &str

Source§

fn warmup_period(&self) -> usize

Source§

fn reset(&mut self)

Source§

fn on_bar(&mut self, bar: &Bar) -> Option<IndicatorOutput>

Source§

fn alerts(&self) -> Vec<IndicatorAlert>

Source§

fn on_checked_bar( &mut self, bar: &Bar, ) -> Result<Option<IndicatorOutput>, BarValidationError>

Validates a bar before forwarding it to Indicator::on_bar.

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.