September 2018
Intermediate to advanced
398 pages
9h 43m
English
As usual, let's start with a new unit test to clarify what we expect from this function:
"RetCalc.nbOfMonthsSaving" should { "calculate how long I need to save before I can retire" in { val actual = RetCalc.nbOfMonthsSaving( interestRate = 0.04 / 12, nbOfMonthsInRetirement = 40 * 12, netIncome = 3000, currentExpenses = 2000, initialCapital = 10000) val expected = 23 * 12 + 1 actual should ===(expected) }}
In this test, the expected value can be a bit difficult to figure out. One way would be to use the NPM function in Excel. Alternatively, you could call simulatePlan many times in the Scala Console, and increase nbOfMonthsSaving to gradually find out what the optimal value is.
Read now
Unlock full access