show XIRR in the overview page
This commit is contained in:
parent
44152d530d
commit
8b972a05b4
|
@ -26,8 +26,10 @@ func GetOverview(db *gorm.DB) gin.H {
|
|||
log.Fatal(result.Error)
|
||||
}
|
||||
|
||||
postings = service.PopulateMarketPrice(db, postings)
|
||||
overviewTimeline := computeOverviewTimeline(db, postings)
|
||||
return gin.H{"overview_timeline": overviewTimeline}
|
||||
xirr := service.XIRR(db, postings)
|
||||
return gin.H{"overview_timeline": overviewTimeline, "xirr": xirr}
|
||||
}
|
||||
|
||||
func computeOverviewTimeline(db *gorm.DB, postings []posting.Posting) []Overview {
|
||||
|
|
|
@ -6,12 +6,13 @@ import {
|
|||
ajax,
|
||||
formatCurrency,
|
||||
formatCurrencyCrude,
|
||||
formatFloat,
|
||||
Overview,
|
||||
setHtml
|
||||
} from "./utils";
|
||||
|
||||
export default async function () {
|
||||
const { overview_timeline: points } = await ajax("/api/overview");
|
||||
const { overview_timeline: points, xirr: xirr } = await ajax("/api/overview");
|
||||
_.each(points, (n) => (n.timestamp = dayjs(n.date)));
|
||||
|
||||
const current = _.last(points);
|
||||
|
@ -26,6 +27,7 @@ export default async function () {
|
|||
setHtml("investment", formatCurrency(current.investment_amount));
|
||||
setHtml("withdrawal", formatCurrency(current.withdrawal_amount));
|
||||
setHtml("gains", formatCurrency(current.gain_amount));
|
||||
setHtml("xirr", formatFloat(xirr));
|
||||
|
||||
renderOverview(points, document.getElementById("d3-overview-timeline"));
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ export function ajax(
|
|||
): Promise<{ postings: Posting[]; breakdowns: Breakdown[] }>;
|
||||
export function ajax(route: "/api/overview"): Promise<{
|
||||
overview_timeline: Overview[];
|
||||
overview_timeline_breakdown: { [key: string]: Overview[] };
|
||||
xirr: number;
|
||||
}>;
|
||||
export function ajax(route: "/api/gain"): Promise<{
|
||||
gain_timeline_breakdown: Gain[];
|
||||
|
@ -118,7 +118,7 @@ export function formatCurrencyCrude(value: number) {
|
|||
unit = "";
|
||||
if (Math.abs(value) < 100000) {
|
||||
(x = value / 1000), (unit = "K");
|
||||
} else if (Math.abs(value) <= 10000000) {
|
||||
} else if (Math.abs(value) < 10000000) {
|
||||
(x = value / 100000), (unit = "L");
|
||||
} else {
|
||||
(x = value / 10000000), (unit = "C");
|
||||
|
|
|
@ -57,6 +57,12 @@
|
|||
<p class="d3-gains title"></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="level-item has-text-centered">
|
||||
<div>
|
||||
<p class="heading">XIRR</p>
|
||||
<p class="d3-xirr title"></p>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
</section>
|
||||
|
|
Loading…
Reference in New Issue