when a money bucket runs out, move spending to another bucket
This commit is contained in:
@@ -80,17 +80,53 @@ function runProjection(useInflation) {
|
|||||||
roth = roth * growthFactor;
|
roth = roth * growthFactor;
|
||||||
realEstate = realEstate * growthFactor;
|
realEstate = realEstate * growthFactor;
|
||||||
|
|
||||||
pretaxSpend = Math.min(pretaxSpend, pretax * (1 - taxRate));
|
var cascadeSpend = 0;
|
||||||
pretax -= pretaxSpend / (1 - taxRate);
|
|
||||||
pretax = Math.max(0, pretax);
|
|
||||||
|
|
||||||
aftertaxSpend = Math.min(aftertaxSpend, aftertax);
|
var grossPreTaxSpend = pretaxSpend / (1 - taxRate);
|
||||||
|
if (grossPreTaxSpend > pretax) {
|
||||||
|
cascadeSpend += pretaxSpend - pretax * (1 - taxRate);
|
||||||
|
pretax = 0;
|
||||||
|
} else {
|
||||||
|
pretax -= grossPreTaxSpend;
|
||||||
|
pretax = Math.max(0, pretax);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aftertaxSpend > aftertax) {
|
||||||
|
cascadeSpend += aftertaxSpend - aftertax;
|
||||||
|
aftertax = 0;
|
||||||
|
} else {
|
||||||
aftertax -= aftertaxSpend;
|
aftertax -= aftertaxSpend;
|
||||||
aftertax = Math.max(0, aftertax);
|
aftertax = Math.max(0, aftertax);
|
||||||
|
}
|
||||||
|
|
||||||
rothSpend = Math.min(rothSpend, roth);
|
if (rothSpend > roth) {
|
||||||
|
cascadeSpend += rothSpend - roth;
|
||||||
|
roth = 0;
|
||||||
|
} else {
|
||||||
roth -= rothSpend;
|
roth -= rothSpend;
|
||||||
roth = Math.max(0, roth);
|
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;
|
pretaxSpend *= inflationFactor;
|
||||||
aftertaxSpend *= inflationFactor;
|
aftertaxSpend *= inflationFactor;
|
||||||
|
|||||||
Reference in New Issue
Block a user