fix gain calculation in overview page
This commit is contained in:
parent
97b407b345
commit
76c9069895
|
@ -65,13 +65,15 @@ func computeOverviewTimeline(db *gorm.DB, postings []posting.Posting) []Overview
|
||||||
}
|
}
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
||||||
gain := lo.Reduce(pastPostings, func(agg float64, p posting.Posting, _ int) float64 {
|
balance := lo.Reduce(pastPostings, func(agg float64, p posting.Posting, _ int) float64 {
|
||||||
if service.IsInterest(db, p) {
|
if service.IsInterest(db, p) {
|
||||||
return p.Amount + agg
|
return p.Amount + agg
|
||||||
} else {
|
} else {
|
||||||
return service.GetMarketPrice(db, p, start) - p.Amount + agg
|
return service.GetMarketPrice(db, p, start) + agg
|
||||||
}
|
}
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
||||||
|
gain := balance + withdrawal - investment
|
||||||
networths = append(networths, Overview{Date: start, InvestmentAmount: investment, WithdrawalAmount: withdrawal, GainAmount: gain})
|
networths = append(networths, Overview{Date: start, InvestmentAmount: investment, WithdrawalAmount: withdrawal, GainAmount: gain})
|
||||||
}
|
}
|
||||||
return networths
|
return networths
|
||||||
|
|
|
@ -130,7 +130,7 @@ function renderBreakdowns(breakdowns: Breakdown[]) {
|
||||||
b.investment_amount != 0 && gain != 0 ? formatCurrency(gain) : ""
|
b.investment_amount != 0 && gain != 0 ? formatCurrency(gain) : ""
|
||||||
}</td>
|
}</td>
|
||||||
<td class='${changeClass} has-text-right'>${
|
<td class='${changeClass} has-text-right'>${
|
||||||
b.xirr > 0.0001 ? formatFloat(b.xirr) : ""
|
b.xirr > 0.0001 || b.xirr < -0.0001 ? formatFloat(b.xirr) : ""
|
||||||
}</td>
|
}</td>
|
||||||
`;
|
`;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue