Skip to content

Commit d9b200a

Browse files
committed
Refactor retirement status
1 parent e629b11 commit d9b200a

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

src/retirement.cpp

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,27 @@ void budget::retirement_status(budget::writer& w) {
171171
const auto wrate = to_number<double>(internal_config_value("withdrawal_rate"));
172172
const auto roi = to_number<double>(internal_config_value("expected_roi"));
173173
const auto years = double(100.0 / wrate);
174-
const auto expenses = running_expenses(w.cache);
175174
const auto savings_rate = running_savings_rate(w.cache);
176175
const auto nw = get_fi_net_worth(w.cache);
177-
const auto goal = years * expenses;
178-
const auto missing = goal - nw;
179176
const auto income = running_income(w.cache);
180177

181-
date_type base_months = 0;
178+
const auto run_expenses = running_expenses(w.cache);
179+
const auto run_goal = years * run_expenses;
180+
const auto run_missing = run_goal - nw;
181+
182+
date_type run_base_months = 0;
182183
{
183184
auto current_nw = nw;
184-
while (current_nw < goal) {
185+
while (current_nw < run_goal) {
185186
current_nw *= 1.0 + (roi / 100.0) / 12;
186187
current_nw += (savings_rate * income) / 12;
187188

188-
++base_months;
189+
++run_base_months;
189190
}
190191
}
191192

193+
auto run_fi_date = budget::local_day() + budget::months(run_base_months);
194+
192195
std::vector<std::string> columns = {};
193196
std::vector<std::vector<std::string>> contents;
194197

@@ -199,30 +202,24 @@ void budget::retirement_status(budget::writer& w) {
199202
contents.push_back({"Annual Return"s, to_string(roi) + "%"});
200203
contents.push_back({"Years of expense"s, to_string(years)});
201204

202-
// The target
203-
contents.push_back({""s, ""s});
204-
contents.push_back({"Running expenses"s, to_string(expenses) + " " + currency});
205-
contents.push_back({"Monthly expenses"s, to_string(expenses / 12) + " " + currency});
206-
contents.push_back({"Target Net Worth"s, to_string(goal) + " " + currency});
207-
208205
contents.push_back({""s, ""s});
209206
contents.push_back({"Current Net Worth"s, to_string(nw) + " " + currency});
210-
contents.push_back({"Missing Net Worth"s, to_string(missing) + " " + currency});
211207
contents.push_back({"Running Income"s, to_string(income) + " " + currency});
212208
contents.push_back({"Running Savings Rate"s, to_string(100 * savings_rate) + "%"});
213209
contents.push_back({"Yearly savings"s, to_string(savings_rate * income) + " " + currency});
214-
contents.push_back({"FI Ratio"s, to_string(100 * (nw / goal)) + "%"});
215-
216-
auto fi_date = budget::local_day() + budget::months(base_months);
217-
contents.push_back({""s, ""s});
218-
contents.push_back({"Months to FI"s, to_string(base_months)});
219-
contents.push_back({"Years to FI"s, to_string(base_months / 12.0)});
220-
contents.push_back({"Date to FI"s, to_string(fi_date)});
221210

222-
contents.push_back({""s, ""s});
223-
contents.push_back({"Current Withdrawal Rate"s, to_string(100.0 * (expenses / nw)) + "%"});
224-
contents.push_back({"Months of FI"s, to_string(nw / (expenses / 12))});
225-
contents.push_back({"Years of FI"s, to_string(nw / expenses)});
211+
// The target (running expenses)
212+
contents.push_back({"Current expense"s, ""s});
213+
contents.push_back({"Running expenses"s, to_string(run_expenses) + " " + currency});
214+
contents.push_back({"Target Net Worth"s, to_string(run_goal) + " " + currency});
215+
contents.push_back({"Missing Net Worth"s, to_string(run_missing) + " " + currency});
216+
contents.push_back({"FI Ratio"s, to_string(100 * (nw / run_goal)) + "%"});
217+
contents.push_back({"Months to FI"s, to_string(run_base_months)});
218+
contents.push_back({"Years to FI"s, to_string(run_base_months / 12.0)});
219+
contents.push_back({"Date to FI"s, to_string(run_fi_date)});
220+
contents.push_back({"Current Withdrawal Rate"s, to_string(100.0 * (run_expenses / nw)) + "%"});
221+
contents.push_back({"Months of FI"s, to_string(nw / (run_expenses / 12))});
222+
contents.push_back({"Years of FI"s, to_string(nw / run_expenses)});
226223

227224
contents.push_back({""s, ""s});
228225
contents.push_back({"Current Yearly Allowance"s, to_string(nw * (wrate / 100.0))});

0 commit comments

Comments
 (0)