Question
Consider for example annuity A, which pays $1,000 per year for 25 years, at a cost of $15,000 today. Now consider annuity B, which pays
-
Consider for example annuity A, which pays $1,000 per year for 25 years, at a cost of $15,000 today. Now consider annuity B, which pays $1,250 per year for 20 years, also at a cost of $15,000 today. Which is a better investment? One way to compare them is to find the implied rate of return in each case; all other things considered equal, the investment with the higher rate of return is superior.
Write a function annuity_rate(n, pmt, pv) to solve for and return the rate of interest required to amortize the pv in n periods with equal periodic payments of pmt.
Your function should call your pv_annuity(r, n, pmt) function when appropriate, and not re-write this calculation in this function.
Examples:
>>> annuity_rate(25,1000,15000) 0.043884217739105225 >>> annuity_rate(20,1250,15000) 0.054501140117645286
The calculation will require use of an iterative process, i.e., a loop, to implement a trial-and-error method of converging on the correct rate of return. We cannot not know in advance how many times we will need to iterate until we have reached a soluition, so this problem lends itself to using an indefinite (while) loop.
You will change the interest rate slightly at each iteration, and then calculate the present value of the annuity payments using that new interest rate. You will know that you have a correct result when the present value of the annuity payments is equal to the present value given by the functions parameter pv.
-
pv annuity function is given:
-
def pv_annuity(r, n, pmt): """ Return the present value of an annuity of pmt to be received each period for n periods """ pv = pmt * ((1 - (1 + r) ** (-n)) / r)
return pv
.-
Once your basic iterative calcuation is working correctly, switch to using an indefinite (while) loop. You will need to stop when you get close enough to the correct result. I recommend that close enough is when the error in the present value is less than $0.01 or $0.001.
-
-
-
When your function is complete, it must return the result. Do not print. Comment out any print statements in your function.
-
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started