diff --git a/src/lib/calculations.test.ts b/src/lib/calculations.test.ts index a5986d6..99b8778 100644 --- a/src/lib/calculations.test.ts +++ b/src/lib/calculations.test.ts @@ -158,10 +158,14 @@ describe("V5 Golden Tests", () => { el("OTHER_ASSET", "HOUSEHOLD", { p1: { startValue: 0, expectedReturn: 0, annualContribution: 0 }, p2: { additionalInvestment: 10000, expectedReturn: 0 } }), ], }); - const p2 = computePlan(p).phases[1]; + const r = computePlan(p); + const p2 = r.phases[1]; expect(p2.capitalInflow).toBe(10000); // Verkaufserloes aus dem Uebergang expect(p2.capitalInvest).toBe(10000); // Zusatzinvestition + expect(p2.cashStart).toBe(0); // Startwert bereits nach Abzug der Investition expect(p2.cashEnd).toBe(0); + // Startvermoegen Phase 2: Cash(0) + Vermoegen B(10'000) = 10'000 (kein Doppelzaehlen). + expect(p2.startWealthNominal).toBe(10000); }); it("Cash-Anfangswert fliesst in die erste Phase ein", () => { diff --git a/src/lib/calculations.ts b/src/lib/calculations.ts index 4514934..5ccdd0a 100644 --- a/src/lib/calculations.ts +++ b/src/lib/calculations.ts @@ -363,8 +363,10 @@ export function computePlan(plan: PlanInput): PlanComputed { } // --- Jahr-fuer-Jahr: indexierte Flows, Cash-Ausgleich, Verzinsung, Ruin --- - const cashStart = cashCarryIn; + // Investitionen dieser Phase werden am Phasenanfang abgezogen -> der Cash-Startwert + // zeigt den Bestand NACH den Investitionen (kein Doppelzaehlen mit dem Vermoegen). let cash = cashCarryIn - (isFirstPhase ? 0 : investmentsFromCash); + const cashStart = cash; let cashNegative = cash < 0; let incomeStart = 0; let incomeEnd = 0;