Browse Source

Portfolio calculation updated

csehatt741 3 weeks ago
committed by Attila Cseh
parent
commit
28a2201679
  1. 7
      apps/api/src/app/import/import.service.ts
  2. 1
      apps/api/src/app/order/interfaces/activities.interface.ts
  3. 7
      apps/api/src/app/order/order.service.ts
  4. 8
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

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

@ -128,6 +128,13 @@ export class ImportService {
symbolProfileId: assetProfile.id, symbolProfileId: assetProfile.id,
type: 'DIVIDEND', type: 'DIVIDEND',
unitPrice: marketPrice, unitPrice: marketPrice,
unitPriceInBaseCurrency:
await this.exchangeRateDataService.toCurrencyAtDate(
marketPrice,
assetProfile.currency,
userCurrency,
date
),
updatedAt: undefined, updatedAt: undefined,
userId: Account?.userId, userId: Account?.userId,
valueInBaseCurrency: valueInBaseCurrency:

1
apps/api/src/app/order/interfaces/activities.interface.ts

@ -14,6 +14,7 @@ export interface Activity extends Order {
feeInBaseCurrency: number; feeInBaseCurrency: number;
SymbolProfile?: EnhancedSymbolProfile; SymbolProfile?: EnhancedSymbolProfile;
tags?: Tag[]; tags?: Tag[];
unitPriceInBaseCurrency: number;
updateAccountBalance?: boolean; updateAccountBalance?: boolean;
value: number; value: number;
valueInBaseCurrency: number; valueInBaseCurrency: number;

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

@ -542,6 +542,13 @@ export class OrderService {
order.date order.date
), ),
SymbolProfile: assetProfile, SymbolProfile: assetProfile,
unitPriceInBaseCurrency:
await this.exchangeRateDataService.toCurrencyAtDate(
order.unitPrice,
order.currency ?? order.SymbolProfile.currency,
userCurrency,
order.date
),
valueInBaseCurrency: valueInBaseCurrency:
await this.exchangeRateDataService.toCurrencyAtDate( await this.exchangeRateDataService.toCurrencyAtDate(
value, value,

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

@ -112,12 +112,12 @@ export abstract class PortfolioCalculator {
.map( .map(
({ ({
date, date,
fee, feeInBaseCurrency,
quantity, quantity,
SymbolProfile, SymbolProfile,
tags = [], tags = [],
type, type,
unitPrice unitPriceInBaseCurrency
}) => { }) => {
if (isBefore(date, dateOfFirstActivity)) { if (isBefore(date, dateOfFirstActivity)) {
dateOfFirstActivity = date; dateOfFirstActivity = date;
@ -134,9 +134,9 @@ export abstract class PortfolioCalculator {
tags, tags,
type, type,
date: format(date, DATE_FORMAT), date: format(date, DATE_FORMAT),
fee: new Big(fee), fee: new Big(feeInBaseCurrency),
quantity: new Big(quantity), quantity: new Big(quantity),
unitPrice: new Big(unitPrice) unitPrice: new Big(unitPriceInBaseCurrency)
}; };
} }
) )

Loading…
Cancel
Save