Skip to content

Commit 3a428d4

Browse files
committed
One more FI ratio fix
1 parent 727a5bf commit 3a428d4

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/retirement.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,21 @@ void budget::retirement_status(budget::writer& w) {
167167
}
168168
}
169169

170-
auto currency = get_default_currency();
171-
auto wrate = to_number<double>(internal_config_value("withdrawal_rate"));
172-
auto roi = to_number<double>(internal_config_value("expected_roi"));
173-
auto years = double(100.0 / wrate);
174-
auto expenses = running_expenses(w.cache);
175-
auto savings_rate = running_savings_rate(w.cache);
176-
auto nw = get_fi_net_worth(w.cache);
177-
auto missing = years * expenses - nw;
178-
auto income = running_income(w.cache);
170+
const auto currency = get_default_currency();
171+
const auto wrate = to_number<double>(internal_config_value("withdrawal_rate"));
172+
const auto roi = to_number<double>(internal_config_value("expected_roi"));
173+
const auto years = double(100.0 / wrate);
174+
const auto expenses = running_expenses(w.cache);
175+
const auto savings_rate = running_savings_rate(w.cache);
176+
const auto nw = get_fi_net_worth(w.cache);
177+
const auto goal = years * expenses;
178+
const auto missing = goal - nw;
179+
const auto income = running_income(w.cache);
179180

180181
date_type base_months = 0;
181182
{
182183
auto current_nw = nw;
183-
while (current_nw < years * expenses) {
184+
while (current_nw < goal) {
184185
current_nw *= 1.0 + (roi / 100.0) / 12;
185186
current_nw += (savings_rate * income) / 12;
186187

@@ -202,15 +203,15 @@ void budget::retirement_status(budget::writer& w) {
202203
contents.push_back({""s, ""s});
203204
contents.push_back({"Running expenses"s, to_string(expenses) + " " + currency});
204205
contents.push_back({"Monthly expenses"s, to_string(expenses / 12) + " " + currency});
205-
contents.push_back({"Target Net Worth"s, to_string(years * expenses) + " " + currency});
206+
contents.push_back({"Target Net Worth"s, to_string(goal) + " " + currency});
206207

207208
contents.push_back({""s, ""s});
208209
contents.push_back({"Current Net Worth"s, to_string(nw) + " " + currency});
209210
contents.push_back({"Missing Net Worth"s, to_string(missing) + " " + currency});
210211
contents.push_back({"Running Income"s, to_string(income) + " " + currency});
211212
contents.push_back({"Running Savings Rate"s, to_string(100 * savings_rate) + "%"});
212213
contents.push_back({"Yearly savings"s, to_string(savings_rate * income) + " " + currency});
213-
contents.push_back({"FI Ratio"s, to_string(100 * (nw / missing)) + "%"});
214+
contents.push_back({"FI Ratio"s, to_string(100 * (nw / goal)) + "%"});
214215

215216
auto fi_date = budget::local_day() + budget::months(base_months);
216217
contents.push_back({""s, ""s});
@@ -240,7 +241,7 @@ void budget::retirement_status(budget::writer& w) {
240241
auto current_nw = nw;
241242
size_t months = 0;
242243

243-
while (current_nw < years * expenses) {
244+
while (current_nw < goal) {
244245
current_nw *= 1.0 + (roi / 100.0) / 12;
245246
current_nw += (dec_savings_rate * income) / 12;
246247

0 commit comments

Comments
 (0)