移除净值读取定点重复转换

This commit is contained in:
boris
2026-08-25 15:08:33 +08:00
parent 5b6b3682dd
commit e368bad7e4
+3 -22
View File
@@ -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::<String, f64>::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()))