O'Reilly logo

Scala Programming Projects by Nicolas Jorand, Mikael Valot

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Refactoring monthlyRate

In Chapter 2Developing 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required