Interest¶
Suppose we invest at time 0. We define the amount of interest earned between times and as:
We define the effective rate of interest for the interval as:
and, if ,
To examine the effective interest rate for a single time period, the -th time period, we can define:
Examples¶
We can use the Amount
class to make various interest calculations. For example, assume the following amount function:
If we invest $5 at time 0, What is the interest earned during the 5th time period?
First lets set up our Amount
instance:
In [1]: from tmval import Amount
In [2]: def f(t, k):
...: return k * (.02 * (t **2) + .02 * t + 1)
...:
In [3]: my_amt = Amount(gr=f, k=5)
We can use the Amount
class’s interest_earned()
method to get the answer:
In [4]: interest = my_amt.interest_earned(t1=4, t2=5)
In [5]: print(interest)
1.0
What is the effective interest rate during the 5th time period? We can use the Amount
class’s effective_rate()
method to get the answer:
In [6]: eff_interest_rate_amt = my_amt.effective_rate(n=5)
In [7]: print(eff_interest_rate_amt)
Pattern: Effective Interest
Rate: 0.14285714285714285
Unit of time: 1 year
We can also use the effective_interval()
method to find the effective rate over a longer interval, say from times 1 to 5:
In [8]: eff_interval_rate_amt = my_amt.effective_interval(t1=1, t2=5)
In [9]: print(eff_interval_rate_amt)
Pattern: Effective Interest
Rate: 0.5384615384615384
Unit of time: 4 years
TmVal’s Accumulation
class is a subclass of the Amount
class. This means that many of the methods that can be used from the Amount
class can also be used by the Accumulation
class.
Assuming proportionality, we can define an amount function from an accumulation function and then get the effective interest rate for the 5th interval. It should be the same answer as that achieved from the amount function:
In [10]: import math
In [11]: my_acc = my_amt.get_accumulation()
In [12]: eff_interest_rate_acc = my_acc.effective_rate(n=5)
In [13]: print(eff_interest_rate_acc)
Pattern: Effective Interest
Rate: 0.142857142857143
Unit of time: 1 year
In [14]: print(math.isclose(eff_interest_rate_acc.rate, eff_interest_rate_amt.rate, rel_tol=.0001))
True
Note that there is some loss of precision due to floating point operations, so we use isclose()
from the math
library for the comparison.