The Maxwell School
Syracuse University
Syracuse University
""" npvtools.py Spring 2020 PJW Module providing functions for computing NPVs of cashflows stored in text files. """ # # Read a cashflow file and return a list of dated payments # def read_cashflow(filename,splitter=None): pmts = [] fh = open(filename) for line in fh: words = line.split(splitter) new_pmt = { 't':int(words[0]), 'amt':float(words[1]) } pmts.append(new_pmt) fh.close() return pmts # # Given an interest rate and a list of dated payments, compute # an NPV. # def npv(r,cashflow): val = 0 for pmt in cashflow: val = val + pmt['amt']/(1+r)**pmt['t'] return val