Browse Source

Add name to position

pull/239/head
Thomas 4 years ago
parent
commit
e0435e5cad
  1. 31
      apps/api/src/app/core/portfolio-calculator.ts
  2. 7
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 1
      libs/common/src/lib/interfaces/timeline-position.interface.ts

31
apps/api/src/app/core/portfolio-calculator.ts

@ -56,25 +56,27 @@ export class PortfolioCalculator {
const unitPrice = new Big(order.unitPrice); const unitPrice = new Big(order.unitPrice);
if (oldAccumulatedSymbol) { if (oldAccumulatedSymbol) {
currentTransactionPointItem = { currentTransactionPointItem = {
quantity: order.quantity currency: order.currency,
.mul(factor) firstBuyDate: oldAccumulatedSymbol.firstBuyDate,
.plus(oldAccumulatedSymbol.quantity),
symbol: order.symbol,
investment: unitPrice investment: unitPrice
.mul(order.quantity) .mul(order.quantity)
.mul(factor) .mul(factor)
.add(oldAccumulatedSymbol.investment), .add(oldAccumulatedSymbol.investment),
currency: order.currency, name: order.name,
firstBuyDate: oldAccumulatedSymbol.firstBuyDate, quantity: order.quantity
.mul(factor)
.plus(oldAccumulatedSymbol.quantity),
symbol: order.symbol,
transactionCount: oldAccumulatedSymbol.transactionCount + 1 transactionCount: oldAccumulatedSymbol.transactionCount + 1
}; };
} else { } else {
currentTransactionPointItem = { currentTransactionPointItem = {
quantity: order.quantity.mul(factor),
symbol: order.symbol,
investment: unitPrice.mul(order.quantity).mul(factor),
currency: order.currency, currency: order.currency,
firstBuyDate: order.date, firstBuyDate: order.date,
investment: unitPrice.mul(order.quantity).mul(factor),
name: order.name,
quantity: order.quantity.mul(factor),
symbol: order.symbol,
transactionCount: 1 transactionCount: 1
}; };
} }
@ -147,6 +149,7 @@ export class PortfolioCalculator {
: null, : null,
investment: item.investment, investment: item.investment,
marketPrice: marketValue?.marketPrice, marketPrice: marketValue?.marketPrice,
name: item.name,
quantity: item.quantity, quantity: item.quantity,
symbol: item.symbol, symbol: item.symbol,
transactionCount: item.transactionCount transactionCount: item.transactionCount
@ -384,11 +387,12 @@ interface TransactionPoint {
} }
interface TransactionPointSymbol { interface TransactionPointSymbol {
quantity: Big;
symbol: string;
investment: Big;
currency: Currency; currency: Currency;
firstBuyDate: string; firstBuyDate: string;
investment: Big;
name: string;
quantity: Big;
symbol: string;
transactionCount: number; transactionCount: number;
} }
@ -407,10 +411,11 @@ export interface TimelinePeriod {
} }
export interface PortfolioOrder { export interface PortfolioOrder {
currency: Currency;
date: string; date: string;
name: string;
quantity: Big; quantity: Big;
symbol: string; symbol: string;
type: OrderType; type: OrderType;
unitPrice: Big; unitPrice: Big;
currency: Currency;
} }

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

@ -231,7 +231,7 @@ export class PortfolioService {
position.grossPerformancePercentage position.grossPerformancePercentage
).toNumber(), ).toNumber(),
investment: new Big(position.investment).toNumber(), investment: new Big(position.investment).toNumber(),
name: '', // TODO name: position.name,
quantity: new Big(position.quantity).toNumber(), quantity: new Big(position.quantity).toNumber(),
type: Type.Unknown, // TODO type: Type.Unknown, // TODO
url: '' // TODO url: '' // TODO
@ -267,12 +267,13 @@ export class PortfolioService {
} }
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({ const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({
currency: order.currency,
date: format(order.date, 'yyyy-MM-dd'), date: format(order.date, 'yyyy-MM-dd'),
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)
currency: order.currency
})); }));
const portfolioCalculator = new PortfolioCalculator( const portfolioCalculator = new PortfolioCalculator(

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

@ -9,6 +9,7 @@ export interface TimelinePosition {
grossPerformancePercentage: Big; grossPerformancePercentage: Big;
investment: Big; investment: Big;
marketPrice: number; marketPrice: number;
name: string;
quantity: Big; quantity: Big;
symbol: string; symbol: string;
transactionCount: number; transactionCount: number;

Loading…
Cancel
Save