Browse Source

Rename SymbolProfile to assetProfile

pull/7310/head
Thomas Kaul 2 days ago
parent
commit
18ac03e22c
  1. 18
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  2. 36
      apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts
  3. 8
      apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts

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

@ -141,9 +141,9 @@ export abstract class PortfolioCalculator {
} }
return { return {
SymbolProfile,
tags, tags,
type, type,
assetProfile: SymbolProfile,
date: format(date, DATE_FORMAT), date: format(date, DATE_FORMAT),
fee: new Big(feeInAssetProfileCurrency), fee: new Big(feeInAssetProfileCurrency),
feeInBaseCurrency: new Big(feeInBaseCurrency), feeInBaseCurrency: new Big(feeInBaseCurrency),
@ -934,23 +934,23 @@ export abstract class PortfolioCalculator {
let lastTransactionPoint: TransactionPoint = null; let lastTransactionPoint: TransactionPoint = null;
for (const { for (const {
assetProfile,
date, date,
fee, fee,
feeInBaseCurrency, feeInBaseCurrency,
quantity, quantity,
SymbolProfile,
tags, tags,
type, type,
unitPrice unitPrice
} of this.activities) { } of this.activities) {
let currentTransactionPointItem: TransactionPointSymbol; let currentTransactionPointItem: TransactionPointSymbol;
const assetSubClass = SymbolProfile.assetSubClass; const assetSubClass = assetProfile.assetSubClass;
const currency = SymbolProfile.currency; const currency = assetProfile.currency;
const dataSource = SymbolProfile.dataSource; const dataSource = assetProfile.dataSource;
const factor = getFactor(type); const factor = getFactor(type);
const skipErrors = !!SymbolProfile.userId; // Skip errors for custom asset profiles const skipErrors = !!assetProfile.userId; // Skip errors for custom asset profiles
const symbol = SymbolProfile.symbol; const symbol = assetProfile.symbol;
const oldAccumulatedSymbol = symbols[symbol]; const oldAccumulatedSymbol = symbols[symbol];
@ -1034,12 +1034,12 @@ export abstract class PortfolioCalculator {
'id' 'id'
); );
symbols[SymbolProfile.symbol] = currentTransactionPointItem; symbols[assetProfile.symbol] = currentTransactionPointItem;
const items = lastTransactionPoint?.items ?? []; const items = lastTransactionPoint?.items ?? [];
const newItems = items.filter(({ symbol }) => { const newItems = items.filter(({ symbol }) => {
return symbol !== SymbolProfile.symbol; return symbol !== assetProfile.symbol;
}); });
newItems.push(currentTransactionPointItem); newItems.push(currentTransactionPointItem);

36
apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts

@ -192,12 +192,12 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
// Clone orders to keep the original values in this.orders // Clone orders to keep the original values in this.orders
let orders: PortfolioOrderItem[] = cloneDeep( let orders: PortfolioOrderItem[] = cloneDeep(
this.activities.filter(({ SymbolProfile }) => { this.activities.filter(({ assetProfile }) => {
return SymbolProfile.symbol === symbol; return assetProfile.symbol === symbol;
}) })
); );
const isCash = orders[0]?.SymbolProfile?.assetSubClass === 'CASH'; const isCash = orders[0]?.assetProfile?.assetSubClass === 'CASH';
if (orders.length <= 0) { if (orders.length <= 0) {
return { return {
@ -301,30 +301,30 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
// Add a synthetic order at the start and the end date // Add a synthetic order at the start and the end date
orders.push({ orders.push({
assetProfile: {
dataSource,
symbol,
assetSubClass: isCash ? 'CASH' : undefined
},
date: startDateString, date: startDateString,
fee: new Big(0), fee: new Big(0),
feeInBaseCurrency: new Big(0), feeInBaseCurrency: new Big(0),
itemType: 'start', itemType: 'start',
quantity: new Big(0), quantity: new Big(0),
SymbolProfile: {
dataSource,
symbol,
assetSubClass: isCash ? 'CASH' : undefined
},
type: 'BUY', type: 'BUY',
unitPrice: unitPriceAtStartDate unitPrice: unitPriceAtStartDate
}); });
orders.push({ orders.push({
date: endDateString, assetProfile: {
fee: new Big(0),
feeInBaseCurrency: new Big(0),
itemType: 'end',
SymbolProfile: {
dataSource, dataSource,
symbol, symbol,
assetSubClass: isCash ? 'CASH' : undefined assetSubClass: isCash ? 'CASH' : undefined
}, },
date: endDateString,
fee: new Big(0),
feeInBaseCurrency: new Big(0),
itemType: 'end',
quantity: new Big(0), quantity: new Big(0),
type: 'BUY', type: 'BUY',
unitPrice: unitPriceAtEndDate unitPrice: unitPriceAtEndDate
@ -357,15 +357,15 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
} }
} else { } else {
orders.push({ orders.push({
date: dateString, assetProfile: {
fee: new Big(0),
feeInBaseCurrency: new Big(0),
quantity: new Big(0),
SymbolProfile: {
dataSource, dataSource,
symbol, symbol,
assetSubClass: isCash ? 'CASH' : undefined assetSubClass: isCash ? 'CASH' : undefined
}, },
date: dateString,
fee: new Big(0),
feeInBaseCurrency: new Big(0),
quantity: new Big(0),
type: 'BUY', type: 'BUY',
unitPrice: marketSymbolMap[dateString]?.[symbol] ?? lastUnitPrice, unitPrice: marketSymbolMap[dateString]?.[symbol] ?? lastUnitPrice,
unitPriceFromMarketData: unitPriceFromMarketData:

8
apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts

@ -1,13 +1,13 @@
import { Activity } from '@ghostfolio/common/interfaces'; import { Activity } from '@ghostfolio/common/interfaces';
export interface PortfolioOrder extends Pick<Activity, 'tags' | 'type'> { export interface PortfolioOrder extends Pick<Activity, 'tags' | 'type'> {
assetProfile: Pick<
Activity['SymbolProfile'],
'assetSubClass' | 'currency' | 'dataSource' | 'name' | 'symbol' | 'userId'
>;
date: string; date: string;
fee: Big; fee: Big;
feeInBaseCurrency: Big; feeInBaseCurrency: Big;
quantity: Big; quantity: Big;
SymbolProfile: Pick<
Activity['SymbolProfile'],
'assetSubClass' | 'currency' | 'dataSource' | 'name' | 'symbol' | 'userId'
>;
unitPrice: Big; unitPrice: Big;
} }

Loading…
Cancel
Save