Question: 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!)
 need help with code! (please include comments in code for each

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!