Skip to content

Commit

Permalink
fix gain calculation in overview page
Browse files Browse the repository at this point in the history
  • Loading branch information
ananthakumaran committed Aug 23, 2022
1 parent 97b407b commit 76c9069
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions internal/server/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion web/src/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
`;
});
Expand Down

0 comments on commit 76c9069

Please sign in to comment.