Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

add current position gross performance (percentage)

Valentin Zicknercdc8faff7fdc
diff --git a/apps/api/src/app/core/portfolio-calculator.spec.ts b/apps/api/src/app/core/portfolio-calculator.spec.ts
index 5c87c29f00..cd7ae8bbba 100644
--- a/apps/api/src/app/core/portfolio-calculator.spec.ts
+++ b/apps/api/src/app/core/portfolio-calculator.spec.ts
@@ -32,7 +32,7 @@ function dateEqual(date1: Date, date2: Date) {
);
}
-jest.mock('./current-rate.service.ts', () => {
+jest.mock('@ghostfolio/api/app/core/current-rate.service', () => {
return {
// eslint-disable-next-line @typescript-eslint/naming-convention
CurrentRateService: jest.fn().mockImplementation(() => {
@@ -546,7 +546,9 @@ describe('PortfolioCalculator', () => {
symbol: 'VTI',
investment: new Big('4460.95'),
marketPrice: new Big('213.32'),
- transactionCount: 5
+ transactionCount: 5,
+ grossPerformance: new Big('872.05'), // 213.32*25-4460.95
+ grossPerformancePercentage: new Big('0.19548526659119694236') // 872.05/4460.95
}
});
});
diff --git a/apps/api/src/app/core/portfolio-calculator.ts b/apps/api/src/app/core/portfolio-calculator.ts
index 11cd13ecb5..f0ceece4be 100644
--- a/apps/api/src/app/core/portfolio-calculator.ts
+++ b/apps/api/src/app/core/portfolio-calculator.ts
@@ -121,6 +121,9 @@ export class PortfolioCalculator {
currency: item.currency,
userCurrency: this.currency
});
+ const grossPerformance = new Big(marketValue.marketPrice)
+ .mul(item.quantity)
+ .minus(item.investment);
result[item.symbol] = {
averagePrice: item.investment.div(item.quantity),
firstBuyDate: item.firstBuyDate,
@@ -128,7 +131,9 @@ export class PortfolioCalculator {
symbol: item.symbol,
investment: item.investment,
marketPrice: marketValue.marketPrice,
- transactionCount: item.transactionCount
+ transactionCount: item.transactionCount,
+ grossPerformance,
+ grossPerformancePercentage: grossPerformance.div(item.investment)
};
}
@@ -290,6 +295,8 @@ interface TimelinePosition {
quantity: Big;
symbol: string;
investment: Big;
+ grossPerformancePercentage: Big;
+ grossPerformance: Big;
marketPrice: number;
transactionCount: number;
}