Using numpy, write function npv to compute the net present value of a set of cash flows given their timing and a single discount rate with continuous compounding.
Question
Using numpy, write function npv to compute the net present value of a set of cash flows given their timing and a single discount rate with continuous compounding.
Solution
Sure, here is a Python function using numpy to compute the net present value (NPV) of a set of cash flows given their timing and a single discount rate with continuous compounding.
import numpy as np
def npv(cash_flows, timing, discount_rate):
"""
Compute the net present value of a set of cash flows given their timing and a single discount rate with continuous compounding.
Parameters:
cash_flows (numpy array): The cash flows.
timing (numpy array): The timing of the cash flows.
discount_rate (float): The discount rate.
Returns:
float: The net present value of the cash flows.
"""
# Compute the present value of each cash flow
present_values = cash_flows * np.exp(-discount_rate * timing)
# Sum up the present values to get the net present value
npv = np.sum(present_values)
return npv
Here's how you can use this function:
cash_flows = np.array([100, 200, 300, 400, 500])
timing = np.array([1, 2, 3, 4, 5])
discount_rate = 0.05
print(npv(cash_flows, timing, discount_rate))
This will compute the NPV of the cash flows [100, 200, 300, 400, 500] at times [1, 2, 3, 4, 5] with a discount rate of 5%. The np.exp(-discount_rate * timing) part is the formula for continuous compounding.
Similar Questions
First, Using numpy, write function npv to compute the net present value of a set of cash flows given their timing and a single discount rate with continuous compounding. Then Apply npv to compute the price of a bond that pays 6% coupons payable semi-annually, knowing that the bond's face value is $1000, it matures in 30 months and the yield to maturity is 5.5% with semi-annual compounding.
Discounted cash flows applicationsNet present Value calculations have a broad range of applications in finance.Calculate the NPV of the project based on the information below.Initial investment: $20,00Cash flow generated each year: $5,000Total period: 5 YearsDiscount rate: 6%
Question 2Considering the following information, calculate the Net Present Value of the Free Cash Flows, using the NPV function in Excel or Google Sheets:Weighted Average Cost of Capital: 5%Cash Flow in Year 1: 100Cash Flow in Year 2: 100Cash Flow in Year 3: 300Cash Flow in Year 4: -200Cash Flow in Year 5: 500Terminal Value: 1400
Consider a project with the following cash flows: CF0 = -$3333 (at t=0), CF1 = 1918.14 (at t=1), and CF2 = 2207.78 (at t=2). If the required rate of return is 15.1% and the internal rate of return is 15.1%, what is the NPV of this project?[Answer: Number with 0 decimals. Do not include '$' or the thousands separator.]
NPV Calculate the net present value (NPV) for the following 20-year projects.Comment on the acceptability of each. Assume that the firm has an opportunity costof 14%.a. Initial investment is $10,000; cash inflows are $2,000 per year.b. Initial investment is $25,000; cash inflows are $3,000 per year.c. Initial investment is $30,000; cash inflows are $5,000 per year.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.