Browse Source

add net performance to calculate timeline #324

pull/336/head
Valentin Zickner 4 years ago
committed by Valentin Zickner
parent
commit
c0c1742618
  1. 1
      apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts
  2. 280
      apps/api/src/app/portfolio/portfolio-calculator.spec.ts
  3. 9
      apps/api/src/app/portfolio/portfolio-calculator.ts

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

@ -4,6 +4,7 @@ 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;

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

File diff suppressed because it is too large

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

@ -59,6 +59,7 @@ export class PortfolioCalculator {
currentTransactionPointItem = { currentTransactionPointItem = {
currency: order.currency, currency: order.currency,
fee: order.fee, fee: order.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)
@ -74,6 +75,7 @@ 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),
@ -474,6 +476,7 @@ export class PortfolioCalculator {
endDate: Date endDate: Date
): Promise<TimelinePeriod[]> { ): Promise<TimelinePeriod[]> {
let investment: Big = new Big(0); let investment: Big = new Big(0);
let fees: Big = new Big(0);
const marketSymbolMap: { const marketSymbolMap: {
[date: string]: { [symbol: string]: Big }; [date: string]: { [symbol: string]: Big };
@ -486,6 +489,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);
} }
let marketSymbols: GetValueObject[] = []; let marketSymbols: GetValueObject[] = [];
@ -545,12 +549,13 @@ export class PortfolioCalculator {
} }
} }
if (!invalid) { if (!invalid) {
const grossPerformance = value.minus(investment);
const result = { const result = {
grossPerformance,
investment, investment,
value, value,
date: currentDateAsString, date: currentDateAsString,
grossPerformance: value.minus(investment), netPerformance: grossPerformance.minus(fees)
netPerformance: new Big(0) // TODO
}; };
results.push(result); results.push(result);
} }

Loading…
Cancel
Save