A Friendly Reminder

If you have read the last couple sections on accumulation and amount functions, you may wonder why we have to define a growth function prior to defining an Amount or Accumulation class. After all, this seems cumbersome and it would be more convenient to simply create an Amount or Accumulation class by specifying an interest rate.

The good news is, we can actually do this! All you have to do is supply a float object to either the Amount or Accumulation classes. Since compound annual interest is the most common scenario, these classes are defined to assume compound annual interest as the default case when supplied with a float. This reduces the amount of typing required by the user.

For example, if money grows at a compound rate of 5%, we can define an accumulation class with a single argument, and see what value it accumulates to after 5 years:

In [1]: from tmval import Accumulation

In [2]: my_acc = Accumulation(gr=.05)

In [3]: print(my_acc.val(5))
1.2762815625000004

If you want to be more explicit about the interest rate, both classes also accept a Rate object:

In [4]: from tmval import Rate

In [5]: my_acc2 = Accumulation(gr=Rate(.05))

In [6]: print(my_acc2.val(5))
1.2762815625000004

In [7]: gr=Rate(
   ...:    rate=.05,
   ...:    pattern="Effective Interest",
   ...:    interval=1
   ...: )
   ...: 

In [8]: my_acc3 = Accumulation(gr=gr)

In [9]: print(my_acc3.val(5))
1.2762815625000004

This also works with simple interest:

In [10]: my_acc4 = Accumulation(gr=Rate(s=.05))

In [11]: print(my_acc4.val(5))
1.25

While it’s possible to even define your own growth functions for simple and compound interest and supply them to the Accumulation and Amount classes, it’s generally not recommended and it’s more computationally efficient to use the Rate class unless you have a custom growth pattern, since more complex financial classes can use more efficient algorithms if they detect a Rate object instead of a function.