محاسبه‌گر NPV (مجموع ارزش فعلی)

برای جریان نقدی پروژه و ارزیابی اقتصادی‌بودن آن

				
					import numpy as np

import matplotlib.pyplot as plt



def calculate_npv(cashflows, discount_rate, initial_investment):

  npv = -initial_investment # Deduct initial investment from NPV

  discounted_cashflows = []



  for i, cashflow in enumerate(cashflows):

    discounted_cashflow = cashflow / ((1 + discount_rate) ** (i+1))

    discounted_cashflows.append(discounted_cashflow)

    npv += discounted_cashflow



  return npv, discounted_cashflows



def plot_cashflows(cashflows):

  x = np.arange(1, len(cashflows)+1)

  plt.bar(x, cashflows)

  plt.xlabel('Year')

  plt.ylabel('Cashflow')

  plt.title('Cashflows Over Time')

  plt.show()



# Get inputs from user

recovery_period = int(input("Enter recovery period (in years): "))



sales = []

expenses = []



for i in range(recovery_period):

  sales.append(float(input(f"Enter sales amount for year {i+1}: ")))

  expenses.append(float(input(f"Enter expenses amount for year {i+1}: ")))



tax_rate = float(input("Enter tax rate: "))

initial_investment = float(input("Enter initial investment: "))



cashflows = [(1 - tax_rate) * (s - e) + tax_rate * (initial_investment / recovery_period) for s, e in zip(sales, expenses)]



discount_rate = float(input("Enter discount rate: "))



# Calculate NPV

npv, discounted_cashflows = calculate_npv(cashflows, discount_rate, initial_investment)



# Print results

print("Financial Analysis Results:")

print("---------------------------")

print(f"Net Present Value (NPV): {int(npv)}") # Round NPV to integer

print("\n")



# Interpretations for the project manager

print("Interpretation and Recommendations:")

print("----------------------------------")



if npv > 0:

  print("The Net Present Value (NPV) of the project is positive, indicating that the project is expected to generate a positive return on investment. This suggests that the project has the potential for profitability.")

else:

  print("The Net Present Value (NPV) of the project is negative, indicating that the project may not generate a positive return on investment. Further evaluation and analysis are recommended to assess the viability of the project.")



print("\n")



# Plot cash flows

plot_cashflows(cashflows)