From 3b901446f19adc3484894a1f68a4b396a0136f9a Mon Sep 17 00:00:00 2001 From: Prashanth Mohan Date: Sat, 30 Sep 2023 21:01:05 +1000 Subject: [PATCH] Add additional time horizon options for portfolio performance. This mirrors the time horizons used in popular finance tracking websites online. --- README.md | 2 +- .../src/app/portfolio/portfolio.service.ts | 19 +++++++++++++++++++ .../src/app/user/update-user-setting.dto.ts | 2 +- .../app/components/toggle/toggle.component.ts | 3 +++ .../src/app/pages/features/features-page.html | 3 ++- libs/common/src/lib/types/date-range.type.ts | 2 +- 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 87e6c7d1b..ec25b0d74 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Ghostfolio is for you if you are... - ✅ Create, update and delete transactions - ✅ Multi account management -- ✅ Portfolio performance for `Today`, `YTD`, `1Y`, `5Y`, `Max` +- ✅ Portfolio performance for `Today`, `1D`, `5D`, `1M`, `6M`, `YTD`, `1Y`, `5Y`, `Max` - ✅ Various charts - ✅ Static analysis to identify potential risks in your portfolio - ✅ Import and export transactions diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index e9d0b2792..f25db78ed 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -71,6 +71,7 @@ import { set, setDayOfYear, subDays, + subMonths, subYears } from 'date-fns'; import { isEmpty, sortBy, uniq, uniqBy } from 'lodash'; @@ -1493,6 +1494,24 @@ export class PortfolioService { subDays(new Date().setHours(0, 0, 0, 0), 1) ]); break; + case '5d': + portfolioStart = max([ + portfolioStart, + subDays(new Date().setHours(0, 0, 0, 0), 5) + ]); + break; + case '1m': + portfolioStart = max([ + portfolioStart, + subMonths(new Date().setHours(0, 0, 0, 0), 1) + ]); + break; + case '6m': + portfolioStart = max([ + portfolioStart, + subMonths(new Date().setHours(0, 0, 0, 0), 6) + ]); + break; case 'ytd': portfolioStart = max([ portfolioStart, diff --git a/apps/api/src/app/user/update-user-setting.dto.ts b/apps/api/src/app/user/update-user-setting.dto.ts index e510880ed..8db920dc1 100644 --- a/apps/api/src/app/user/update-user-setting.dto.ts +++ b/apps/api/src/app/user/update-user-setting.dto.ts @@ -29,7 +29,7 @@ export class UpdateUserSettingDto { @IsOptional() colorScheme?: ColorScheme; - @IsIn(['1d', '1y', '5y', 'max', 'ytd']) + @IsIn(['1d', '5d', '1m', '6m', '1y', '5y', 'max', 'ytd']) @IsOptional() dateRange?: DateRange; diff --git a/apps/client/src/app/components/toggle/toggle.component.ts b/apps/client/src/app/components/toggle/toggle.component.ts index a330e8af8..55fe4f1af 100644 --- a/apps/client/src/app/components/toggle/toggle.component.ts +++ b/apps/client/src/app/components/toggle/toggle.component.ts @@ -19,6 +19,9 @@ import { ToggleOption } from '@ghostfolio/common/types'; export class ToggleComponent implements OnChanges, OnInit { public static DEFAULT_DATE_RANGE_OPTIONS: ToggleOption[] = [ { label: $localize`Today`, value: '1d' }, + { label: $localize`5D`, value: '5d' }, + { label: $localize`1M`, value: '1m' }, + { label: $localize`6M`, value: '6m' }, { label: $localize`YTD`, value: 'ytd' }, { label: $localize`1Y`, value: '1y' }, { label: $localize`5Y`, value: '5y' }, diff --git a/apps/client/src/app/pages/features/features-page.html b/apps/client/src/app/pages/features/features-page.html index c63fa9a49..4120a774c 100644 --- a/apps/client/src/app/pages/features/features-page.html +++ b/apps/client/src/app/pages/features/features-page.html @@ -146,7 +146,8 @@

Check the rate of return of your portfolio for - Today, YTD, 1Y, + Today, 5D, 1M, + 6M, YTD, 1Y, 5Y, and Max.

diff --git a/libs/common/src/lib/types/date-range.type.ts b/libs/common/src/lib/types/date-range.type.ts index afee7b100..f4b4b4ec3 100644 --- a/libs/common/src/lib/types/date-range.type.ts +++ b/libs/common/src/lib/types/date-range.type.ts @@ -1 +1 @@ -export type DateRange = '1d' | '1y' | '5y' | 'max' | 'ytd'; +export type DateRange = '1d' | '5d' | '1m' | '6m' | '1y' | '5y' | 'max' | 'ytd';