import numpy as np
r = 0.08
pv_investments = np.sum(
np.array([100, 20]) * (1+r)**np.arange(0, -2, -1)
)
pv_withdrawals = np.sum(
np.array([50, 50, 50, 80]) * (1+r)**np.arange(-2, -6, -1)
)
print(f"PV of investments is ${pv_investments:.2f}")
print(f"PV of withdrawals is ${pv_withdrawals:.2f}")
PV of investments is $118.52 PV of withdrawals is $173.76
cash_flows = np.array(
[-100, -20, 50, 50, 50, 80]
)
NPV = np.sum(
cash_flows * (1+r)**np.arange(0, -6, -1)
)
print(f"The NPV is ${NPV:.2f}")
The NPV is $55.24
import numpy_financial as npf
NPV = npf.npv(0.08, cash_flows)
print(f"The NPV is ${NPV:.2f}")
The NPV is $55.24