From 328d8149222ff98a6e37a47ba6b5f2c4b5c25251 Mon Sep 17 00:00:00 2001 From: Valentin Zickner Date: Sat, 31 Jul 2021 20:50:48 +0200 Subject: [PATCH] remove getPerformance from portfolio.ts Co-authored-by: Thomas --- apps/api/src/models/portfolio.spec.ts | 95 --------------------------- apps/api/src/models/portfolio.ts | 43 ------------ 2 files changed, 138 deletions(-) diff --git a/apps/api/src/models/portfolio.spec.ts b/apps/api/src/models/portfolio.spec.ts index 053ef4f8c..5e3b34f7b 100644 --- a/apps/api/src/models/portfolio.spec.ts +++ b/apps/api/src/models/portfolio.spec.ts @@ -208,28 +208,6 @@ describe('Portfolio', () => { } }); }); - - it('should return zero performance for 1d', async () => { - const performance = await portfolio.getPerformance('1d'); - expect(performance).toEqual({ - currentGrossPerformance: 0, - currentGrossPerformancePercent: 0, - currentNetPerformance: 0, - currentNetPerformancePercent: 0, - currentValue: 0 - }); - }); - - it('should return zero performance for max', async () => { - const performance = await portfolio.getPerformance('max'); - expect(performance).toEqual({ - currentGrossPerformance: 0, - currentGrossPerformancePercent: 0, - currentNetPerformance: 0, - currentNetPerformancePercent: 0, - currentValue: 0 - }); - }); }); describe(`works with today's orders`, () => { @@ -303,32 +281,6 @@ describe('Portfolio', () => { expect(portfolio.getFees()).toEqual(0); - /*const performance1d = await portfolio.getPerformance('1d'); - expect(performance1d).toEqual({ - currentGrossPerformance: 0, - currentGrossPerformancePercent: 0, - currentNetPerformance: 0, - currentNetPerformancePercent: 0, - currentValue: exchangeRateDataService.toBaseCurrency( - 1 * 49631.24, - Currency.USD, - baseCurrency - ) - });*/ - - /*const performanceMax = await portfolio.getPerformance('max'); - expect(performanceMax).toEqual({ - currentGrossPerformance: 0, - currentGrossPerformancePercent: 0, - currentNetPerformance: 0, - currentNetPerformancePercent: 0, - currentValue: exchangeRateDataService.toBaseCurrency( - 1 * 49631.24, - Currency.USD, - baseCurrency - ) - });*/ - expect(portfolio.getPositions(getYesterday())).toMatchObject({}); expect(portfolio.getSymbols(getYesterday())).toEqual([]); @@ -367,55 +319,8 @@ describe('Portfolio', () => { ) ); - /*const details = await portfolio.getDetails('1d'); - expect(details).toMatchObject({ - ETHUSD: { - accounts: { - [UNKNOWN_KEY]: { - current: exchangeRateDataService.toCurrency( - 0.2 * 991.49, - Currency.USD, - baseCurrency - ), - original: exchangeRateDataService.toCurrency( - 0.2 * 991.49, - Currency.USD, - baseCurrency - ) - } - }, - // allocationCurrent: 1, - allocationInvestment: 1, - countries: [], - currency: Currency.USD, - exchange: UNKNOWN_KEY, - // grossPerformance: 0, - // grossPerformancePercent: 0, - investment: exchangeRateDataService.toCurrency( - 0.2 * 991.49, - Currency.USD, - baseCurrency - ), - marketPrice: 3915.337, - name: 'Ethereum USD', - quantity: 0.2, - transactionCount: 1, - symbol: 'ETHUSD', - type: 'Cryptocurrency' - } - });*/ - expect(portfolio.getFees()).toEqual(0); - /*const performance = await portfolio.getPerformance('max'); - expect(performance).toEqual({ - currentGrossPerformance: 0, - currentGrossPerformancePercent: 0, - currentNetPerformance: 0, - currentNetPerformancePercent: 0, - currentValue: 0 - });*/ - expect(portfolio.getPositions(getYesterday())).toMatchObject({ ETHUSD: { averagePrice: 991.49, diff --git a/apps/api/src/models/portfolio.ts b/apps/api/src/models/portfolio.ts index 1ea841821..b03a9b829 100644 --- a/apps/api/src/models/portfolio.ts +++ b/apps/api/src/models/portfolio.ts @@ -426,49 +426,6 @@ export class Portfolio implements PortfolioInterface { return null; } - public async getPerformance( - aDateRange: DateRange = 'max' - ): Promise { - const dateRangeDate = this.convertDateRangeToDate( - aDateRange, - this.getMinDate() - ); - - const currentInvestment = this.getInvestment(new Date()); - const currentValue = await this.getValue(); - - let originalInvestment = currentInvestment; - let originalValue = this.getCommittedFunds(); - - if (dateRangeDate) { - originalInvestment = this.getInvestment(dateRangeDate); - originalValue = (await this.getValue(dateRangeDate)) || originalValue; - } - - const fees = this.getFees(dateRangeDate); - - const currentGrossPerformance = - currentValue - currentInvestment - (originalValue - originalInvestment); - - // https://www.skillsyouneed.com/num/percent-change.html - const currentGrossPerformancePercent = - currentGrossPerformance / originalInvestment || 0; - - const currentNetPerformance = currentGrossPerformance - fees; - - // https://www.skillsyouneed.com/num/percent-change.html - const currentNetPerformancePercent = - currentNetPerformance / originalInvestment || 0; - - return { - currentGrossPerformance, - currentGrossPerformancePercent, - currentNetPerformance, - currentNetPerformancePercent, - currentValue - }; - } - public getPositions(aDate: Date) { const [portfolioItem] = this.get(aDate);