Fix: Cash-Startwert zeigt Bestand NACH den Investitionen (kein Doppelzaehlen)
Deploy App / deploy (push) Successful in 56s

Investitionen einer Phase (Zusatz-/Neuinvestitionen aus Cash) werden am Phasenanfang
abgezogen; der Cash-Startwert bildet das nun ab. Behebt zugleich eine Doppelzaehlung im
Startvermoegen (der investierte Betrag stand zuvor sowohl im Cash-Start als auch im
Vermoegen). Endwerte unveraendert.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-15 23:17:41 +02:00
parent 3acac56640
commit f768e01d61
2 changed files with 8 additions and 2 deletions
+5 -1
View File
@@ -158,10 +158,14 @@ describe("V5 Golden Tests", () => {
el("OTHER_ASSET", "HOUSEHOLD", { p1: { startValue: 0, expectedReturn: 0, annualContribution: 0 }, p2: { additionalInvestment: 10000, expectedReturn: 0 } }), 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.capitalInflow).toBe(10000); // Verkaufserloes aus dem Uebergang
expect(p2.capitalInvest).toBe(10000); // Zusatzinvestition expect(p2.capitalInvest).toBe(10000); // Zusatzinvestition
expect(p2.cashStart).toBe(0); // Startwert bereits nach Abzug der Investition
expect(p2.cashEnd).toBe(0); 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", () => { it("Cash-Anfangswert fliesst in die erste Phase ein", () => {
+3 -1
View File
@@ -363,8 +363,10 @@ export function computePlan(plan: PlanInput): PlanComputed {
} }
// --- Jahr-fuer-Jahr: indexierte Flows, Cash-Ausgleich, Verzinsung, Ruin --- // --- 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); let cash = cashCarryIn - (isFirstPhase ? 0 : investmentsFromCash);
const cashStart = cash;
let cashNegative = cash < 0; let cashNegative = cash < 0;
let incomeStart = 0; let incomeStart = 0;
let incomeEnd = 0; let incomeEnd = 0;