Browse Source

Bugfix/time in market of portfolio summary to be empty if no activity (#7428)

* Fix time in market if no activity

* Update changelog
pull/7420/head
Thomas Kaul 2 days ago
committed by GitHub
parent
commit
f11c30160b
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      CHANGELOG.md
  2. 18
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  3. 4
      apps/api/src/app/portfolio/portfolio.service.ts
  4. 2
      apps/client/src/app/components/portfolio-summary/portfolio-summary.component.ts
  5. 2
      libs/common/src/lib/interfaces/portfolio-summary.interface.ts

6
CHANGELOG.md

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Fixed
- Fixed the time in market of the portfolio summary to be empty if there is no activity
## 3.35.0 - 2026-07-27 ## 3.35.0 - 2026-07-27
### Added ### Added

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

@ -816,15 +816,18 @@ export abstract class PortfolioCalculator {
let firstAccountBalanceDate: Date; let firstAccountBalanceDate: Date;
let firstActivityDate: Date; let firstActivityDate: Date;
if (this.accountBalanceItems?.length > 0) {
try { try {
const firstAccountBalanceDateString = this.accountBalanceItems[0]?.date; const firstAccountBalanceDateString = this.accountBalanceItems[0].date;
firstAccountBalanceDate = firstAccountBalanceDateString firstAccountBalanceDate = firstAccountBalanceDateString
? parseDate(firstAccountBalanceDateString) ? parseDate(firstAccountBalanceDateString)
: new Date(); : new Date();
} catch (error) { } catch (error) {
firstAccountBalanceDate = new Date(); firstAccountBalanceDate = new Date();
} }
}
if (this.transactionPoints?.length > 0) {
try { try {
const firstActivityDateString = this.transactionPoints[0].date; const firstActivityDateString = this.transactionPoints[0].date;
firstActivityDate = firstActivityDateString firstActivityDate = firstActivityDateString
@ -833,8 +836,19 @@ export abstract class PortfolioCalculator {
} catch (error) { } catch (error) {
firstActivityDate = new Date(); firstActivityDate = new Date();
} }
}
const dates = [firstAccountBalanceDate, firstActivityDate].filter(
(date) => {
return !!date;
}
);
if (dates.length === 0) {
return undefined;
}
return min([firstAccountBalanceDate, firstActivityDate]); return min(dates);
} }
protected abstract getSymbolMetrics({ protected abstract getSymbolMetrics({

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

@ -1986,7 +1986,9 @@ export class PortfolioService {
.minus(liabilities) .minus(liabilities)
.toNumber(); .toNumber();
const daysInMarket = differenceInDays(new Date(), dateOfFirstActivity); const daysInMarket = dateOfFirstActivity
? differenceInDays(new Date(), dateOfFirstActivity)
: 0;
const annualizedPerformancePercent = getAnnualizedPerformancePercent({ const annualizedPerformancePercent = getAnnualizedPerformancePercent({
daysInMarket, daysInMarket,

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

@ -116,7 +116,7 @@ export class GfPortfolioSummaryComponent implements OnChanges {
} }
); );
} else { } else {
this.timeInMarket = '-'; this.timeInMarket = '';
} }
} else { } else {
this.timeInMarket = undefined; this.timeInMarket = undefined;

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

@ -6,7 +6,7 @@ export interface PortfolioSummary extends PortfolioPerformance {
annualizedPerformancePercent: number; annualizedPerformancePercent: number;
annualizedPerformancePercentWithCurrencyEffect: number; annualizedPerformancePercentWithCurrencyEffect: number;
cash: number; cash: number;
dateOfFirstActivity: Date; dateOfFirstActivity?: Date;
dividendInBaseCurrency: number; dividendInBaseCurrency: number;
emergencyFund: { emergencyFund: {
assets: number; assets: number;

Loading…
Cancel
Save