|
|
|
@ -1302,12 +1302,11 @@ export class PortfolioService {
|
|
|
|
|
}: {
|
|
|
|
|
activities: OrderWithAccount[];
|
|
|
|
|
date?: Date;
|
|
|
|
|
|
|
|
|
|
userCurrency: string;
|
|
|
|
|
}) {
|
|
|
|
|
return activities
|
|
|
|
|
.filter((activity) => {
|
|
|
|
|
// Filter out all activities before given date and type dividend
|
|
|
|
|
// Filter out all activities before given date (drafts) and type dividend
|
|
|
|
|
return (
|
|
|
|
|
isBefore(date, new Date(activity.date)) &&
|
|
|
|
|
activity.type === TypeOfOrder.DIVIDEND
|
|
|
|
@ -1431,7 +1430,7 @@ export class PortfolioService {
|
|
|
|
|
}) {
|
|
|
|
|
return activities
|
|
|
|
|
.filter((activity) => {
|
|
|
|
|
// Filter out all activities before given date
|
|
|
|
|
// Filter out all activities before given date (drafts)
|
|
|
|
|
return isBefore(date, new Date(activity.date));
|
|
|
|
|
})
|
|
|
|
|
.map(({ fee, SymbolProfile }) => {
|
|
|
|
@ -1478,19 +1477,37 @@ export class PortfolioService {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getItems(orders: OrderWithAccount[], date = new Date(0)) {
|
|
|
|
|
return orders
|
|
|
|
|
.filter((order) => {
|
|
|
|
|
// Filter out all orders before given date and type item
|
|
|
|
|
private getItems(activities: OrderWithAccount[], date = new Date(0)) {
|
|
|
|
|
return activities
|
|
|
|
|
.filter((activity) => {
|
|
|
|
|
// Filter out all activities before given date (drafts) and type item
|
|
|
|
|
return (
|
|
|
|
|
isBefore(date, new Date(order.date)) &&
|
|
|
|
|
order.type === TypeOfOrder.ITEM
|
|
|
|
|
isBefore(date, new Date(activity.date)) &&
|
|
|
|
|
activity.type === TypeOfOrder.ITEM
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
.map((order) => {
|
|
|
|
|
.map(({ quantity, SymbolProfile, unitPrice }) => {
|
|
|
|
|
return this.exchangeRateDataService.toCurrency(
|
|
|
|
|
new Big(order.quantity).mul(order.unitPrice).toNumber(),
|
|
|
|
|
order.SymbolProfile.currency,
|
|
|
|
|
new Big(quantity).mul(unitPrice).toNumber(),
|
|
|
|
|
SymbolProfile.currency,
|
|
|
|
|
this.request.user.Settings.settings.baseCurrency
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
.reduce(
|
|
|
|
|
(previous, current) => new Big(previous).plus(current),
|
|
|
|
|
new Big(0)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getLiabilities(activities: OrderWithAccount[]) {
|
|
|
|
|
return activities
|
|
|
|
|
.filter(({ type }) => {
|
|
|
|
|
return type === TypeOfOrder.LIABILITY;
|
|
|
|
|
})
|
|
|
|
|
.map(({ quantity, SymbolProfile, unitPrice }) => {
|
|
|
|
|
return this.exchangeRateDataService.toCurrency(
|
|
|
|
|
new Big(quantity).mul(unitPrice).toNumber(),
|
|
|
|
|
SymbolProfile.currency,
|
|
|
|
|
this.request.user.Settings.settings.baseCurrency
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
@ -1601,6 +1618,7 @@ export class PortfolioService {
|
|
|
|
|
const fees = this.getFees({ activities, userCurrency }).toNumber();
|
|
|
|
|
const firstOrderDate = activities[0]?.date;
|
|
|
|
|
const items = this.getItems(activities).toNumber();
|
|
|
|
|
const liabilities = this.getLiabilities(activities).toNumber();
|
|
|
|
|
|
|
|
|
|
const totalBuy = this.getTotalByType(activities, userCurrency, 'BUY');
|
|
|
|
|
const totalSell = this.getTotalByType(activities, userCurrency, 'SELL');
|
|
|
|
@ -1633,6 +1651,7 @@ export class PortfolioService {
|
|
|
|
|
.plus(performanceInformation.performance.currentValue)
|
|
|
|
|
.plus(items)
|
|
|
|
|
.plus(excludedAccountsAndActivities)
|
|
|
|
|
.minus(liabilities)
|
|
|
|
|
.toNumber();
|
|
|
|
|
|
|
|
|
|
const daysInMarket = differenceInDays(new Date(), firstOrderDate);
|
|
|
|
@ -1659,6 +1678,7 @@ export class PortfolioService {
|
|
|
|
|
fees,
|
|
|
|
|
firstOrderDate,
|
|
|
|
|
items,
|
|
|
|
|
liabilities,
|
|
|
|
|
netWorth,
|
|
|
|
|
totalBuy,
|
|
|
|
|
totalSell,
|
|
|
|
|