移除净值读取定点重复转换
This commit is contained in:
@@ -907,7 +907,7 @@ impl PortfolioState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn total_equity(&self) -> f64 {
|
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 {
|
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) {
|
fn refresh_dividend_receivables(&mut self) {
|
||||||
let mut per_symbol = BTreeMap::<String, f64>::new();
|
let mut per_symbol = BTreeMap::<String, f64>::new();
|
||||||
for receivable in &self.cash_receivables {
|
for receivable in &self.cash_receivables {
|
||||||
@@ -1147,8 +1128,8 @@ impl PortfolioState {
|
|||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
if unit_net_value_before > 0.0 && unit_net_value_before.is_finite() {
|
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 unit_nav = Self::fixed_money(unit_net_value_before, "unit net value")?;
|
||||||
let units_raw = self
|
let total_equity = Self::fixed_money(self.total_equity(), "total equity")?;
|
||||||
.total_equity_money()
|
let units_raw = total_equity
|
||||||
.raw()
|
.raw()
|
||||||
.checked_mul(MONEY_SCALE)
|
.checked_mul(MONEY_SCALE)
|
||||||
.and_then(|value| value.checked_div(unit_nav.raw()))
|
.and_then(|value| value.checked_div(unit_nav.raw()))
|
||||||
|
|||||||
Reference in New Issue
Block a user