Browse Source

Add dividend to portfolio summary

pull/547/head
Thomas 4 years ago
parent
commit
eee61da915
  1. 1
      apps/api/src/app/portfolio/portfolio.controller.ts
  2. 63
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 14
      apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html
  4. 1
      libs/common/src/lib/interfaces/portfolio-summary.interface.ts

1
apps/api/src/app/portfolio/portfolio.controller.ts

@ -330,6 +330,7 @@ export class PortfolioController {
'currentGrossPerformance', 'currentGrossPerformance',
'currentNetPerformance', 'currentNetPerformance',
'currentValue', 'currentValue',
'dividend',
'fees', 'fees',
'netWorth', 'netWorth',
'totalBuy', 'totalBuy',

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

@ -729,22 +729,6 @@ export class PortfolioService {
}; };
} }
public getFees(orders: OrderWithAccount[], date = new Date(0)) {
return orders
.filter((order) => {
// Filter out all orders before given date
return isBefore(date, new Date(order.date));
})
.map((order) => {
return this.exchangeRateDataService.toCurrency(
order.fee,
order.currency,
this.request.user.Settings.currency
);
})
.reduce((previous, current) => previous + current, 0);
}
public async getReport(impersonationId: string): Promise<PortfolioReport> { public async getReport(impersonationId: string): Promise<PortfolioReport> {
const currency = this.request.user.Settings.currency; const currency = this.request.user.Settings.currency;
const userId = await this.getUserId(impersonationId, this.request.user.id); const userId = await this.getUserId(impersonationId, this.request.user.id);
@ -825,7 +809,7 @@ export class PortfolioService {
new FeeRatioInitialInvestment( new FeeRatioInitialInvestment(
this.exchangeRateDataService, this.exchangeRateDataService,
currentPositions.totalInvestment.toNumber(), currentPositions.totalInvestment.toNumber(),
this.getFees(orders) this.getFees(orders).toNumber()
) )
], ],
{ baseCurrency: currency } { baseCurrency: currency }
@ -845,7 +829,8 @@ export class PortfolioService {
currency currency
); );
const orders = await this.orderService.getOrders({ userId }); const orders = await this.orderService.getOrders({ userId });
const fees = this.getFees(orders); const dividend = this.getDividend(orders).toNumber();
const fees = this.getFees(orders).toNumber();
const firstOrderDate = orders[0]?.date; const firstOrderDate = orders[0]?.date;
const totalBuy = this.getTotalByType(orders, currency, 'BUY'); const totalBuy = this.getTotalByType(orders, currency, 'BUY');
@ -859,6 +844,7 @@ export class PortfolioService {
return { return {
...performanceInformation.performance, ...performanceInformation.performance,
dividend,
fees, fees,
firstOrderDate, firstOrderDate,
netWorth, netWorth,
@ -939,6 +925,47 @@ export class PortfolioService {
return cashPositions; return cashPositions;
} }
private getDividend(orders: OrderWithAccount[], date = new Date(0)) {
return orders
.filter((order) => {
// Filter out all orders before given date and type dividend
return (
isBefore(date, new Date(order.date)) &&
order.type === TypeOfOrder.DIVIDEND
);
})
.map((order) => {
return this.exchangeRateDataService.toCurrency(
new Big(order.quantity).mul(order.unitPrice).toNumber(),
order.currency,
this.request.user.Settings.currency
);
})
.reduce(
(previous, current) => new Big(previous).plus(current),
new Big(0)
);
}
private getFees(orders: OrderWithAccount[], date = new Date(0)) {
return orders
.filter((order) => {
// Filter out all orders before given date
return isBefore(date, new Date(order.date));
})
.map((order) => {
return this.exchangeRateDataService.toCurrency(
order.fee,
order.currency,
this.request.user.Settings.currency
);
})
.reduce(
(previous, current) => new Big(previous).plus(current),
new Big(0)
);
}
private getStartDate(aDateRange: DateRange, portfolioStart: Date) { private getStartDate(aDateRange: DateRange, portfolioStart: Date) {
switch (aDateRange) { switch (aDateRange) {
case '1d': case '1d':

14
apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html

@ -48,6 +48,20 @@
></gf-value> ></gf-value>
</div> </div>
</div> </div>
<div class="row px-3 py-1">
<div class="d-flex flex-grow-1" i18n>Dividend</div>
<div class="d-flex justify-content-end">
<span *ngIf="summary?.dividend || summary?.dividend === 0" class="mr-1"
>+</span
>
<gf-value
class="justify-content-end"
[currency]="baseCurrency"
[locale]="locale"
[value]="isLoading ? undefined : summary?.dividend"
></gf-value>
</div>
</div>
<div class="row px-3 py-1"> <div class="row px-3 py-1">
<div class="d-flex flex-grow-1" i18n>Absolute Gross Performance</div> <div class="d-flex flex-grow-1" i18n>Absolute Gross Performance</div>
<div class="d-flex justify-content-end"> <div class="d-flex justify-content-end">

1
libs/common/src/lib/interfaces/portfolio-summary.interface.ts

@ -3,6 +3,7 @@ import { PortfolioPerformance } from './portfolio-performance.interface';
export interface PortfolioSummary extends PortfolioPerformance { export interface PortfolioSummary extends PortfolioPerformance {
annualizedPerformancePercent: number; annualizedPerformancePercent: number;
cash: number; cash: number;
dividend: number;
committedFunds: number; committedFunds: number;
fees: number; fees: number;
firstOrderDate: Date; firstOrderDate: Date;

Loading…
Cancel
Save