I need to create a function which calculates NPV of Cash flows from a list, using different one-year discount rates at different points in time. Such that r is a list of floats of length len(cash flows)-1, where the value at position 'i' is discount rate to use between periods i and i + 1. Cannot use numpy as this is the requirement of an assignment.
cash_flows = [1000, 5000, 3000] r = [0.05, 0.08, 0.1]
I am new to python and have written below after understanding from here and my class. If you can please help. Thanks!
def npv(cash_flows, r):
for t, cf in enumerate(cash_flows, 1):
for t, r in enumerate(r, 1):
result = 0
result += (cf/(1 + r) ** t)
return result
How to get a changing discount rate as enumerate only takes 2 parameters?