From 4bd41ffa4146c5e2b506db5ae1072d6fe3cfbec6 Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sun, 1 Aug 2021 20:43:12 +0200 Subject: [PATCH] Feature/eliminate name from timeline position (#245) * Eliminate name from timeline position: Get the name from the symbolProfileService instead * Update changelog --- CHANGELOG.md | 6 ++ .../transaction-point-symbol.interface.ts | 1 - .../src/app/core/portfolio-calculator.spec.ts | 64 ++----------------- apps/api/src/app/core/portfolio-calculator.ts | 7 +- apps/api/src/app/order/order.controller.ts | 5 ++ .../src/app/portfolio/portfolio.service.ts | 17 ++++- .../transactions-table.component.html | 7 +- .../interfaces/timeline-position.interface.ts | 1 - 8 files changed, 40 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddab4e985..31fb3d66c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added + +- Added the name to the position detail dialog when opened from the transactions table + ## 1.31.1 - 01.08.2021 ### Fixed diff --git a/apps/api/src/app/core/interfaces/transaction-point-symbol.interface.ts b/apps/api/src/app/core/interfaces/transaction-point-symbol.interface.ts index acd1f923c..0cf66083c 100644 --- a/apps/api/src/app/core/interfaces/transaction-point-symbol.interface.ts +++ b/apps/api/src/app/core/interfaces/transaction-point-symbol.interface.ts @@ -5,7 +5,6 @@ export interface TransactionPointSymbol { currency: Currency; firstBuyDate: string; investment: Big; - name: string; quantity: Big; symbol: string; transactionCount: number; diff --git a/apps/api/src/app/core/portfolio-calculator.spec.ts b/apps/api/src/app/core/portfolio-calculator.spec.ts index 551eeded1..19e524789 100644 --- a/apps/api/src/app/core/portfolio-calculator.spec.ts +++ b/apps/api/src/app/core/portfolio-calculator.spec.ts @@ -170,7 +170,6 @@ describe('PortfolioCalculator', () => { currency: Currency.USD, firstBuyDate: '2019-02-01', investment: new Big('1443.8'), - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('10'), symbol: 'VTI', transactionCount: 1 @@ -184,7 +183,6 @@ describe('PortfolioCalculator', () => { currency: Currency.USD, firstBuyDate: '2019-02-01', investment: new Big('2923.7'), - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('20'), symbol: 'VTI', transactionCount: 2 @@ -198,7 +196,6 @@ describe('PortfolioCalculator', () => { currency: Currency.USD, firstBuyDate: '2019-02-01', investment: new Big('652.55'), - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('5'), symbol: 'VTI', transactionCount: 3 @@ -212,7 +209,6 @@ describe('PortfolioCalculator', () => { currency: Currency.USD, firstBuyDate: '2019-02-01', investment: new Big('6627.05'), - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('35'), symbol: 'VTI', transactionCount: 5 @@ -226,7 +222,6 @@ describe('PortfolioCalculator', () => { currency: Currency.USD, firstBuyDate: '2019-02-01', investment: new Big('8403.95'), - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('45'), symbol: 'VTI', transactionCount: 6 @@ -262,7 +257,6 @@ describe('PortfolioCalculator', () => { date: '2019-02-01', items: [ { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('10'), symbol: 'VTI', investment: new Big('1443.8'), @@ -276,7 +270,6 @@ describe('PortfolioCalculator', () => { date: '2019-08-03', items: [ { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('20'), symbol: 'VTI', investment: new Big('2923.7'), @@ -290,7 +283,6 @@ describe('PortfolioCalculator', () => { date: '2019-09-01', items: [ { - name: 'Amazon.com, Inc.', quantity: new Big('5'), symbol: 'AMZN', investment: new Big('10109.95'), @@ -299,7 +291,6 @@ describe('PortfolioCalculator', () => { transactionCount: 1 }, { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('20'), symbol: 'VTI', investment: new Big('2923.7'), @@ -313,7 +304,6 @@ describe('PortfolioCalculator', () => { date: '2020-02-02', items: [ { - name: 'Amazon.com, Inc.', quantity: new Big('5'), symbol: 'AMZN', investment: new Big('10109.95'), @@ -322,7 +312,6 @@ describe('PortfolioCalculator', () => { transactionCount: 1 }, { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('5'), symbol: 'VTI', investment: new Big('652.55'), @@ -336,7 +325,6 @@ describe('PortfolioCalculator', () => { date: '2021-02-01', items: [ { - name: 'Amazon.com, Inc.', quantity: new Big('5'), symbol: 'AMZN', investment: new Big('10109.95'), @@ -345,7 +333,6 @@ describe('PortfolioCalculator', () => { transactionCount: 1 }, { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('15'), symbol: 'VTI', investment: new Big('2684.05'), @@ -359,7 +346,6 @@ describe('PortfolioCalculator', () => { date: '2021-08-01', items: [ { - name: 'Amazon.com, Inc.', quantity: new Big('5'), symbol: 'AMZN', investment: new Big('10109.95'), @@ -368,7 +354,6 @@ describe('PortfolioCalculator', () => { transactionCount: 1 }, { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('25'), symbol: 'VTI', investment: new Big('4460.95'), @@ -416,7 +401,6 @@ describe('PortfolioCalculator', () => { date: '2019-02-01', items: [ { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('10'), symbol: 'VTI', investment: new Big('1443.8'), @@ -430,7 +414,6 @@ describe('PortfolioCalculator', () => { date: '2019-08-03', items: [ { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('20'), symbol: 'VTI', investment: new Big('2923.7'), @@ -444,7 +427,6 @@ describe('PortfolioCalculator', () => { date: '2019-09-01', items: [ { - name: 'Amazon.com, Inc.', quantity: new Big('5'), symbol: 'AMZN', investment: new Big('10109.95'), @@ -453,7 +435,6 @@ describe('PortfolioCalculator', () => { transactionCount: 1 }, { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('20'), symbol: 'VTI', investment: new Big('2923.7'), @@ -467,7 +448,6 @@ describe('PortfolioCalculator', () => { date: '2020-02-02', items: [ { - name: 'Amazon.com, Inc.', quantity: new Big('5'), symbol: 'AMZN', investment: new Big('10109.95'), @@ -476,7 +456,6 @@ describe('PortfolioCalculator', () => { transactionCount: 1 }, { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('5'), symbol: 'VTI', investment: new Big('652.55'), @@ -490,7 +469,6 @@ describe('PortfolioCalculator', () => { date: '2020-08-02', items: [ { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('5'), symbol: 'VTI', investment: new Big('652.55'), @@ -504,7 +482,6 @@ describe('PortfolioCalculator', () => { date: '2021-02-01', items: [ { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('15'), symbol: 'VTI', investment: new Big('2684.05'), @@ -518,7 +495,6 @@ describe('PortfolioCalculator', () => { date: '2021-08-01', items: [ { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('25'), symbol: 'VTI', investment: new Big('4460.95'), @@ -545,7 +521,6 @@ describe('PortfolioCalculator', () => { date: '2017-01-03', items: [ { - name: 'Tesla, Inc.', quantity: new Big('50'), symbol: 'TSLA', investment: new Big('2148.5'), @@ -559,7 +534,6 @@ describe('PortfolioCalculator', () => { date: '2017-07-01', items: [ { - name: 'Bitcoin USD', quantity: new Big('0.5614682'), symbol: 'BTCUSD', investment: new Big('1999.9999999999998659756'), @@ -568,7 +542,6 @@ describe('PortfolioCalculator', () => { transactionCount: 1 }, { - name: 'Tesla, Inc.', quantity: new Big('50'), symbol: 'TSLA', investment: new Big('2148.5'), @@ -582,7 +555,6 @@ describe('PortfolioCalculator', () => { date: '2018-09-01', items: [ { - name: 'Amazon.com, Inc.', quantity: new Big('5'), symbol: 'AMZN', investment: new Big('10109.95'), @@ -591,7 +563,6 @@ describe('PortfolioCalculator', () => { transactionCount: 1 }, { - name: 'Bitcoin USD', quantity: new Big('0.5614682'), symbol: 'BTCUSD', investment: new Big('1999.9999999999998659756'), @@ -600,7 +571,6 @@ describe('PortfolioCalculator', () => { transactionCount: 1 }, { - name: 'Tesla, Inc.', quantity: new Big('50'), symbol: 'TSLA', investment: new Big('2148.5'), @@ -645,7 +615,6 @@ describe('PortfolioCalculator', () => { grossPerformancePercentage: new Big('-0.08595335390431712673'), // (657.62-719.46)/719.46=-0.08595335390431712673 investment: new Big('719.46'), marketPrice: 657.62, - name: 'Tesla, Inc.', quantity: new Big('1'), symbol: 'TSLA', transactionCount: 1 @@ -684,7 +653,6 @@ describe('PortfolioCalculator', () => { grossPerformancePercentage: new Big('-0.08595335390431712673'), // (657.62-719.46)/719.46=-0.08595335390431712673 investment: new Big('719.46'), marketPrice: 657.62, - name: 'Tesla, Inc.', quantity: new Big('1'), symbol: 'TSLA', transactionCount: 1 @@ -723,7 +691,6 @@ describe('PortfolioCalculator', () => { grossPerformancePercentage: new Big('-0.01356013560135601356'), // 657.62/666.66-1=-0.013560136 investment: new Big('719.46'), marketPrice: 657.62, - name: 'Tesla, Inc.', quantity: new Big('1'), symbol: 'TSLA', transactionCount: 1 @@ -765,7 +732,6 @@ describe('PortfolioCalculator', () => { ), investment: new Big('4460.95'), marketPrice: 194.86, - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('25'), symbol: 'VTI', transactionCount: 5 @@ -847,7 +813,6 @@ describe('PortfolioCalculator', () => { grossPerformancePercentage: new Big( '0.2753783814827239834392742298083677500037' ), - name: 'Vanguard Total Stock Market Index Fund ETF Shares', currency: 'USD' } ] @@ -867,9 +832,8 @@ describe('PortfolioCalculator', () => { date: '2010-12-31', items: [ { - name: 'Mutual Fund A', quantity: new Big('1000000'), // 1 million - symbol: 'MFA', + symbol: 'MFA', // Mutual Fund A investment: new Big('1000000'), // 1 million currency: Currency.USD, firstBuyDate: '2010-12-31', @@ -881,9 +845,8 @@ describe('PortfolioCalculator', () => { date: '2011-08-15', items: [ { - name: 'Mutual Fund A', quantity: new Big('1086022.689344541'), // 1,000,000 + 100,000 / 1.162484 - symbol: 'MFA', + symbol: 'MFA', // Mutual Fund A investment: new Big('1100000'), // 1,000,000 + 100,000 currency: Currency.USD, firstBuyDate: '2010-12-31', @@ -919,7 +882,6 @@ describe('PortfolioCalculator', () => { transactionCount: 2, grossPerformance: new Big('92327.999656600898394721'), // 1'192'328 - 1'100'000 = 92'328 grossPerformancePercentage: new Big('0.09788498099999947808927632'), // 9.79 % - name: 'Mutual Fund A', currency: 'USD' } ] @@ -939,18 +901,16 @@ describe('PortfolioCalculator', () => { date: '2012-12-31', items: [ { - name: 'Sub Portfolio A', quantity: new Big('200'), - symbol: 'SPA', + symbol: 'SPA', // Sub Portfolio A investment: new Big('200'), currency: Currency.CHF, firstBuyDate: '2012-12-31', transactionCount: 1 }, { - name: 'Sub Portfolio B', quantity: new Big('300'), - symbol: 'SPB', + symbol: 'SPB', // Sub Portfolio B investment: new Big('300'), currency: Currency.CHF, firstBuyDate: '2012-12-31', @@ -962,18 +922,16 @@ describe('PortfolioCalculator', () => { date: '2013-12-31', items: [ { - name: 'Sub Portfolio A', quantity: new Big('200'), - symbol: 'SPA', + symbol: 'SPA', // Sub Portfolio A investment: new Big('200'), currency: Currency.CHF, firstBuyDate: '2012-12-31', transactionCount: 1 }, { - name: 'Sub Portfolio B', quantity: new Big('300'), - symbol: 'SPB', + symbol: 'SPB', // Sub Portfolio B investment: new Big('300'), currency: Currency.CHF, firstBuyDate: '2012-12-31', @@ -1009,7 +967,6 @@ describe('PortfolioCalculator', () => { transactionCount: 1, grossPerformance: new Big('5'), // 205 - 200 grossPerformancePercentage: new Big('0.025'), - name: 'Sub Portfolio A', currency: 'CHF' }, { @@ -1022,7 +979,6 @@ describe('PortfolioCalculator', () => { transactionCount: 1, grossPerformance: new Big('12'), // 312 - 300 grossPerformancePercentage: new Big('0.04'), - name: 'Sub Portfolio B', currency: 'CHF' } ] @@ -1611,7 +1567,6 @@ describe('PortfolioCalculator', () => { date: '2019-02-01', items: [ { - name: 'Amazon.com, Inc.', quantity: new Big('5'), symbol: 'AMZN', investment: new Big('10109.95'), @@ -1620,7 +1575,6 @@ describe('PortfolioCalculator', () => { transactionCount: 1 }, { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('10'), symbol: 'VTI', investment: new Big('1443.8'), @@ -1744,7 +1698,6 @@ const orderTslaTransactionPoint: TransactionPoint[] = [ date: '2021-01-01', items: [ { - name: 'Tesla, Inc.', quantity: new Big('1'), symbol: 'TSLA', investment: new Big('719.46'), @@ -1761,7 +1714,6 @@ const ordersVTITransactionPoints: TransactionPoint[] = [ date: '2019-02-01', items: [ { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('10'), symbol: 'VTI', investment: new Big('1443.8'), @@ -1775,7 +1727,6 @@ const ordersVTITransactionPoints: TransactionPoint[] = [ date: '2019-08-03', items: [ { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('20'), symbol: 'VTI', investment: new Big('2923.7'), @@ -1789,7 +1740,6 @@ const ordersVTITransactionPoints: TransactionPoint[] = [ date: '2020-02-02', items: [ { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('5'), symbol: 'VTI', investment: new Big('652.55'), @@ -1803,7 +1753,6 @@ const ordersVTITransactionPoints: TransactionPoint[] = [ date: '2021-02-01', items: [ { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('15'), symbol: 'VTI', investment: new Big('2684.05'), @@ -1817,7 +1766,6 @@ const ordersVTITransactionPoints: TransactionPoint[] = [ date: '2021-08-01', items: [ { - name: 'Vanguard Total Stock Market Index Fund ETF Shares', quantity: new Big('25'), symbol: 'VTI', investment: new Big('4460.95'), diff --git a/apps/api/src/app/core/portfolio-calculator.ts b/apps/api/src/app/core/portfolio-calculator.ts index 3ff1f4ba3..0af578c30 100644 --- a/apps/api/src/app/core/portfolio-calculator.ts +++ b/apps/api/src/app/core/portfolio-calculator.ts @@ -23,8 +23,7 @@ import { isAfter, isBefore, max, - min, - subDays + min } from 'date-fns'; import { flatten } from 'lodash'; @@ -60,7 +59,6 @@ export class PortfolioCalculator { .mul(order.quantity) .mul(factor) .add(oldAccumulatedSymbol.investment), - name: order.name, quantity: order.quantity .mul(factor) .plus(oldAccumulatedSymbol.quantity), @@ -72,7 +70,6 @@ export class PortfolioCalculator { currency: order.currency, firstBuyDate: order.date, investment: unitPrice.mul(order.quantity).mul(factor), - name: order.name, quantity: order.quantity.mul(factor), symbol: order.symbol, transactionCount: 1 @@ -265,6 +262,7 @@ export class PortfolioCalculator { } const positions: TimelinePosition[] = []; + for (const item of lastTransactionPoint.items) { const marketValue = marketSymbolMap[todayString]?.[item.symbol]; const isValid = invalidSymbols.indexOf(item.symbol) === -1; @@ -281,7 +279,6 @@ export class PortfolioCalculator { : null, investment: item.investment, marketPrice: marketValue?.toNumber() ?? null, - name: item.name, quantity: item.quantity, symbol: item.symbol, transactionCount: item.transactionCount diff --git a/apps/api/src/app/order/order.controller.ts b/apps/api/src/app/order/order.controller.ts index 5671a5c9f..6e7a15026 100644 --- a/apps/api/src/app/order/order.controller.ts +++ b/apps/api/src/app/order/order.controller.ts @@ -80,6 +80,11 @@ export class OrderController { include: { Platform: true } + }, + SymbolProfile: { + select: { + name: true + } } }, orderBy: { date: 'desc' }, diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 68ea64ad2..6ac630b7c 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -239,7 +239,7 @@ export class PortfolioService { investment: item.investment.toNumber(), marketPrice: item.marketPrice, marketState: dataProviderResponse.marketState, - name: item.name, + name: symbolProfile.name, quantity: item.quantity.toNumber(), sectors: symbolProfile.sectors, symbol: item.symbol, @@ -438,6 +438,19 @@ export class PortfolioService { startDate ); + const symbols = currentPositions.positions.map( + (position) => position.symbol + ); + + const [symbolProfiles] = await Promise.all([ + this.symbolProfileService.getSymbolProfiles(symbols) + ]); + + const symbolProfileMap: { [symbol: string]: EnhancedSymbolProfile } = {}; + for (const symbolProfile of symbolProfiles) { + symbolProfileMap[symbolProfile.symbol] = symbolProfile; + } + return { hasErrors: currentPositions.hasErrors, positions: currentPositions.positions.map((position) => { @@ -448,7 +461,7 @@ export class PortfolioService { grossPerformancePercentage: position.grossPerformancePercentage?.toNumber() ?? null, investment: new Big(position.investment).toNumber(), - name: position.name, + name: symbolProfileMap[position.symbol].name, quantity: new Big(position.quantity).toNumber() }; }) diff --git a/apps/client/src/app/components/transactions-table/transactions-table.component.html b/apps/client/src/app/components/transactions-table/transactions-table.component.html index bdb670d71..6cf45b552 100644 --- a/apps/client/src/app/components/transactions-table/transactions-table.component.html +++ b/apps/client/src/app/components/transactions-table/transactions-table.component.html @@ -258,7 +258,12 @@