I am a grad student getting my MBA with an emphasis in finance. I am struggling to answers this question as I have no experience in coding. I am supposed to work the problem using python. Any help would be greatly appreciated!
PROBLEM Problem Statement: We have a project with given cashflows.
[-50, 20, 10, 30, 10, 15] The first element is negative and represents the initial investment required for the project. The subsequent elements represent the expected cash inflows and outflows from the project over 15 periods.
We would like to calculate the Internal Rate of Return (IRR) of this project. As a reminder, the IRR is the discount rate at which the NPV of a project equals zero. Therefore, we are looking for an such that
()=0⇒−50+201++10(1+)2+30(1+)3+10(1+)4+15(1+)5=0.
In this exercise, we will numerically solve this equation using Numpy. The idea is to calculate () over a grid of , e.g., [0,0.001,0.002,0.003,…,0.199,0.200] , and find a point on the grid where () is close to zero. The finer our initial grid, the closer we can get to the root of the equation above.
Your task is to:
Define the cash flows array. Create an array of potential discount rates ranging from 0% to 20%. Calculate the NPV for each discount rate. Identify the discount rate at which the NPV is closest to zero. This rate is the project's approximate IRR.
GUIDE
Step 1:
import numpy as np
# Define the number of points on the grid
N = 10001
# Define cashflows
cash_flows = np.array([-60, 20, 10, 30, 10, 15])
# Define the array of potential discount rates
r = np.linspace(0, 0.20, N)
# Define an array to keep NPV values
npv = np.zeros((N,))
Step 2:
# Calculate NPVs for each value of the discount rate
for i in range(N):
# Calculate NPV for discount rate = r[i]
Step 3:
# Identify the discount rate at which NPV is closest to zero
index = np.argmin(np.abs(npv))
Step 4:
# Print the IRR
Step 5:
# Copy the code for N = 1001
Step 6:
# Copy the code for N = 10001
I tried used ChatGPT, but I am not getting the correct code.