In Chapter 2, Developing a Retirement Calculator, we implemented a Returns.monthlyRate(returns: Returns, month: Int): Double function that returned the monthly return rate for a given month. When we called it with a month exceeding the size of an instance of VariableReturns, we rolled over to the first month using a modulo operation.
This was not completely satisfying, as it could compute unrealistic simulations. Say that your VariableReturns instance contains data for 1950 to 2017. When you ask the monthly returns for 2018, monthlyRate would give you the returns that we had in 1950. The economic outlook of the fifties was very different compared to the current one, and it is unlikely that the returns in 2018 will ...