#[repr(C)]pub struct PortfolioAnalyzer { /* private fields */ }
Expand description
Analyzes portfolio performance and calculates various statistics.
The PortfolioAnalyzer
tracks account balances, positions, and realized PnLs
to provide comprehensive portfolio analysis including returns, PnL calculations,
and customizable statistics.
Implementations§
Source§impl PortfolioAnalyzer
impl PortfolioAnalyzer
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new PortfolioAnalyzer
instance.
Starts with empty state.
Sourcepub fn register_statistic(&mut self, statistic: Statistic)
pub fn register_statistic(&mut self, statistic: Statistic)
Registers a new portfolio statistic for calculation.
Sourcepub fn deregister_statistic(&mut self, statistic: Statistic)
pub fn deregister_statistic(&mut self, statistic: Statistic)
Removes a specific statistic from calculation.
Sourcepub fn deregister_statistics(&mut self)
pub fn deregister_statistics(&mut self)
Removes all registered statistics.
Sourcepub fn currencies(&self) -> Vec<&Currency>
pub fn currencies(&self) -> Vec<&Currency>
Returns all tracked currencies.
Sourcepub fn statistic(&self, name: &str) -> Option<&Statistic>
pub fn statistic(&self, name: &str) -> Option<&Statistic>
Retrieves a specific statistic by name.
Sourcepub fn calculate_statistics(
&mut self,
account: &dyn Account,
positions: &[Position],
)
pub fn calculate_statistics( &mut self, account: &dyn Account, positions: &[Position], )
Calculates statistics based on account and position data.
Sourcepub fn add_positions(&mut self, positions: &[Position])
pub fn add_positions(&mut self, positions: &[Position])
Adds new positions for analysis.
Sourcepub fn add_return(&mut self, timestamp: UnixNanos, value: f64)
pub fn add_return(&mut self, timestamp: UnixNanos, value: f64)
Records a return at a specific timestamp.
Sourcepub fn realized_pnls(
&self,
currency: Option<&Currency>,
) -> Option<Vec<(PositionId, f64)>>
pub fn realized_pnls( &self, currency: Option<&Currency>, ) -> Option<Vec<(PositionId, f64)>>
Retrieves realized PnLs
for a specific currency.
Sourcepub fn total_pnl(
&self,
currency: Option<&Currency>,
unrealized_pnl: Option<&Money>,
) -> Result<f64, &'static str>
pub fn total_pnl( &self, currency: Option<&Currency>, unrealized_pnl: Option<&Money>, ) -> Result<f64, &'static str>
Calculates total PnL
including unrealized PnL
if provided.
Sourcepub fn total_pnl_percentage(
&self,
currency: Option<&Currency>,
unrealized_pnl: Option<&Money>,
) -> Result<f64, &'static str>
pub fn total_pnl_percentage( &self, currency: Option<&Currency>, unrealized_pnl: Option<&Money>, ) -> Result<f64, &'static str>
Calculates total PnL
as a percentage of starting balance.
Sourcepub fn get_performance_stats_pnls(
&self,
currency: Option<&Currency>,
unrealized_pnl: Option<&Money>,
) -> Result<HashMap<String, f64>, &'static str>
pub fn get_performance_stats_pnls( &self, currency: Option<&Currency>, unrealized_pnl: Option<&Money>, ) -> Result<HashMap<String, f64>, &'static str>
Gets all PnL-related performance statistics.
Sourcepub fn get_performance_stats_returns(&self) -> HashMap<String, f64>
pub fn get_performance_stats_returns(&self) -> HashMap<String, f64>
Gets all return-based performance statistics.
Sourcepub fn get_performance_stats_general(&self) -> HashMap<String, f64>
pub fn get_performance_stats_general(&self) -> HashMap<String, f64>
Gets general portfolio statistics.
Sourcepub fn get_stats_pnls_formatted(
&self,
currency: Option<&Currency>,
unrealized_pnl: Option<&Money>,
) -> Result<Vec<String>, String>
pub fn get_stats_pnls_formatted( &self, currency: Option<&Currency>, unrealized_pnl: Option<&Money>, ) -> Result<Vec<String>, String>
Gets formatted PnL
statistics as strings.
Sourcepub fn get_stats_returns_formatted(&self) -> Vec<String>
pub fn get_stats_returns_formatted(&self) -> Vec<String>
Gets formatted return statistics as strings.
Sourcepub fn get_stats_general_formatted(&self) -> Vec<String>
pub fn get_stats_general_formatted(&self) -> Vec<String>
Gets formatted general statistics as strings.
Trait Implementations§
Source§impl Debug for PortfolioAnalyzer
impl Debug for PortfolioAnalyzer
Source§impl Default for PortfolioAnalyzer
impl Default for PortfolioAnalyzer
Source§fn default() -> Self
fn default() -> Self
Creates a new default PortfolioAnalyzer
instance.
Source§impl IntoPy<Py<PyAny>> for PortfolioAnalyzer
impl IntoPy<Py<PyAny>> for PortfolioAnalyzer
Source§impl PyClass for PortfolioAnalyzer
impl PyClass for PortfolioAnalyzer
Source§impl PyClassImpl for PortfolioAnalyzer
impl PyClassImpl for PortfolioAnalyzer
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§type ThreadChecker = SendablePyClass<PortfolioAnalyzer>
type ThreadChecker = SendablePyClass<PortfolioAnalyzer>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a PortfolioAnalyzer
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a PortfolioAnalyzer
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut PortfolioAnalyzer
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut PortfolioAnalyzer
Source§impl PyTypeInfo for PortfolioAnalyzer
impl PyTypeInfo for PortfolioAnalyzer
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool
object
is an instance of this type or a subclass of this type.§fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool
object
is an instance of this type.