when a money bucket runs out, move spending to another bucket

This commit is contained in:
2026-05-15 11:36:12 -04:00
parent 1cdee5d05b
commit 72402abffd
+45 -9
View File
@@ -80,17 +80,53 @@ function runProjection(useInflation) {
roth = roth * growthFactor;
realEstate = realEstate * growthFactor;
pretaxSpend = Math.min(pretaxSpend, pretax * (1 - taxRate));
pretax -= pretaxSpend / (1 - taxRate);
pretax = Math.max(0, pretax);
var cascadeSpend = 0;
aftertaxSpend = Math.min(aftertaxSpend, aftertax);
aftertax -= aftertaxSpend;
aftertax = Math.max(0, aftertax);
var grossPreTaxSpend = pretaxSpend / (1 - taxRate);
if (grossPreTaxSpend > pretax) {
cascadeSpend += pretaxSpend - pretax * (1 - taxRate);
pretax = 0;
} else {
pretax -= grossPreTaxSpend;
pretax = Math.max(0, pretax);
}
rothSpend = Math.min(rothSpend, roth);
roth -= rothSpend;
roth = Math.max(0, roth);
if (aftertaxSpend > aftertax) {
cascadeSpend += aftertaxSpend - aftertax;
aftertax = 0;
} else {
aftertax -= aftertaxSpend;
aftertax = Math.max(0, aftertax);
}
if (rothSpend > roth) {
cascadeSpend += rothSpend - roth;
roth = 0;
} else {
roth -= rothSpend;
roth = Math.max(0, roth);
}
if (cascadeSpend > 0) {
var grossCascade = cascadeSpend / (1 - taxRate);
if (aftertax > 0) {
var aftertaxDraw = Math.min(cascadeSpend, aftertax);
aftertax -= aftertaxDraw;
aftertax = Math.max(0, aftertax);
cascadeSpend -= aftertaxDraw;
}
if (cascadeSpend > 0 && pretax > 0) {
var pretaxDraw = Math.min(cascadeSpend / (1 - taxRate), pretax);
pretax -= pretaxDraw;
pretax = Math.max(0, pretax);
cascadeSpend -= pretaxDraw * (1 - taxRate);
}
if (cascadeSpend > 0 && roth > 0) {
var rothDraw = Math.min(cascadeSpend, roth);
roth -= rothDraw;
roth = Math.max(0, roth);
}
}
pretaxSpend *= inflationFactor;
aftertaxSpend *= inflationFactor;