Skip to content

Commit 1563882

Browse files
committed
Started taking the total fee of a portfolio entry into consideration when calculating it's total relative change
1 parent 414325f commit 1563882

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Services/Services/SummaryService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public ISummaryService.Summary GetPortfolioEntrySummary(List<MarketOrder> portfo
8989
decimal currentTotalHoldingValue = totalHoldingSize * assetPrice;
9090

9191
decimal totalAbsoluteChange = currentTotalHoldingValue + totalSellValue - totalCost - totalFee;
92-
decimal totalRelativeChange = totalAbsoluteChange / totalCost;
92+
decimal totalRelativeChange = totalAbsoluteChange / (totalCost + totalFee);
9393

9494
return new ISummaryService.Summary(totalAbsoluteChange, totalRelativeChange, currentTotalHoldingValue,
9595
totalCost + totalFee);

Tests/Unit/Service/SummaryServiceTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void GetPortfolioEntrySummary_WithFee_InProfit_Returns_Correct_Summary()
101101
}, 40000);
102102
Assert.Equal(new ISummaryService.Summary(
103103
30000m + 20000m - 6,
104-
((80000m - 6m) / 30000m) - 1m,
104+
((80000m) / (30000m + 6m)) - 1m,
105105
80000m,
106106
30006
107107
), summary);
@@ -137,7 +137,7 @@ public void GetPortfolioEntrySummary_WithFee_InProfit_WithSell_Returns_Correct_S
137137
}, 40000);
138138
Assert.Equal(new ISummaryService.Summary(
139139
30000m + 20000m - 6,
140-
((80000m - 6m) / 30000m) - 1m,
140+
(80000m / (30000m + 6m)) - 1m,
141141
80000m,
142142
30006
143143
), summary);

0 commit comments

Comments
 (0)