September 2018
Intermediate to advanced
398 pages
9h 43m
English
When we have VariableReturns over a long period, for instance, 1900 to 2017, it can be interesting to use a smaller period to simulate what would happen if the historical returns in a smaller period, say 50 years, would be repeated.
We are going to create a method in the VariableReturns class that will keep only the returns contained in a specific period. Here is the unit test in ReturnsSpec.scala:
"VariableReturns.fromUntil" should { "keep only a window of the returns" in { val variableReturns = VariableReturns(Vector.tabulate(12) { i => val d = (i + 1).toDouble VariableReturn(f"2017.$d%02.0f", d) }) variableReturns.fromUntil("2017.07", "2017.09").returns should === (Vector( VariableReturn("2017.07" ...
Read now
Unlock full access