Browse Source

Clean up after code review

pull/330/head
Thomas 4 years ago
parent
commit
68b1085b4d
  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 { export interface PortfolioOrder {
currency: Currency; currency: Currency;
date: string; date: string;
fee: Big;
name: string; name: string;
quantity: Big; quantity: Big;
symbol: string; symbol: string;
type: OrderType; type: OrderType;
unitPrice: Big; 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 { export interface TransactionPointSymbol {
currency: Currency; currency: Currency;
fee: Big;
firstBuyDate: string; firstBuyDate: string;
investment: Big; investment: Big;
quantity: Big; quantity: Big;
symbol: string; symbol: string;
transactionCount: number; transactionCount: number;
fee: Big;
} }

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

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

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

@ -291,12 +291,12 @@ export class PortfolioService {
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({ const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({
currency: order.currency, currency: order.currency,
date: format(order.date, DATE_FORMAT), date: format(order.date, DATE_FORMAT),
fee: new Big(order.fee),
name: order.SymbolProfile?.name, name: order.SymbolProfile?.name,
quantity: new Big(order.quantity), quantity: new Big(order.quantity),
symbol: order.symbol, symbol: order.symbol,
type: <OrderType>order.type, type: <OrderType>order.type,
unitPrice: new Big(order.unitPrice), unitPrice: new Big(order.unitPrice)
fee: new Big(order.fee)
})); }));
const portfolioCalculator = new PortfolioCalculator( const portfolioCalculator = new PortfolioCalculator(
@ -779,6 +779,13 @@ export class PortfolioService {
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({ const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({
currency: order.currency, currency: order.currency,
date: format(order.date, DATE_FORMAT), date: format(order.date, DATE_FORMAT),
fee: new Big(
this.exchangeRateDataService.toCurrency(
order.fee,
order.currency,
userCurrency
)
),
name: order.SymbolProfile?.name, name: order.SymbolProfile?.name,
quantity: new Big(order.quantity), quantity: new Big(order.quantity),
symbol: order.symbol, symbol: order.symbol,
@ -789,13 +796,6 @@ export class PortfolioService {
order.currency, order.currency,
userCurrency 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; firstBuyDate: string;
grossPerformance: Big; grossPerformance: Big;
grossPerformancePercentage: Big; grossPerformancePercentage: Big;
netPerformance: Big;
netPerformancePercentage: Big;
investment: Big; investment: Big;
marketPrice: number; marketPrice: number;
netPerformance: Big;
netPerformancePercentage: Big;
quantity: Big; quantity: Big;
symbol: string; symbol: string;
transactionCount: number; transactionCount: number;

Loading…
Cancel
Save