Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help with code! (please include comments in code for each step!) Write a function to implement the Newton-Raphson optimization method to calculate the IRR

need help with code! (please include comments in code for each step!)
image text in transcribed
Write a function to implement the Newton-Raphson optimization method to calculate the IRR of cash flows. The function should: 1. Take as input a numpy array of cashflows, an initial guess for the IRR (optional), and an epsilon tolerance level (optional). a. Numpy array input: Element 0 is the time 0 cash flow, Element t is the time t cash flow b. Set guess =0.05 as the default value if not provided by the function call c. Set =0.001 as the default value if not provided by the function call d. Hint: please google "create optional arguments function python" to learn how to make certain arguments optional and set default values if not provided 2. Implement the Newton-Raphson optimization method to calculate the IRR of the cash flows based on the initial guess and tolerance a. Hint 1: You may find it useful to define two functions. One to calculate the present value of cash flows [f(x)] and another to calculate the derivative of the present value function at a particular value [f(x)]. b. Hint 2: Please google how to implement a "while loop" in Python, which will be useful to use to know when to stop generating new guesses. 3. Provide debugging informational output via a print statement, on how the optimization method arrived at the answer a. Output should show each iteration number, what the guess is in that iteration, what the present value is at that guess and the new guess (if applicable). Something like: "Iteration A3: Guess=7.5\%, PV=12.345, New Guess =5.4% " b. Output should also show the total number of iterations taken and the final answer for the IRR 4. Output a plot where the x-axis is the iteration number and the y-axis is the IRR guess at each iteration

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions