From 3a428d4493d6819db2f161832066e03756b78912 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Sat, 1 Mar 2025 21:07:10 +0100 Subject: [PATCH 1/3] One more FI ratio fix --- src/retirement.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/retirement.cpp b/src/retirement.cpp index a9120a1..72ef747 100644 --- a/src/retirement.cpp +++ b/src/retirement.cpp @@ -167,20 +167,21 @@ void budget::retirement_status(budget::writer& w) { } } - auto currency = get_default_currency(); - auto wrate = to_number(internal_config_value("withdrawal_rate")); - auto roi = to_number(internal_config_value("expected_roi")); - auto years = double(100.0 / wrate); - auto expenses = running_expenses(w.cache); - auto savings_rate = running_savings_rate(w.cache); - auto nw = get_fi_net_worth(w.cache); - auto missing = years * expenses - nw; - auto income = running_income(w.cache); + const auto currency = get_default_currency(); + const auto wrate = to_number(internal_config_value("withdrawal_rate")); + const auto roi = to_number(internal_config_value("expected_roi")); + const auto years = double(100.0 / wrate); + const auto expenses = running_expenses(w.cache); + const auto savings_rate = running_savings_rate(w.cache); + const auto nw = get_fi_net_worth(w.cache); + const auto goal = years * expenses; + const auto missing = goal - nw; + const auto income = running_income(w.cache); date_type base_months = 0; { auto current_nw = nw; - while (current_nw < years * expenses) { + while (current_nw < goal) { current_nw *= 1.0 + (roi / 100.0) / 12; current_nw += (savings_rate * income) / 12; @@ -202,7 +203,7 @@ void budget::retirement_status(budget::writer& w) { contents.push_back({""s, ""s}); contents.push_back({"Running expenses"s, to_string(expenses) + " " + currency}); contents.push_back({"Monthly expenses"s, to_string(expenses / 12) + " " + currency}); - contents.push_back({"Target Net Worth"s, to_string(years * expenses) + " " + currency}); + contents.push_back({"Target Net Worth"s, to_string(goal) + " " + currency}); contents.push_back({""s, ""s}); contents.push_back({"Current Net Worth"s, to_string(nw) + " " + currency}); @@ -210,7 +211,7 @@ void budget::retirement_status(budget::writer& w) { contents.push_back({"Running Income"s, to_string(income) + " " + currency}); contents.push_back({"Running Savings Rate"s, to_string(100 * savings_rate) + "%"}); contents.push_back({"Yearly savings"s, to_string(savings_rate * income) + " " + currency}); - contents.push_back({"FI Ratio"s, to_string(100 * (nw / missing)) + "%"}); + contents.push_back({"FI Ratio"s, to_string(100 * (nw / goal)) + "%"}); auto fi_date = budget::local_day() + budget::months(base_months); contents.push_back({""s, ""s}); @@ -240,7 +241,7 @@ void budget::retirement_status(budget::writer& w) { auto current_nw = nw; size_t months = 0; - while (current_nw < years * expenses) { + while (current_nw < goal) { current_nw *= 1.0 + (roi / 100.0) / 12; current_nw += (dec_savings_rate * income) / 12; From 5c30bb0f7866a9aa0095ba82e80d0320765e14c9 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Sun, 2 Mar 2025 07:50:01 +0100 Subject: [PATCH 2/3] Improvements for overviews in the future --- src/overview.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/overview.cpp b/src/overview.cpp index e92216c..61112f8 100644 --- a/src/overview.cpp +++ b/src/overview.cpp @@ -15,6 +15,7 @@ #include "cpp_utils/assert.hpp" #include "cpp_utils/hash.hpp" +#include "date.hpp" #include "overview.hpp" #include "console.hpp" #include "data_cache.hpp" @@ -1148,8 +1149,14 @@ void budget::display_month_overview(budget::month month, budget::year year, budg second_contents.emplace_back(std::vector{"Tax Rate", budget::to_string(tax_rate) + "%"}); } + const budget::date today = budget::local_day(); const budget::date month_start(year, month, 1); - const budget::date month_end = month_start.end_of_month(); + budget::date month_end = month_start.end_of_month(); + + // If we are on the current month, we avoid going into the future + if (month_start.year() == today.year() && month_start.month() == today.month()) { + month_end = today; + } auto net_worth_end = get_net_worth(month_end, writer.cache); auto net_worth_month_start = get_net_worth(month_start, writer.cache); From a3a24aeff05f0e45faad7bd8aac9bba7a0bf8574 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Sun, 2 Mar 2025 07:53:14 +0100 Subject: [PATCH 3/3] Avoid computations in the future --- src/overview.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/overview.cpp b/src/overview.cpp index 61112f8..aab5824 100644 --- a/src/overview.cpp +++ b/src/overview.cpp @@ -1151,24 +1151,28 @@ void budget::display_month_overview(budget::month month, budget::year year, budg const budget::date today = budget::local_day(); const budget::date month_start(year, month, 1); - budget::date month_end = month_start.end_of_month(); - // If we are on the current month, we avoid going into the future - if (month_start.year() == today.year() && month_start.month() == today.month()) { - month_end = today; - } + // We cannot compute NW increases in the future + if (month_start.end_of_month() < today) { + budget::date month_end = month_start.end_of_month(); - auto net_worth_end = get_net_worth(month_end, writer.cache); - auto net_worth_month_start = get_net_worth(month_start, writer.cache); + // If we are on the current month, we avoid going into the future + if (month_start.year() == today.year() && month_start.month() == today.month()) { + month_end = today; + } - auto month_increase = net_worth_end - net_worth_month_start; + auto net_worth_end = get_net_worth(month_end, writer.cache); + auto net_worth_month_start = get_net_worth(month_start, writer.cache); - second_contents.emplace_back(std::vector{"Net Worth Increase", budget::to_string(month_increase)}); + auto month_increase = net_worth_end - net_worth_month_start; - if (month_increase.zero() || month_increase.negative()) { - second_contents.emplace_back(std::vector{"Savings Contribution", "N/A"}); - } else { - second_contents.emplace_back(std::vector{"Savings Contribution", budget::to_string(100.0 * (savings / month_increase)) + "%"}); + second_contents.emplace_back(std::vector{"Net Worth Increase", budget::to_string(month_increase)}); + + if (month_increase.zero() || month_increase.negative()) { + second_contents.emplace_back(std::vector{"Savings Contribution", "N/A"}); + } else { + second_contents.emplace_back(std::vector{"Savings Contribution", budget::to_string(100.0 * (savings / month_increase)) + "%"}); + } } writer.display_table(second_columns, second_contents, 1, {}, accounts.size() * 9 + 1);