Browse Source

make timeline fee accumulated by default #324

pull/339/head
Valentin Zickner 4 years ago
parent
commit
c868fa7536
  1. 1
      apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts
  2. 97
      apps/api/src/app/portfolio/portfolio-calculator.spec.ts
  3. 20
      apps/api/src/app/portfolio/portfolio-calculator.ts

1
apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts

@ -4,7 +4,6 @@ import Big from 'big.js';
export interface TransactionPointSymbol { export interface TransactionPointSymbol {
currency: Currency; currency: Currency;
fee: Big; fee: Big;
feeAccumulated: Big;
firstBuyDate: string; firstBuyDate: string;
investment: Big; investment: Big;
quantity: Big; quantity: Big;

97
apps/api/src/app/portfolio/portfolio-calculator.spec.ts

@ -194,8 +194,7 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
transactionCount: 1, transactionCount: 1,
fee: new Big('5'), fee: new Big('5')
feeAccumulated: new Big('5')
} }
] ]
}, },
@ -209,8 +208,7 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
transactionCount: 2, transactionCount: 2,
fee: new Big('10'), fee: new Big('15')
feeAccumulated: new Big('15')
} }
] ]
}, },
@ -224,8 +222,7 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
transactionCount: 3, transactionCount: 3,
fee: new Big('5'), fee: new Big('20')
feeAccumulated: new Big('20')
} }
] ]
} }
@ -284,8 +281,7 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
transactionCount: 1, transactionCount: 1,
fee: new Big('5'), fee: new Big('5')
feeAccumulated: new Big('5')
} }
] ]
}, },
@ -299,8 +295,7 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
transactionCount: 1, transactionCount: 1,
fee: new Big('0'), fee: new Big('5')
feeAccumulated: new Big('5')
}, },
{ {
quantity: new Big('10'), quantity: new Big('10'),
@ -309,8 +304,7 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-08-03', firstBuyDate: '2019-08-03',
transactionCount: 1, transactionCount: 1,
fee: new Big('10'), fee: new Big('10')
feeAccumulated: new Big('10')
} }
] ]
}, },
@ -324,8 +318,7 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
transactionCount: 2, transactionCount: 2,
fee: new Big('5'), fee: new Big('10')
feeAccumulated: new Big('10')
}, },
{ {
quantity: new Big('10'), quantity: new Big('10'),
@ -334,8 +327,7 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-08-03', firstBuyDate: '2019-08-03',
transactionCount: 1, transactionCount: 1,
fee: new Big('0'), fee: new Big('10')
feeAccumulated: new Big('10')
} }
] ]
} }
@ -375,7 +367,6 @@ describe('PortfolioCalculator', () => {
quantity: new Big('10'), quantity: new Big('10'),
symbol: 'VTI', symbol: 'VTI',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -390,7 +381,6 @@ describe('PortfolioCalculator', () => {
quantity: new Big('20'), quantity: new Big('20'),
symbol: 'VTI', symbol: 'VTI',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 2 transactionCount: 2
} }
] ]
@ -405,7 +395,6 @@ describe('PortfolioCalculator', () => {
quantity: new Big('5'), quantity: new Big('5'),
symbol: 'VTI', symbol: 'VTI',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 3 transactionCount: 3
} }
] ]
@ -420,7 +409,6 @@ describe('PortfolioCalculator', () => {
quantity: new Big('35'), quantity: new Big('35'),
symbol: 'VTI', symbol: 'VTI',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 5 transactionCount: 5
} }
] ]
@ -435,7 +423,6 @@ describe('PortfolioCalculator', () => {
quantity: new Big('45'), quantity: new Big('45'),
symbol: 'VTI', symbol: 'VTI',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 6 transactionCount: 6
} }
] ]
@ -476,7 +463,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -491,7 +477,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 2 transactionCount: 2
} }
] ]
@ -506,7 +491,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-09-01', firstBuyDate: '2019-09-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
}, },
{ {
@ -516,7 +500,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 2 transactionCount: 2
} }
] ]
@ -531,7 +514,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-09-01', firstBuyDate: '2019-09-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
}, },
{ {
@ -541,7 +523,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 3 transactionCount: 3
} }
] ]
@ -556,7 +537,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-09-01', firstBuyDate: '2019-09-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
}, },
{ {
@ -566,7 +546,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 4 transactionCount: 4
} }
] ]
@ -581,7 +560,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-09-01', firstBuyDate: '2019-09-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
}, },
{ {
@ -591,7 +569,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 5 transactionCount: 5
} }
] ]
@ -656,7 +633,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2017-01-03', firstBuyDate: '2017-01-03',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -671,7 +647,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2017-07-01', firstBuyDate: '2017-07-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
}, },
{ {
@ -681,7 +656,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2017-01-03', firstBuyDate: '2017-01-03',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -696,7 +670,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2018-09-01', firstBuyDate: '2018-09-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
}, },
{ {
@ -706,7 +679,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2017-07-01', firstBuyDate: '2017-07-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
}, },
{ {
@ -716,7 +688,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2017-01-03', firstBuyDate: '2017-01-03',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -959,7 +930,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-09-01', firstBuyDate: '2019-09-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -974,7 +944,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-09-01', firstBuyDate: '2019-09-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 2 transactionCount: 2
} }
] ]
@ -989,7 +958,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-09-01', firstBuyDate: '2019-09-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 3 transactionCount: 3
} }
] ]
@ -1048,7 +1016,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -1064,7 +1031,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 2 transactionCount: 2
} }
] ]
@ -1133,7 +1099,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(50), fee: new Big(50),
feeAccumulated: new Big(50),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -1148,8 +1113,7 @@ describe('PortfolioCalculator', () => {
investment: new Big('2923.7'), investment: new Big('2923.7'),
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(50), fee: new Big(100),
feeAccumulated: new Big(100),
transactionCount: 2 transactionCount: 2
} }
] ]
@ -1226,7 +1190,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(50), fee: new Big(50),
feeAccumulated: new Big(50),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -1241,8 +1204,7 @@ describe('PortfolioCalculator', () => {
investment: new Big('2923.7'), investment: new Big('2923.7'),
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(50), fee: new Big(100),
feeAccumulated: new Big(100),
transactionCount: 2 transactionCount: 2
} }
] ]
@ -1315,7 +1277,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2010-12-31', firstBuyDate: '2010-12-31',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -1330,7 +1291,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2010-12-31', firstBuyDate: '2010-12-31',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 2 transactionCount: 2
} }
] ]
@ -1392,7 +1352,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.CHF, currency: Currency.CHF,
firstBuyDate: '2012-12-31', firstBuyDate: '2012-12-31',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
}, },
{ {
@ -1402,7 +1361,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.CHF, currency: Currency.CHF,
firstBuyDate: '2012-12-31', firstBuyDate: '2012-12-31',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -1417,7 +1375,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.CHF, currency: Currency.CHF,
firstBuyDate: '2012-12-31', firstBuyDate: '2012-12-31',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
}, },
{ {
@ -1427,7 +1384,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.CHF, currency: Currency.CHF,
firstBuyDate: '2012-12-31', firstBuyDate: '2012-12-31',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -1541,7 +1497,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(50), fee: new Big(50),
feeAccumulated: new Big(50),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -1555,8 +1510,7 @@ describe('PortfolioCalculator', () => {
investment: new Big('2923.7'), investment: new Big('2923.7'),
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(50), fee: new Big(100),
feeAccumulated: new Big(100),
transactionCount: 2 transactionCount: 2
} }
] ]
@ -1570,8 +1524,7 @@ describe('PortfolioCalculator', () => {
investment: new Big('652.55'), investment: new Big('652.55'),
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(50), fee: new Big(150),
feeAccumulated: new Big(150),
transactionCount: 3 transactionCount: 3
} }
] ]
@ -1585,8 +1538,7 @@ describe('PortfolioCalculator', () => {
investment: new Big('2684.05'), investment: new Big('2684.05'),
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(50), fee: new Big(200),
feeAccumulated: new Big(200),
transactionCount: 4 transactionCount: 4
} }
] ]
@ -1600,8 +1552,7 @@ describe('PortfolioCalculator', () => {
investment: new Big('4460.95'), investment: new Big('4460.95'),
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(50), fee: new Big(250),
feeAccumulated: new Big(250),
transactionCount: 5 transactionCount: 5
} }
] ]
@ -2266,7 +2217,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
}, },
{ {
@ -2276,7 +2226,6 @@ describe('PortfolioCalculator', () => {
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -2411,7 +2360,6 @@ const orderTslaTransactionPoint: TransactionPoint[] = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2021-01-01', firstBuyDate: '2021-01-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -2429,7 +2377,6 @@ const ordersVTITransactionPoints: TransactionPoint[] = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -2444,7 +2391,6 @@ const ordersVTITransactionPoints: TransactionPoint[] = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 2 transactionCount: 2
} }
] ]
@ -2459,7 +2405,6 @@ const ordersVTITransactionPoints: TransactionPoint[] = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 3 transactionCount: 3
} }
] ]
@ -2474,7 +2419,6 @@ const ordersVTITransactionPoints: TransactionPoint[] = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 4 transactionCount: 4
} }
] ]
@ -2489,7 +2433,6 @@ const ordersVTITransactionPoints: TransactionPoint[] = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 5 transactionCount: 5
} }
] ]
@ -2507,7 +2450,6 @@ const transactionPointsBuyAndSell = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
} }
] ]
@ -2522,7 +2464,6 @@ const transactionPointsBuyAndSell = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 2 transactionCount: 2
} }
] ]
@ -2537,7 +2478,6 @@ const transactionPointsBuyAndSell = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-09-01', firstBuyDate: '2019-09-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
}, },
{ {
@ -2547,7 +2487,6 @@ const transactionPointsBuyAndSell = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 2 transactionCount: 2
} }
] ]
@ -2562,7 +2501,6 @@ const transactionPointsBuyAndSell = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-09-01', firstBuyDate: '2019-09-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 1 transactionCount: 1
}, },
{ {
@ -2572,7 +2510,6 @@ const transactionPointsBuyAndSell = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 3 transactionCount: 3
} }
] ]
@ -2587,7 +2524,6 @@ const transactionPointsBuyAndSell = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-09-01', firstBuyDate: '2019-09-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 2 transactionCount: 2
}, },
{ {
@ -2597,7 +2533,6 @@ const transactionPointsBuyAndSell = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 3 transactionCount: 3
} }
] ]
@ -2612,7 +2547,6 @@ const transactionPointsBuyAndSell = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-09-01', firstBuyDate: '2019-09-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 2 transactionCount: 2
}, },
{ {
@ -2622,7 +2556,6 @@ const transactionPointsBuyAndSell = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 4 transactionCount: 4
} }
] ]
@ -2637,7 +2570,6 @@ const transactionPointsBuyAndSell = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-09-01', firstBuyDate: '2019-09-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 2 transactionCount: 2
}, },
{ {
@ -2647,7 +2579,6 @@ const transactionPointsBuyAndSell = [
currency: Currency.USD, currency: Currency.USD,
firstBuyDate: '2019-02-01', firstBuyDate: '2019-02-01',
fee: new Big(0), fee: new Big(0),
feeAccumulated: new Big(0),
transactionCount: 5 transactionCount: 5
} }
] ]

20
apps/api/src/app/portfolio/portfolio-calculator.ts

@ -58,8 +58,7 @@ export class PortfolioCalculator {
.plus(oldAccumulatedSymbol.quantity); .plus(oldAccumulatedSymbol.quantity);
currentTransactionPointItem = { currentTransactionPointItem = {
currency: order.currency, currency: order.currency,
fee: order.fee, fee: order.fee.plus(oldAccumulatedSymbol.fee),
feeAccumulated: order.fee.plus(oldAccumulatedSymbol.feeAccumulated),
firstBuyDate: oldAccumulatedSymbol.firstBuyDate, firstBuyDate: oldAccumulatedSymbol.firstBuyDate,
investment: newQuantity.eq(0) investment: newQuantity.eq(0)
? new Big(0) ? new Big(0)
@ -75,7 +74,6 @@ export class PortfolioCalculator {
currentTransactionPointItem = { currentTransactionPointItem = {
currency: order.currency, currency: order.currency,
fee: order.fee, fee: order.fee,
feeAccumulated: order.fee,
firstBuyDate: order.date, firstBuyDate: order.date,
investment: unitPrice.mul(order.quantity).mul(factor), investment: unitPrice.mul(order.quantity).mul(factor),
quantity: order.quantity.mul(factor), quantity: order.quantity.mul(factor),
@ -87,14 +85,9 @@ export class PortfolioCalculator {
symbols[order.symbol] = currentTransactionPointItem; symbols[order.symbol] = currentTransactionPointItem;
const items = lastTransactionPoint?.items ?? []; const items = lastTransactionPoint?.items ?? [];
const newItems = items const newItems = items.filter(
.filter(
(transactionPointItem) => transactionPointItem.symbol !== order.symbol (transactionPointItem) => transactionPointItem.symbol !== order.symbol
) );
.map((transactionPoint) => ({
...transactionPoint,
fee: new Big(0)
}));
newItems.push(currentTransactionPointItem); newItems.push(currentTransactionPointItem);
newItems.sort((a, b) => a.symbol.localeCompare(b.symbol)); newItems.sort((a, b) => a.symbol.localeCompare(b.symbol));
if (lastDate !== currentDate || lastTransactionPoint === null) { if (lastDate !== currentDate || lastTransactionPoint === null) {
@ -203,6 +196,7 @@ export class PortfolioCalculator {
const invalidSymbols = []; const invalidSymbols = [];
const lastInvestments: { [symbol: string]: Big } = {}; const lastInvestments: { [symbol: string]: Big } = {};
const lastQuantities: { [symbol: string]: Big } = {}; const lastQuantities: { [symbol: string]: Big } = {};
const lastFees: { [symbol: string]: Big } = {};
const initialValues: { [symbol: string]: Big } = {}; const initialValues: { [symbol: string]: Big } = {};
for (let i = firstIndex; i < this.transactionPoints.length; i++) { for (let i = firstIndex; i < this.transactionPoints.length; i++) {
@ -236,9 +230,10 @@ export class PortfolioCalculator {
const isFirstOrderAndIsStartBeforeCurrentDate = const isFirstOrderAndIsStartBeforeCurrentDate =
i === firstIndex && i === firstIndex &&
isBefore(parseDate(this.transactionPoints[i].date), start); isBefore(parseDate(this.transactionPoints[i].date), start);
const lastFee: Big = lastFees[item.symbol] ?? new Big(0);
const fee = isFirstOrderAndIsStartBeforeCurrentDate const fee = isFirstOrderAndIsStartBeforeCurrentDate
? new Big(0) ? new Big(0)
: item.fee; : item.fee.minus(lastFee);
if (!isAfter(parseDate(currentDate), parseDate(item.firstBuyDate))) { if (!isAfter(parseDate(currentDate), parseDate(item.firstBuyDate))) {
initialValue = item.investment; initialValue = item.investment;
investedValue = item.investment; investedValue = item.investment;
@ -281,6 +276,7 @@ export class PortfolioCalculator {
} }
lastInvestments[item.symbol] = item.investment; lastInvestments[item.symbol] = item.investment;
lastQuantities[item.symbol] = item.quantity; lastQuantities[item.symbol] = item.quantity;
lastFees[item.symbol] = item.fee;
} }
} }
@ -489,7 +485,7 @@ export class PortfolioCalculator {
currencies[item.symbol] = item.currency; currencies[item.symbol] = item.currency;
symbols.push(item.symbol); symbols.push(item.symbol);
investment = investment.add(item.investment); investment = investment.add(item.investment);
fees = fees.add(item.feeAccumulated); fees = fees.add(item.fee);
} }
let marketSymbols: GetValueObject[] = []; let marketSymbols: GetValueObject[] = [];

Loading…
Cancel
Save