pub struct Portfolio {
pub balances: Vec<Balance>,
pub name: String,
}Expand description
Represents a portfolio containing multiple option balances.
This struct provides functionality to manage and analyze a collection of option positions across different exchanges.
Fields§
§balances: Vec<Balance>Collection of option balances
name: StringName or identifier for the portfolio
Implementations§
Source§impl Portfolio
impl Portfolio
Sourcepub fn add_balance(&mut self, balance: Balance)
pub fn add_balance(&mut self, balance: Balance)
Sourcepub fn remove_balance(&mut self, symbol: &str, exchange: &str) -> bool
pub fn remove_balance(&mut self, symbol: &str, exchange: &str) -> bool
Sourcepub fn get_total_value(&self) -> Result<Positive, PositiveError>
pub fn get_total_value(&self) -> Result<Positive, PositiveError>
Calculates the total portfolio value.
§Returns
The sum of all balance values in the portfolio, accumulated in
Decimal with no f64 step. An empty portfolio is worth zero.
§Errors
Returns PositiveError::ArithmeticError when a balance value or the
running sum overflows Decimal.
Sourcepub fn get_total_unrealized_pnl(&self) -> Result<Decimal, DecimalError>
pub fn get_total_unrealized_pnl(&self) -> Result<Decimal, DecimalError>
Calculates the total unrealized PnL for the portfolio.
§Returns
The sum of all unrealized PnL across all balances
§Errors
Propagates the error of Balance::get_unrealized_pnl, and returns
DecimalError::Overflow when the sum leaves the Decimal range;
Iterator::sum aborted with Addition overflowed (#788).
Sourcepub fn get_balances_by_exchange(&self, exchange: &str) -> Vec<&Balance>
pub fn get_balances_by_exchange(&self, exchange: &str) -> Vec<&Balance>
Sourcepub fn has_profitable_positions(&self) -> Result<bool, DecimalError>
pub fn has_profitable_positions(&self) -> Result<bool, DecimalError>
Checks if the portfolio has any profitable positions.
§Returns
true if any balance in the portfolio is profitable
§Errors
Propagates the error of Balance::is_profitable.