From c0b30298a246177b3a9b483167da18a64387df3c Mon Sep 17 00:00:00 2001 From: PJ Date: Wed, 18 Nov 2026 21:11:02 +0100 Subject: [PATCH] refactor(targets): share preset definitions with common model --- .../pages/portfolio/targets/target-presets.ts | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/apps/client/src/app/pages/portfolio/targets/target-presets.ts b/apps/client/src/app/pages/portfolio/targets/target-presets.ts index 39a73e4e04..7488a64fe9 100644 --- a/apps/client/src/app/pages/portfolio/targets/target-presets.ts +++ b/apps/client/src/app/pages/portfolio/targets/target-presets.ts @@ -1,29 +1,22 @@ import { PortfolioTargetProfile } from '@ghostfolio/common/interfaces'; -import { AssetClass } from '@ghostfolio/prisma/enums'; +import { PORTFOLIO_TARGET_PRESETS } from '@ghostfolio/common/portfolio-targets/portfolio-targets-presets'; -export const TARGET_PRESETS = [ - { id: 'cautious', label: $localize`Cautious (20/80)`, equity: 20, bonds: 80, commodities: 0 }, - { id: 'conservative', label: $localize`Conservative (40/60)`, equity: 40, bonds: 60, commodities: 0 }, - { id: 'moderate', label: $localize`Moderate (60/40)`, equity: 60, bonds: 40, commodities: 0 }, - { id: 'aggressive', label: $localize`Aggressive (80/20)`, equity: 80, bonds: 20, commodities: 0 }, - { id: 'golden-butterfly', label: $localize`Golden Butterfly (simplified)`, equity: 40, bonds: 40, commodities: 20 } -] as const; +/** The user-visible presets share the same source as the default model. */ +export const TARGET_PRESETS = PORTFOLIO_TARGET_PRESETS.map(({ id, name }) => ({ + id, + label: name +})); export function createTargetFromPreset(presetId: string): PortfolioTargetProfile { - const preset = TARGET_PRESETS.find(({ id }) => id === presetId) ?? TARGET_PRESETS[2]; + const preset = + PORTFOLIO_TARGET_PRESETS.find(({ id }) => id === presetId) ?? + PORTFOLIO_TARGET_PRESETS[2]; return { id: 'global', - name: preset.label, + name: preset.name, presetId: preset.id, tolerance: 0.05, - allocations: { - [AssetClass.ALTERNATIVE_INVESTMENT]: 0, - [AssetClass.COMMODITY]: preset.commodities / 100, - [AssetClass.EQUITY]: preset.equity / 100, - [AssetClass.FIXED_INCOME]: preset.bonds / 100, - [AssetClass.LIQUIDITY]: 0, - [AssetClass.REAL_ESTATE]: 0 - } + allocations: { ...preset.allocations } }; }