
[Python-Financial]NPV, SPP,DPP and IRR to assess the feasibility of project implementation
import pandas as pd
import datetime as dt
from scipy.optimize import fsolve
investment = 1000000
start_date = dt.datetime(2020, 1, 1)
end_date = dt.datetime(2024, 12, 31)
project_life = round((end_date - start_date).days / 365, 0)
tax_rate = 0.25
discount_rate = 0.15
scrap_value = 100000
cash_flow = {
'Date': [
dt.datetime(2020, 12, 31),
dt.datetime(2021, 12, 31),
dt.datetime(2022, 12, 31),
dt.datetime(2023, 12, 31),
dt.datetime(2024, 12, 31)
],
'Cash Inflow': [1000000, 1000000, 1100000, 1100000, 1100000],
'Cash Outflow': [660000, 670000, 680000, 690000, 700000]
}
df = pd.DataFrame(cash_flow)
# Calculate number of periods,
#depreciation, profit before tax,
#income tax, net profit, net cash flow,
# discount factor and discounted cash flow
df['Period'] = round((df['Date'] - start_date).dt.days / 365, 2)
df['Depreciation'] = (investment - scrap_value) / project_life * (df['Period'] - df['Period'].shift(1).fillna(0))
df['Pre-tax Profit'] = df['Cash Inflow'] - df['Cash Outflow'] - df['Depreciation']
df['Income Tax'] = df['Pre-tax Profit'] * tax_rate
df['Net Profit'] = df['Pre-tax Profit'] - df['Income Tax']
df['Net Cash Flow'] = df['Net Profit'] + df['Depreciation']
df['Discount Factor'] = (1 + discount_rate) ** df['Period']
df['Discounted Cash Flow'] = df['Net Cash Flow'] / df['Discount Factor']
# Calculate NPV
NPV = df['Discounted Cash Flow'].sum() - investment
# Calculate SPP
df2 = df[['Net Cash Flow', 'Discounted Cash Flow']].cumsum()
df2 = pd.concat([df['Period'], df2 - investment], axis=1)
i = df2[(df2['Net Cash Flow'] * df2['Net Cash Flow'].shift(1)) < 0].index[0]
SPP = df2.iloc[i-1, 0] + abs(df2.iloc[i-1, 1]) / (abs(df2.iloc[i-1, 1]) + df2.iloc[i, 1])
# Calculate DPP
j = df2[(df2['Discounted Cash Flow'] * df2['Discounted Cash Flow'].shift(1)) < 0].index[0]
DPP = df2.iloc[j-1, 0] + abs(df2.iloc[j-1, 2]) / (abs(df2.iloc[j-1, 2]) + df2.iloc[j, 2])
# Calculate IRR
def f(x):
y = 0
for i, row in df[['Period', 'Net Cash Flow']].iterrows():
y = y + row['Net Cash Flow'] / (1 + x[0]) ** row['Period']
y = -investment + y
return y
irr = fsolve(f, [0])[0]
# Output results
print("NPV:", NPV)
print("SPP:", SPP)
print("DPP:", DPP)
print("IRR:", irr)To judge whether a project is feasible, the first thing we consider is the opportunity cost. Opportunity cost refers to using the given capital to invest in this project and giving up other projects. If the rate of return on investing in other projects is 10%, then the rate of return on investing in this project must be much higher than 10% to prove that this project is feasible and worthy of investment.
Net Present Value (NPV) is the difference between the discounted present value of future cash flows generated by an investment and the present value of the project investment cost. If the net present value is positive, the investment plan is acceptable; if the net present value is negative, the investment plan is theoretically unacceptable.
Static payback period: The time it takes for future net cash flows to accumulate to the original investment without considering the time value of money.
Dynamic payback period: considering the time value of money, the time it takes for the present value of future net cash flows to accumulate to the original investment