From 254cb01402db891490980bbc51a990b2502aca15 Mon Sep 17 00:00:00 2001 From: Ani Channarasappa Date: Sat, 6 Mar 2021 22:50:59 -0500 Subject: [PATCH] fix: total change percent miscalculation --- internal/position/position.go | 4 +++- internal/position/position_test.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/position/position.go b/internal/position/position.go index c2acba6..56188cb 100644 --- a/internal/position/position.go +++ b/internal/position/position.go @@ -106,12 +106,14 @@ func GetPositions(ctx c.Context, aggregatedLots map[string]AggregatedLot) func([ positionsReduced := getPositionsReduced(ctx, aggregatedLots, quotes) + change := positionsReduced.positionSummaryBase.value - positionsReduced.positionSummaryBase.cost + positionSummary := PositionSummary{ Value: positionsReduced.positionSummaryBase.value, Cost: positionsReduced.positionSummaryBase.cost, Change: positionsReduced.positionSummaryBase.value - positionsReduced.positionSummaryBase.cost, DayChange: positionsReduced.positionSummaryBase.dayChange, - ChangePercent: (positionsReduced.positionSummaryBase.value / positionsReduced.positionSummaryBase.cost) * 100, + ChangePercent: (change / positionsReduced.positionSummaryBase.cost) * 100, DayChangePercent: (positionsReduced.positionSummaryBase.dayChange / positionsReduced.positionSummaryBase.value) * 100, } diff --git a/internal/position/position_test.go b/internal/position/position_test.go index 8cfaf1e..b5045bd 100644 --- a/internal/position/position_test.go +++ b/internal/position/position_test.go @@ -102,7 +102,7 @@ var _ = Describe("Position", func() { Cost: 4000, Change: 1450, DayChange: 625, - ChangePercent: 136.25, + ChangePercent: 36.25, DayChangePercent: 11.46788990825688, } Expect(outputPositions["ARKW"]).To(Equal(Position{