Net Present Value (NPV) On Python Using Numpy

Net present value (NPV) is the difference between the present value of cash inflows and the present value of cash outflows over a period of time. 

NPV is used in capital budgeting and investment planning.

The NPV Rule is:-
If  NPV > 0  Then the project is Accepted 
If  NPV < 0 Then the project is Rejected

The formula for calculating NPV is -


\text{NPV} = \frac{R_{t}}{(1+i)^{t}}


\text{NPV}=net present value
R_{t}=net cash flow at time t
i=discount rate
{t}=time of the cash flow

This is how NPV is calculated manually with the generic formula, now we are going to use NumPy for calculating the NPV of a project.

Here is an example. The initial investment is $100. The cash inflows in the next five years are $50, $60, $70, $100, and $20, starting from year one. If the discount rate is 11.2%, what is the project's NPV value? 


#import Numpy 
import numpy as np

#Put/define values in the cashflows & Interestrate.

CF0 = -100
CF1 = 50
CF2 = 60
CF3 = 70
CF4 = 100
CF5 = 20
interestrate = 0.112


cashflows = [CF0,CF1,CF2,CF3,CF4,CF5]
cashflows





NPV = 0


 Now we are going to calculate NPV by using 2 methods, first one is where we will create a function for calculating NPV and in the second method we will use a predefined function of NumPy for calculating NPV 

FIRST Method:-

#writing own function to calculate npv

def npv(interestrate,cashflows):
    npv=0
    for i in range(len(cashflows)):
        npv = npv + cashflows[i]/(1+interestrate)**i
    return npv



npv(interestrate,cashflows)






SECOND Method:-





This is how NPV is calculated in Python using Numpy or you can use SciPy too for doing the same.

Comments

Popular posts from this blog

Commodity Channel Index ( CCI ) Using Python

SMA Trading Strategy Using Python