Browse Source

Integrate dividend into transaction point concept

pull/3092/head
Thomas Kaul 2 years ago
parent
commit
67b29814b1
  1. 2
      apps/api/src/app/order/order.service.ts
  2. 1
      apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts
  3. 2
      apps/api/src/app/portfolio/portfolio-calculator-baln-buy-and-sell.spec.ts
  4. 2
      apps/api/src/app/portfolio/portfolio-calculator-baln-buy.spec.ts
  5. 2
      apps/api/src/app/portfolio/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts
  6. 2
      apps/api/src/app/portfolio/portfolio-calculator-googl-buy.spec.ts
  7. 2
      apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell-partially.spec.ts
  8. 2
      apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell.spec.ts
  9. 74
      apps/api/src/app/portfolio/portfolio-calculator.ts
  10. 22
      apps/api/src/app/portfolio/portfolio.controller.ts
  11. 64
      apps/api/src/app/portfolio/portfolio.service.ts
  12. 2
      apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html
  13. 1
      libs/common/src/lib/interfaces/portfolio-position.interface.ts
  14. 2
      libs/common/src/lib/interfaces/portfolio-summary.interface.ts
  15. 2
      libs/common/src/lib/interfaces/symbol-metrics.interface.ts
  16. 2
      libs/common/src/lib/interfaces/timeline-position.interface.ts

2
apps/api/src/app/order/order.service.ts

@ -340,11 +340,13 @@ export class OrderService {
return { return {
...order, ...order,
value, value,
// TODO: Use exchange rate of date
feeInBaseCurrency: this.exchangeRateDataService.toCurrency( feeInBaseCurrency: this.exchangeRateDataService.toCurrency(
order.fee, order.fee,
order.SymbolProfile.currency, order.SymbolProfile.currency,
userCurrency userCurrency
), ),
// TODO: Use exchange rate of date
valueInBaseCurrency: this.exchangeRateDataService.toCurrency( valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
value, value,
order.SymbolProfile.currency, order.SymbolProfile.currency,

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

@ -4,6 +4,7 @@ import Big from 'big.js';
export interface TransactionPointSymbol { export interface TransactionPointSymbol {
currency: string; currency: string;
dataSource: DataSource; dataSource: DataSource;
dividend: Big;
fee: Big; fee: Big;
firstBuyDate: string; firstBuyDate: string;
investment: Big; investment: Big;

2
apps/api/src/app/portfolio/portfolio-calculator-baln-buy-and-sell.spec.ts

@ -107,6 +107,8 @@ describe('PortfolioCalculator', () => {
averagePrice: new Big('0'), averagePrice: new Big('0'),
currency: 'CHF', currency: 'CHF',
dataSource: 'YAHOO', dataSource: 'YAHOO',
dividend: new Big('0'),
dividendInBaseCurrency: new Big('0'),
fee: new Big('3.2'), fee: new Big('3.2'),
firstBuyDate: '2021-11-22', firstBuyDate: '2021-11-22',
grossPerformance: new Big('-12.6'), grossPerformance: new Big('-12.6'),

2
apps/api/src/app/portfolio/portfolio-calculator-baln-buy.spec.ts

@ -96,6 +96,8 @@ describe('PortfolioCalculator', () => {
averagePrice: new Big('136.6'), averagePrice: new Big('136.6'),
currency: 'CHF', currency: 'CHF',
dataSource: 'YAHOO', dataSource: 'YAHOO',
dividend: new Big('0'),
dividendInBaseCurrency: new Big('0'),
fee: new Big('1.55'), fee: new Big('1.55'),
firstBuyDate: '2021-11-30', firstBuyDate: '2021-11-30',
grossPerformance: new Big('24.6'), grossPerformance: new Big('24.6'),

2
apps/api/src/app/portfolio/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts

@ -120,6 +120,8 @@ describe('PortfolioCalculator', () => {
averagePrice: new Big('320.43'), averagePrice: new Big('320.43'),
currency: 'USD', currency: 'USD',
dataSource: 'YAHOO', dataSource: 'YAHOO',
dividend: new Big('0'),
dividendInBaseCurrency: new Big('0'),
fee: new Big('0'), fee: new Big('0'),
firstBuyDate: '2015-01-01', firstBuyDate: '2015-01-01',
grossPerformance: new Big('27172.74'), grossPerformance: new Big('27172.74'),

2
apps/api/src/app/portfolio/portfolio-calculator-googl-buy.spec.ts

@ -109,6 +109,8 @@ describe('PortfolioCalculator', () => {
averagePrice: new Big('89.12'), averagePrice: new Big('89.12'),
currency: 'USD', currency: 'USD',
dataSource: 'YAHOO', dataSource: 'YAHOO',
dividend: new Big('0'),
dividendInBaseCurrency: new Big('0'),
fee: new Big('1'), fee: new Big('1'),
firstBuyDate: '2023-01-03', firstBuyDate: '2023-01-03',
grossPerformance: new Big('27.33'), grossPerformance: new Big('27.33'),

2
apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell-partially.spec.ts

@ -107,6 +107,8 @@ describe('PortfolioCalculator', () => {
averagePrice: new Big('75.80'), averagePrice: new Big('75.80'),
currency: 'CHF', currency: 'CHF',
dataSource: 'YAHOO', dataSource: 'YAHOO',
dividend: new Big('0'),
dividendInBaseCurrency: new Big('0'),
fee: new Big('4.25'), fee: new Big('4.25'),
firstBuyDate: '2022-03-07', firstBuyDate: '2022-03-07',
grossPerformance: new Big('21.93'), grossPerformance: new Big('21.93'),

2
apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell.spec.ts

@ -133,6 +133,8 @@ describe('PortfolioCalculator', () => {
averagePrice: new Big('0'), averagePrice: new Big('0'),
currency: 'CHF', currency: 'CHF',
dataSource: 'YAHOO', dataSource: 'YAHOO',
dividend: new Big('0'),
dividendInBaseCurrency: new Big('0'),
fee: new Big('0'), fee: new Big('0'),
firstBuyDate: '2022-03-07', firstBuyDate: '2022-03-07',
grossPerformance: new Big('19.86'), grossPerformance: new Big('19.86'),

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

@ -70,6 +70,7 @@ export class PortfolioCalculator {
let lastDate: string = null; let lastDate: string = null;
let lastTransactionPoint: TransactionPoint = null; let lastTransactionPoint: TransactionPoint = null;
for (const order of this.orders) { for (const order of this.orders) {
const currentDate = order.date; const currentDate = order.date;
@ -78,12 +79,13 @@ export class PortfolioCalculator {
const factor = getFactor(order.type); const factor = getFactor(order.type);
const unitPrice = new Big(order.unitPrice); const unitPrice = new Big(order.unitPrice);
if (oldAccumulatedSymbol) { if (oldAccumulatedSymbol) {
const newQuantity = order.quantity const newQuantity = order.quantity
.mul(factor) .mul(factor)
.plus(oldAccumulatedSymbol.quantity); .plus(oldAccumulatedSymbol.quantity);
let investment = new Big(0); let investment = oldAccumulatedSymbol.investment;
if (newQuantity.gt(0)) { if (newQuantity.gt(0)) {
if (order.type === 'BUY') { if (order.type === 'BUY') {
@ -104,6 +106,7 @@ export class PortfolioCalculator {
investment, investment,
currency: order.currency, currency: order.currency,
dataSource: order.dataSource, dataSource: order.dataSource,
dividend: new Big(0),
fee: order.fee.plus(oldAccumulatedSymbol.fee), fee: order.fee.plus(oldAccumulatedSymbol.fee),
firstBuyDate: oldAccumulatedSymbol.firstBuyDate, firstBuyDate: oldAccumulatedSymbol.firstBuyDate,
quantity: newQuantity, quantity: newQuantity,
@ -115,6 +118,7 @@ export class PortfolioCalculator {
currentTransactionPointItem = { currentTransactionPointItem = {
currency: order.currency, currency: order.currency,
dataSource: order.dataSource, dataSource: order.dataSource,
dividend: new Big(0),
fee: order.fee, fee: order.fee,
firstBuyDate: order.date, firstBuyDate: order.date,
investment: unitPrice.mul(order.quantity).mul(factor), investment: unitPrice.mul(order.quantity).mul(factor),
@ -583,6 +587,8 @@ export class PortfolioCalculator {
); );
const { const {
dividend,
dividendInBaseCurrency,
grossPerformance, grossPerformance,
grossPerformancePercentage, grossPerformancePercentage,
grossPerformancePercentageWithCurrencyEffect, grossPerformancePercentageWithCurrencyEffect,
@ -608,6 +614,8 @@ export class PortfolioCalculator {
hasAnySymbolMetricsErrors = hasAnySymbolMetricsErrors || hasErrors; hasAnySymbolMetricsErrors = hasAnySymbolMetricsErrors || hasErrors;
positions.push({ positions.push({
dividend,
dividendInBaseCurrency,
timeWeightedInvestment, timeWeightedInvestment,
timeWeightedInvestmentWithCurrencyEffect, timeWeightedInvestmentWithCurrencyEffect,
averagePrice: item.quantity.eq(0) averagePrice: item.quantity.eq(0)
@ -842,6 +850,8 @@ export class PortfolioCalculator {
const currentExchangeRate = exchangeRates[format(new Date(), DATE_FORMAT)]; const currentExchangeRate = exchangeRates[format(new Date(), DATE_FORMAT)];
const currentValues: { [date: string]: Big } = {}; const currentValues: { [date: string]: Big } = {};
const currentValuesWithCurrencyEffect: { [date: string]: Big } = {}; const currentValuesWithCurrencyEffect: { [date: string]: Big } = {};
let dividend = new Big(0);
let dividendInBaseCurrency = new Big(0);
let fees = new Big(0); let fees = new Big(0);
let feesAtStartDate = new Big(0); let feesAtStartDate = new Big(0);
let feesAtStartDateWithCurrencyEffect = new Big(0); let feesAtStartDateWithCurrencyEffect = new Big(0);
@ -894,6 +904,8 @@ export class PortfolioCalculator {
return { return {
currentValues: {}, currentValues: {},
currentValuesWithCurrencyEffect: {}, currentValuesWithCurrencyEffect: {},
dividend: new Big(0),
dividendInBaseCurrency: new Big(0),
grossPerformance: new Big(0), grossPerformance: new Big(0),
grossPerformancePercentage: new Big(0), grossPerformancePercentage: new Big(0),
grossPerformancePercentageWithCurrencyEffect: new Big(0), grossPerformancePercentageWithCurrencyEffect: new Big(0),
@ -934,6 +946,8 @@ export class PortfolioCalculator {
return { return {
currentValues: {}, currentValues: {},
currentValuesWithCurrencyEffect: {}, currentValuesWithCurrencyEffect: {},
dividend: new Big(0),
dividendInBaseCurrency: new Big(0),
grossPerformance: new Big(0), grossPerformance: new Big(0),
grossPerformancePercentage: new Big(0), grossPerformancePercentage: new Big(0),
grossPerformancePercentageWithCurrencyEffect: new Big(0), grossPerformancePercentageWithCurrencyEffect: new Big(0),
@ -1108,29 +1122,29 @@ export class PortfolioCalculator {
valueOfInvestmentBeforeTransactionWithCurrencyEffect; valueOfInvestmentBeforeTransactionWithCurrencyEffect;
} }
const transactionInvestment = let transactionInvestment = new Big(0);
order.type === 'BUY' let transactionInvestmentWithCurrencyEffect = new Big(0);
? order.quantity
.mul(order.unitPriceInBaseCurrency) if (order.type === 'BUY') {
.mul(getFactor(order.type)) transactionInvestment = order.quantity
: totalUnits.gt(0) .mul(order.unitPriceInBaseCurrency)
? totalInvestment .mul(getFactor(order.type));
.div(totalUnits) transactionInvestmentWithCurrencyEffect = order.quantity
.mul(order.quantity) .mul(order.unitPriceInBaseCurrencyWithCurrencyEffect)
.mul(getFactor(order.type)) .mul(getFactor(order.type));
: new Big(0); } else if (order.type === 'SELL') {
if (totalUnits.gt(0)) {
const transactionInvestmentWithCurrencyEffect = transactionInvestment = totalInvestment
order.type === 'BUY' .div(totalUnits)
? order.quantity .mul(order.quantity)
.mul(order.unitPriceInBaseCurrencyWithCurrencyEffect) .mul(getFactor(order.type));
.mul(getFactor(order.type)) transactionInvestmentWithCurrencyEffect =
: totalUnits.gt(0) totalInvestmentWithCurrencyEffect
? totalInvestmentWithCurrencyEffect .div(totalUnits)
.div(totalUnits) .mul(order.quantity)
.mul(order.quantity) .mul(getFactor(order.type));
.mul(getFactor(order.type)) }
: new Big(0); }
if (PortfolioCalculator.ENABLE_LOGGING) { if (PortfolioCalculator.ENABLE_LOGGING) {
console.log('totalInvestment', totalInvestment.toNumber()); console.log('totalInvestment', totalInvestment.toNumber());
@ -1186,6 +1200,13 @@ export class PortfolioCalculator {
totalUnits = totalUnits.plus(order.quantity.mul(getFactor(order.type))); totalUnits = totalUnits.plus(order.quantity.mul(getFactor(order.type)));
if (order.type === 'DIVIDEND') {
dividend = dividend.plus(order.quantity.mul(order.unitPrice));
dividendInBaseCurrency = dividendInBaseCurrency.plus(
dividend.mul(exchangeRateAtOrderDate ?? 1)
);
}
const valueOfInvestment = totalUnits.mul(order.unitPriceInBaseCurrency); const valueOfInvestment = totalUnits.mul(order.unitPriceInBaseCurrency);
const valueOfInvestmentWithCurrencyEffect = totalUnits.mul( const valueOfInvestmentWithCurrencyEffect = totalUnits.mul(
@ -1277,7 +1298,7 @@ export class PortfolioCalculator {
grossPerformanceWithCurrencyEffect; grossPerformanceWithCurrencyEffect;
} }
if (i > indexOfStartOrder) { if (i > indexOfStartOrder && ['BUY', 'SELL'].includes(order.type)) {
// Only consider periods with an investment for the calculation of // Only consider periods with an investment for the calculation of
// the time weighted investment // the time weighted investment
if (valueOfInvestmentBeforeTransaction.gt(0)) { if (valueOfInvestmentBeforeTransaction.gt(0)) {
@ -1471,6 +1492,7 @@ export class PortfolioCalculator {
Time weighted investment with currency effect: ${timeWeightedAverageInvestmentBetweenStartAndEndDateWithCurrencyEffect.toFixed( Time weighted investment with currency effect: ${timeWeightedAverageInvestmentBetweenStartAndEndDateWithCurrencyEffect.toFixed(
2 2
)} )}
Total dividend: ${dividend.toFixed(2)}
Gross performance: ${totalGrossPerformance.toFixed( Gross performance: ${totalGrossPerformance.toFixed(
2 2
)} / ${grossPerformancePercentage.mul(100).toFixed(2)}% )} / ${grossPerformancePercentage.mul(100).toFixed(2)}%
@ -1495,6 +1517,8 @@ export class PortfolioCalculator {
return { return {
currentValues, currentValues,
currentValuesWithCurrencyEffect, currentValuesWithCurrencyEffect,
dividend,
dividendInBaseCurrency,
grossPerformancePercentage, grossPerformancePercentage,
grossPerformancePercentageWithCurrencyEffect, grossPerformancePercentageWithCurrencyEffect,
initialValue, initialValue,

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

@ -1,4 +1,5 @@
import { AccessService } from '@ghostfolio/api/app/access/access.service'; import { AccessService } from '@ghostfolio/api/app/access/access.service';
import { OrderService } from '@ghostfolio/api/app/order/order.service';
import { UserService } from '@ghostfolio/api/app/user/user.service'; import { UserService } from '@ghostfolio/api/app/user/user.service';
import { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard'; import { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard';
import { import {
@ -11,6 +12,7 @@ import { TransformDataSourceInResponseInterceptor } from '@ghostfolio/api/interc
import { ApiService } from '@ghostfolio/api/services/api/api.service'; import { ApiService } from '@ghostfolio/api/services/api/api.service';
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service';
import { ImpersonationService } from '@ghostfolio/api/services/impersonation/impersonation.service';
import { import {
DEFAULT_CURRENCY, DEFAULT_CURRENCY,
HEADER_KEY_IMPERSONATION HEADER_KEY_IMPERSONATION
@ -57,6 +59,8 @@ export class PortfolioController {
private readonly apiService: ApiService, private readonly apiService: ApiService,
private readonly configurationService: ConfigurationService, private readonly configurationService: ConfigurationService,
private readonly exchangeRateDataService: ExchangeRateDataService, private readonly exchangeRateDataService: ExchangeRateDataService,
private readonly impersonationService: ImpersonationService,
private readonly orderService: OrderService,
private readonly portfolioService: PortfolioService, private readonly portfolioService: PortfolioService,
@Inject(REQUEST) private readonly request: RequestWithUser, @Inject(REQUEST) private readonly request: RequestWithUser,
private readonly userService: UserService private readonly userService: UserService
@ -161,7 +165,7 @@ export class PortfolioController {
'currentNetPerformance', 'currentNetPerformance',
'currentNetPerformanceWithCurrencyEffect', 'currentNetPerformanceWithCurrencyEffect',
'currentValue', 'currentValue',
'dividend', 'dividendInBaseCurrency',
'emergencyFund', 'emergencyFund',
'excludedAccountsAndActivities', 'excludedAccountsAndActivities',
'fees', 'fees',
@ -231,11 +235,21 @@ export class PortfolioController {
filterByTags filterByTags
}); });
const impersonationUserId =
await this.impersonationService.validateImpersonationId(impersonationId);
const userCurrency = this.request.user.Settings.settings.baseCurrency;
const { activities } = await this.orderService.getOrders({
filters,
userCurrency,
userId: impersonationUserId || this.request.user.id,
types: ['DIVIDEND']
});
let dividends = await this.portfolioService.getDividends({ let dividends = await this.portfolioService.getDividends({
activities,
dateRange, dateRange,
filters, groupBy
groupBy,
impersonationId
}); });
if ( if (

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

@ -218,27 +218,14 @@ export class PortfolioService {
} }
public async getDividends({ public async getDividends({
dateRange, activities,
filters, dateRange = 'max',
groupBy, groupBy
impersonationId
}: { }: {
dateRange: DateRange; activities: Activity[];
filters?: Filter[]; dateRange?: DateRange;
groupBy?: GroupBy; groupBy?: GroupBy;
impersonationId: string;
}): Promise<InvestmentItem[]> { }): Promise<InvestmentItem[]> {
const userId = await this.getUserId(impersonationId, this.request.user.id);
const user = await this.userService.user({ id: userId });
const userCurrency = this.getUserCurrency(user);
const { activities } = await this.orderService.getOrders({
filters,
userCurrency,
userId,
types: ['DIVIDEND']
});
let dividends = activities.map(({ date, valueInBaseCurrency }) => { let dividends = activities.map(({ date, valueInBaseCurrency }) => {
return { return {
date: format(date, DATE_FORMAT), date: format(date, DATE_FORMAT),
@ -441,6 +428,7 @@ export class PortfolioService {
for (const { for (const {
currency, currency,
dividend,
firstBuyDate, firstBuyDate,
grossPerformance, grossPerformance,
grossPerformanceWithCurrencyEffect, grossPerformanceWithCurrencyEffect,
@ -553,6 +541,7 @@ export class PortfolioService {
countries: symbolProfile.countries, countries: symbolProfile.countries,
dataSource: symbolProfile.dataSource, dataSource: symbolProfile.dataSource,
dateOfFirstActivity: parseDate(firstBuyDate), dateOfFirstActivity: parseDate(firstBuyDate),
dividend: dividend?.toNumber() ?? 0,
grossPerformance: grossPerformance?.toNumber() ?? 0, grossPerformance: grossPerformance?.toNumber() ?? 0,
grossPerformancePercent: grossPerformancePercentage?.toNumber() ?? 0, grossPerformancePercent: grossPerformancePercentage?.toNumber() ?? 0,
grossPerformancePercentWithCurrencyEffect: grossPerformancePercentWithCurrencyEffect:
@ -723,7 +712,7 @@ export class PortfolioService {
.filter((order) => { .filter((order) => {
tags = tags.concat(order.tags); tags = tags.concat(order.tags);
return ['BUY', 'ITEM', 'SELL'].includes(order.type); return ['BUY', 'DIVIDEND', 'ITEM', 'SELL'].includes(order.type);
}) })
.map((order) => ({ .map((order) => ({
currency: order.SymbolProfile.currency, currency: order.SymbolProfile.currency,
@ -764,6 +753,8 @@ export class PortfolioService {
averagePrice, averagePrice,
currency, currency,
dataSource, dataSource,
dividend,
dividendInBaseCurrency,
fee, fee,
firstBuyDate, firstBuyDate,
marketPrice, marketPrice,
@ -780,16 +771,6 @@ export class PortfolioService {
return Account; return Account;
}); });
const dividendInBaseCurrency = getSum(
orders
.filter(({ type }) => {
return type === 'DIVIDEND';
})
.map(({ valueInBaseCurrency }) => {
return new Big(valueInBaseCurrency);
})
);
const historicalData = await this.dataProviderService.getHistorical( const historicalData = await this.dataProviderService.getHistorical(
[{ dataSource, symbol: aSymbol }], [{ dataSource, symbol: aSymbol }],
'day', 'day',
@ -1636,6 +1617,7 @@ export class PortfolioService {
countries: [], countries: [],
dataSource: undefined, dataSource: undefined,
dateOfFirstActivity: undefined, dateOfFirstActivity: undefined,
dividend: 0,
grossPerformance: 0, grossPerformance: 0,
grossPerformancePercent: 0, grossPerformancePercent: 0,
grossPerformancePercentWithCurrencyEffect: 0, grossPerformancePercentWithCurrencyEffect: 0,
@ -1765,11 +1747,16 @@ export class PortfolioService {
} }
} }
const dividend = this.getSumOfActivityType({ const dividendInBaseCurrency = (
activities, await this.getDividends({
userCurrency, activities: activities.filter(({ type }) => {
activityType: 'DIVIDEND' return type === 'DIVIDEND';
}).toNumber(); })
})
).reduce(
(previous, current) => new Big(previous).plus(current.investment),
new Big(0)
);
const emergencyFund = new Big( const emergencyFund = new Big(
Math.max( Math.max(
@ -1904,7 +1891,6 @@ export class PortfolioService {
annualizedPerformancePercent, annualizedPerformancePercent,
annualizedPerformancePercentWithCurrencyEffect, annualizedPerformancePercentWithCurrencyEffect,
cash, cash,
dividend,
excludedAccountsAndActivities, excludedAccountsAndActivities,
fees, fees,
firstOrderDate, firstOrderDate,
@ -1915,6 +1901,7 @@ export class PortfolioService {
totalBuy, totalBuy,
totalSell, totalSell,
committedFunds: committedFunds.toNumber(), committedFunds: committedFunds.toNumber(),
dividendInBaseCurrency: dividendInBaseCurrency.toNumber(),
emergencyFund: { emergencyFund: {
assets: emergencyFundPositionsValueInBaseCurrency, assets: emergencyFundPositionsValueInBaseCurrency,
cash: emergencyFund cash: emergencyFund
@ -1967,7 +1954,7 @@ export class PortfolioService {
private async getTransactionPoints({ private async getTransactionPoints({
filters, filters,
includeDrafts = false, includeDrafts = false,
types = ['BUY', 'ITEM', 'LIABILITY', 'SELL'], types = ['BUY', 'DIVIDEND', 'ITEM', 'LIABILITY', 'SELL'],
userId, userId,
withExcludedAccounts = false withExcludedAccounts = false
}: { }: {
@ -2144,14 +2131,11 @@ export class PortfolioService {
type type
} of ordersByAccount) { } of ordersByAccount) {
let currentValueOfSymbolInBaseCurrency = let currentValueOfSymbolInBaseCurrency =
getFactor(type) *
quantity * quantity *
(portfolioItemsNow[SymbolProfile.symbol]?.marketPriceInBaseCurrency ?? (portfolioItemsNow[SymbolProfile.symbol]?.marketPriceInBaseCurrency ??
0); 0);
if (['LIABILITY', 'SELL'].includes(type)) {
currentValueOfSymbolInBaseCurrency *= getFactor(type);
}
if (accounts[Account?.id || UNKNOWN_KEY]?.valueInBaseCurrency) { if (accounts[Account?.id || UNKNOWN_KEY]?.valueInBaseCurrency) {
accounts[Account?.id || UNKNOWN_KEY].valueInBaseCurrency += accounts[Account?.id || UNKNOWN_KEY].valueInBaseCurrency +=
currentValueOfSymbolInBaseCurrency; currentValueOfSymbolInBaseCurrency;

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

@ -328,7 +328,7 @@
[isCurrency]="true" [isCurrency]="true"
[locale]="locale" [locale]="locale"
[unit]="baseCurrency" [unit]="baseCurrency"
[value]="isLoading ? undefined : summary?.dividend" [value]="isLoading ? undefined : summary?.dividendInBaseCurrency"
/> />
</div> </div>
</div> </div>

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

@ -14,6 +14,7 @@ export interface PortfolioPosition {
currency: string; currency: string;
dataSource: DataSource; dataSource: DataSource;
dateOfFirstActivity: Date; dateOfFirstActivity: Date;
dividend: number;
exchange?: string; exchange?: string;
grossPerformance: number; grossPerformance: number;
grossPerformancePercent: number; grossPerformancePercent: number;

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

@ -5,7 +5,7 @@ export interface PortfolioSummary extends PortfolioPerformance {
annualizedPerformancePercentWithCurrencyEffect: number; annualizedPerformancePercentWithCurrencyEffect: number;
cash: number; cash: number;
committedFunds: number; committedFunds: number;
dividend: number; dividendInBaseCurrency: number;
emergencyFund: { emergencyFund: {
assets: number; assets: number;
cash: number; cash: number;

2
libs/common/src/lib/interfaces/symbol-metrics.interface.ts

@ -7,6 +7,8 @@ export interface SymbolMetrics {
currentValuesWithCurrencyEffect: { currentValuesWithCurrencyEffect: {
[date: string]: Big; [date: string]: Big;
}; };
dividend: Big;
dividendInBaseCurrency: Big;
grossPerformance: Big; grossPerformance: Big;
grossPerformancePercentage: Big; grossPerformancePercentage: Big;
grossPerformancePercentageWithCurrencyEffect: Big; grossPerformancePercentageWithCurrencyEffect: Big;

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

@ -5,6 +5,8 @@ export interface TimelinePosition {
averagePrice: Big; averagePrice: Big;
currency: string; currency: string;
dataSource: DataSource; dataSource: DataSource;
dividend: Big;
dividendInBaseCurrency: Big;
fee: Big; fee: Big;
firstBuyDate: string; firstBuyDate: string;
grossPerformance: Big; grossPerformance: Big;

Loading…
Cancel
Save