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)
|
||||
|
||||
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) {
|
||||
return p.Amount + agg
|
||||
} else {
|
||||
return service.GetMarketPrice(db, p, start) - p.Amount + agg
|
||||
return service.GetMarketPrice(db, p, start) + agg
|
||||
}
|
||||
}, 0)
|
||||
|
||||
gain := balance + withdrawal - investment
|
||||
networths = append(networths, Overview{Date: start, InvestmentAmount: investment, WithdrawalAmount: withdrawal, GainAmount: gain})
|
||||
}
|
||||
return networths
|
||||
|
|
|
@ -130,7 +130,7 @@ function renderBreakdowns(breakdowns: Breakdown[]) {
|
|||
b.investment_amount != 0 && gain != 0 ? formatCurrency(gain) : ""
|
||||
}</td>
|
||||
<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>
|
||||
`;
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue