Trait PortfolioStatistic

Source
pub trait PortfolioStatistic: Debug {
    type Item;

    // Required method
    fn name(&self) -> String;

    // Provided methods
    fn calculate_from_returns(&self, returns: &Returns) -> Option<Self::Item> { ... }
    fn calculate_from_realized_pnls(
        &self,
        realized_pnls: &[f64],
    ) -> Option<Self::Item> { ... }
    fn calculate_from_orders(
        &self,
        orders: Vec<Box<dyn Order>>,
    ) -> Option<Self::Item> { ... }
    fn calculate_from_positions(
        &self,
        positions: &[Position],
    ) -> Option<Self::Item> { ... }
    fn check_valid_returns(&self, returns: &Returns) -> bool { ... }
    fn downsample_to_daily_bins(&self, returns: &Returns) -> Returns { ... }
    fn calculate_std(&self, returns: &Returns) -> f64 { ... }
}
Expand description

Trait for portfolio performance statistics that can be calculated from different data sources.

This trait provides a flexible framework for implementing various financial performance metrics that can operate on returns, realized PnLs, orders, or positions data. Each statistic implementation should override the relevant calculation methods.

Required Associated Types§

Required Methods§

Source

fn name(&self) -> String

Returns the name of this statistic for display and identification purposes.

Provided Methods§

Source

fn calculate_from_returns(&self, returns: &Returns) -> Option<Self::Item>

Calculates the statistic from time-indexed returns data.

§Panics

Panics if this method is not implemented for the specific statistic.

Source

fn calculate_from_realized_pnls( &self, realized_pnls: &[f64], ) -> Option<Self::Item>

Calculates the statistic from realized profit and loss values.

§Panics

Panics if this method is not implemented for the specific statistic.

Source

fn calculate_from_orders( &self, orders: Vec<Box<dyn Order>>, ) -> Option<Self::Item>

Calculates the statistic from order data.

§Panics

Panics if this method is not implemented for the specific statistic.

Source

fn calculate_from_positions(&self, positions: &[Position]) -> Option<Self::Item>

Calculates the statistic from position data.

§Panics

Panics if this method is not implemented for the specific statistic.

Source

fn check_valid_returns(&self, returns: &Returns) -> bool

Validates that returns data is not empty.

Source

fn downsample_to_daily_bins(&self, returns: &Returns) -> Returns

Downsamples high-frequency returns to daily bins for daily statistics calculation.

Source

fn calculate_std(&self, returns: &Returns) -> f64

Calculates the standard deviation of returns with Bessel’s correction.

Implementors§