diff --git a/crates/fidc-core/src/portfolio.rs b/crates/fidc-core/src/portfolio.rs index db00ff7..39203ff 100644 --- a/crates/fidc-core/src/portfolio.rs +++ b/crates/fidc-core/src/portfolio.rs @@ -907,7 +907,7 @@ impl PortfolioState { } pub fn total_equity(&self) -> f64 { - self.total_equity_money().to_f64() + self.cash.to_f64() + self.market_value() - self.cash_liabilities.to_f64() } pub fn total_value(&self) -> f64 { @@ -1112,25 +1112,6 @@ impl PortfolioState { }) } - fn market_value_money(&self) -> FixedMoney { - self.positions - .values() - .fold(FixedMoney::ZERO, |total, position| { - let value = Self::fixed_money(position.market_value(), "position market value") - .expect("position market value must be finite fixed-point money"); - total - .checked_add(value) - .expect("fixed-point market value overflow") - }) - } - - fn total_equity_money(&self) -> FixedMoney { - self.cash - .checked_add(self.market_value_money()) - .and_then(|value| value.checked_sub(self.cash_liabilities)) - .expect("fixed-point total equity overflow") - } - fn refresh_dividend_receivables(&mut self) { let mut per_symbol = BTreeMap::::new(); for receivable in &self.cash_receivables { @@ -1147,8 +1128,8 @@ impl PortfolioState { ) -> Result<(), String> { if unit_net_value_before > 0.0 && unit_net_value_before.is_finite() { let unit_nav = Self::fixed_money(unit_net_value_before, "unit net value")?; - let units_raw = self - .total_equity_money() + let total_equity = Self::fixed_money(self.total_equity(), "total equity")?; + let units_raw = total_equity .raw() .checked_mul(MONEY_SCALE) .and_then(|value| value.checked_div(unit_nav.raw()))