Browse Source

Clean up after code review

pull/339/head
Thomas 4 years ago
parent
commit
d1553975e1
  1. 2
      apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts
  2. 2
      apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts
  3. 14
      apps/api/src/app/portfolio/portfolio-calculator.ts
  4. 18
      apps/api/src/app/portfolio/portfolio.service.ts
  5. 4
      libs/common/src/lib/interfaces/timeline-position.interface.ts

2
apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts

@ -5,10 +5,10 @@ import Big from 'big.js';
export interface PortfolioOrder {
currency: Currency;
date: string;
fee: Big;
name: string;
quantity: Big;
symbol: string;
type: OrderType;
unitPrice: Big;
fee: Big;
}

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

@ -3,10 +3,10 @@ import Big from 'big.js';
export interface TransactionPointSymbol {
currency: Currency;
fee: Big;
firstBuyDate: string;
investment: Big;
quantity: Big;
symbol: string;
transactionCount: number;
fee: Big;
}

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

@ -58,6 +58,7 @@ export class PortfolioCalculator {
.plus(oldAccumulatedSymbol.quantity);
currentTransactionPointItem = {
currency: order.currency,
fee: order.fee,
firstBuyDate: oldAccumulatedSymbol.firstBuyDate,
investment: newQuantity.eq(0)
? new Big(0)
@ -67,17 +68,16 @@ export class PortfolioCalculator {
.add(oldAccumulatedSymbol.investment),
quantity: newQuantity,
symbol: order.symbol,
fee: order.fee,
transactionCount: oldAccumulatedSymbol.transactionCount + 1
};
} else {
currentTransactionPointItem = {
currency: order.currency,
fee: order.fee,
firstBuyDate: order.date,
investment: unitPrice.mul(order.quantity).mul(factor),
quantity: order.quantity.mul(factor),
symbol: order.symbol,
fee: order.fee,
transactionCount: 1
};
}
@ -119,13 +119,13 @@ export class PortfolioCalculator {
public async getCurrentPositions(start: Date): Promise<CurrentPositions> {
if (!this.transactionPoints?.length) {
return {
currentValue: new Big(0),
hasErrors: false,
positions: [],
grossPerformance: new Big(0),
grossPerformancePercentage: new Big(0),
netPerformance: new Big(0),
netPerformancePercentage: new Big(0),
currentValue: new Big(0),
positions: [],
totalInvestment: new Big(0)
};
}
@ -300,13 +300,13 @@ export class PortfolioCalculator {
isValid && holdingPeriodReturns[item.symbol]
? holdingPeriodReturns[item.symbol].minus(1)
: null,
investment: item.investment,
marketPrice: marketValue?.toNumber() ?? null,
netPerformance: isValid ? netPerformance[item.symbol] ?? null : null,
netPerformancePercentage:
isValid && netHoldingPeriodReturns[item.symbol]
? netHoldingPeriodReturns[item.symbol].minus(1)
: null,
investment: item.investment,
marketPrice: marketValue?.toNumber() ?? null,
quantity: item.quantity,
symbol: item.symbol,
transactionCount: item.transactionCount
@ -461,9 +461,9 @@ export class PortfolioCalculator {
currentValue,
grossPerformance,
grossPerformancePercentage,
hasErrors,
netPerformance,
netPerformancePercentage,
hasErrors,
totalInvestment
};
}

18
apps/api/src/app/portfolio/portfolio.service.ts

@ -292,12 +292,12 @@ export class PortfolioService {
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({
currency: order.currency,
date: format(order.date, DATE_FORMAT),
fee: new Big(order.fee),
name: order.SymbolProfile?.name,
quantity: new Big(order.quantity),
symbol: order.symbol,
type: <OrderType>order.type,
unitPrice: new Big(order.unitPrice),
fee: new Big(order.fee)
unitPrice: new Big(order.unitPrice)
}));
const portfolioCalculator = new PortfolioCalculator(
@ -780,6 +780,13 @@ export class PortfolioService {
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({
currency: order.currency,
date: format(order.date, DATE_FORMAT),
fee: new Big(
this.exchangeRateDataService.toCurrency(
order.fee,
order.currency,
userCurrency
)
),
name: order.SymbolProfile?.name,
quantity: new Big(order.quantity),
symbol: order.symbol,
@ -790,13 +797,6 @@ export class PortfolioService {
order.currency,
userCurrency
)
),
fee: new Big(
this.exchangeRateDataService.toCurrency(
order.fee,
order.currency,
userCurrency
)
)
}));

4
libs/common/src/lib/interfaces/timeline-position.interface.ts

@ -7,10 +7,10 @@ export interface TimelinePosition {
firstBuyDate: string;
grossPerformance: Big;
grossPerformancePercentage: Big;
netPerformance: Big;
netPerformancePercentage: Big;
investment: Big;
marketPrice: number;
netPerformance: Big;
netPerformancePercentage: Big;
quantity: Big;
symbol: string;
transactionCount: number;

Loading…
Cancel
Save