Browse Source

Include cash in portfolio performance

pull/7148/head
Thomas Kaul 6 days ago
parent
commit
e92c6ca298
  1. 9
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  2. 1
      apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-cash.spec.ts
  3. 1
      apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts
  4. 2
      apps/api/src/app/portfolio/portfolio.service.ts
  5. 4
      libs/common/src/lib/models/portfolio-snapshot.ts

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

@ -193,6 +193,7 @@ export abstract class PortfolioCalculator {
hasErrors: false, hasErrors: false,
historicalData: [], historicalData: [],
positions: [], positions: [],
totalCashInBaseCurrency: new Big(0),
totalFeesWithCurrencyEffect: new Big(0), totalFeesWithCurrencyEffect: new Big(0),
totalInterestWithCurrencyEffect: new Big(0), totalInterestWithCurrencyEffect: new Big(0),
totalInvestment: new Big(0), totalInvestment: new Big(0),
@ -205,6 +206,7 @@ export abstract class PortfolioCalculator {
const dataGatheringItems: DataGatheringItem[] = []; const dataGatheringItems: DataGatheringItem[] = [];
let firstIndex = transactionPoints.length; let firstIndex = transactionPoints.length;
let firstTransactionPoint: TransactionPoint = null; let firstTransactionPoint: TransactionPoint = null;
let totalCashInBaseCurrency = new Big(0);
let totalInterestWithCurrencyEffect = new Big(0); let totalInterestWithCurrencyEffect = new Big(0);
let totalLiabilitiesWithCurrencyEffect = new Big(0); let totalLiabilitiesWithCurrencyEffect = new Big(0);
@ -447,6 +449,12 @@ export abstract class PortfolioCalculator {
) )
}); });
if (item.assetSubClass === 'CASH') {
totalCashInBaseCurrency = totalCashInBaseCurrency.plus(
marketPriceInBaseCurrency.mul(item.quantity)
);
}
totalInterestWithCurrencyEffect = totalInterestWithCurrencyEffect.plus( totalInterestWithCurrencyEffect = totalInterestWithCurrencyEffect.plus(
totalInterestInBaseCurrency totalInterestInBaseCurrency
); );
@ -661,6 +669,7 @@ export abstract class PortfolioCalculator {
...overall, ...overall,
errors, errors,
historicalData, historicalData,
totalCashInBaseCurrency,
totalInterestWithCurrencyEffect, totalInterestWithCurrencyEffect,
totalLiabilitiesWithCurrencyEffect, totalLiabilitiesWithCurrencyEffect,
hasErrors: hasAnySymbolMetricsErrors || overall.hasErrors, hasErrors: hasAnySymbolMetricsErrors || overall.hasErrors,

1
apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-cash.spec.ts

@ -286,6 +286,7 @@ describe('PortfolioCalculator', () => {
expect(portfolioSnapshot).toMatchObject({ expect(portfolioSnapshot).toMatchObject({
currentValueInBaseCurrency: new Big(1820), currentValueInBaseCurrency: new Big(1820),
hasErrors: false, hasErrors: false,
totalCashInBaseCurrency: new Big(1820),
totalFeesWithCurrencyEffect: new Big(0), totalFeesWithCurrencyEffect: new Big(0),
totalInterestWithCurrencyEffect: new Big(0), totalInterestWithCurrencyEffect: new Big(0),
totalInvestment: new Big(1820), totalInvestment: new Big(1820),

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

@ -113,6 +113,7 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
createdAt: new Date(), createdAt: new Date(),
errors: [], errors: [],
historicalData: [], historicalData: [],
totalCashInBaseCurrency: new Big(0),
totalLiabilitiesWithCurrencyEffect: new Big(0) totalLiabilitiesWithCurrencyEffect: new Big(0)
}; };
} }

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

@ -1887,6 +1887,7 @@ export class PortfolioService {
const { const {
currentValueInBaseCurrency, currentValueInBaseCurrency,
totalCashInBaseCurrency,
totalInvestment, totalInvestment,
totalInvestmentWithCurrencyEffect totalInvestmentWithCurrencyEffect
} = await portfolioCalculator.getSnapshot(); } = await portfolioCalculator.getSnapshot();
@ -2015,6 +2016,7 @@ export class PortfolioService {
fireWealth: { fireWealth: {
today: { today: {
valueInBaseCurrency: new Big(currentValueInBaseCurrency) valueInBaseCurrency: new Big(currentValueInBaseCurrency)
.minus(totalCashInBaseCurrency ?? 0)
.minus(emergencyFundHoldingsValueInBaseCurrency) .minus(emergencyFundHoldingsValueInBaseCurrency)
.toNumber() .toNumber()
} }

4
libs/common/src/lib/models/portfolio-snapshot.ts

@ -26,6 +26,10 @@ export class PortfolioSnapshot {
@Type(() => TimelinePosition) @Type(() => TimelinePosition)
positions: TimelinePosition[]; positions: TimelinePosition[];
@Transform(transformToBig, { toClassOnly: true })
@Type(() => Big)
totalCashInBaseCurrency: Big;
@Transform(transformToBig, { toClassOnly: true }) @Transform(transformToBig, { toClassOnly: true })
@Type(() => Big) @Type(() => Big)
totalFeesWithCurrencyEffect: Big; totalFeesWithCurrencyEffect: Big;

Loading…
Cancel
Save