Skip to content

Commit

Permalink
Fix issue with the duplicate lots not adding the subsequent entries' …
Browse files Browse the repository at this point in the history
…fixed costs into the total cost. (#283)
  • Loading branch information
yodigi7 committed Jan 7, 2025
1 parent 82ffdd8 commit 9896468
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func getLots(lots []c.Lot) map[string]AggregatedLot {
} else {

aggregatedLot.Quantity += lot.Quantity
aggregatedLot.Cost += lot.Quantity * lot.UnitCost
aggregatedLot.Cost += (lot.Quantity * lot.UnitCost) + lot.FixedCost

aggregatedLots[lot.Symbol] = aggregatedLot

Expand Down
54 changes: 54 additions & 0 deletions internal/asset/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,59 @@ var _ = Describe("Asset", func() {
})
})

When("there are duplicate lots with fixed costs", func() {
It("both fixed costs should be added to total cost", func() {
inputContext := c.Context{}
inputAssetGroupQuote := fixtureAssetGroupQuote
inputAssetGroupQuote.AssetGroup.ConfigAssetGroup.Holdings = []c.Lot{
{
Symbol: "TWKS",
UnitCost: 100,
Quantity: 10,
FixedCost: 7,
},
{
Symbol: "TWKS",
UnitCost: 75,
Quantity: 10,
FixedCost: 1,
},
{
Symbol: "MSFT",
UnitCost: 400,
Quantity: 10,
FixedCost: 0,
},
}

outputAssets, outputHoldingSummary := GetAssets(inputContext, inputAssetGroupQuote)

Expect(outputAssets).To(HaveLen(3))

Expect(outputAssets[0].Holding.Value).To(Equal(2200.0))
Expect(outputAssets[0].Holding.Cost).To(Equal(1758.0))
Expect(outputAssets[0].Holding.Quantity).To(Equal(20.0))
Expect(outputAssets[0].Holding.UnitValue).To(Equal(110.0))
Expect(outputAssets[0].Holding.UnitCost).To(Equal(87.9))
Expect(outputAssets[0].Holding.Weight).To(Equal(50.0))

Expect(outputAssets[1].Holding.Value).To(Equal(2200.0))
Expect(outputAssets[1].Holding.Cost).To(Equal(4000.0))
Expect(outputAssets[1].Holding.Quantity).To(Equal(10.0))
Expect(outputAssets[1].Holding.UnitValue).To(Equal(220.0))
Expect(outputAssets[1].Holding.UnitCost).To(Equal(400.0))
Expect(outputAssets[1].Holding.Weight).To(Equal(50.0))

Expect(outputAssets[2].Holding).To(Equal(c.Holding{}))

Expect(outputHoldingSummary.Cost).To(Equal(5757.0))
Expect(outputHoldingSummary.Value).To(Equal(4400.0))
Expect(outputHoldingSummary.TotalChange.Amount).To(Equal(-1357.0))
Expect(outputHoldingSummary.TotalChange.Percent).To(Equal(-23.57130449887094))
Expect(outputHoldingSummary.DayChange.Amount).To(Equal(400.0))
Expect(outputHoldingSummary.DayChange.Percent).To(Equal(9.090909090909092))
})
})

})
})

0 comments on commit 9896468

Please sign in to comment.