add current position gross performance (percentage)

pull/239/head
Valentin Zickner 3 years ago committed by Thomas
parent 7b696e39de
commit cdc8faff7f

@ -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
}
});
});

@ -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;
}

Loading…
Cancel
Save