Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import sys
  3.  
  4.  
  5. def calc_npv(cf, invest, discount):
  6. result = 0
  7. r = discount
  8. for i in range (len(cf)):
  9. result += ((cf[i])/((1+r)**(i+1)))
  10. #print(f"{i} ({cf[i]}) : {result}")
  11. return int(result)
  12.  
  13. def calc_irr(cf, invest, discount):
  14. counter = 0
  15. rate = 1
  16. gs = 0.1
  17. cnt = 0
  18. npv = calc_npv(cf,invest, gs)
  19. gs +=0.001
  20. if (cnt > 110):
  21. return -1
  22. else:
  23. cnt+=1
  24. while(npv > 0):
  25. #print(f"npv: {npv}")
  26. #print(f"gs: {gs}")
  27. npv = calc_npv(cf,invest, gs)
  28. gs +=0.001
  29. if (cnt > 110000):
  30. print(f"shit {gs} : {counter}")
  31. return -1
  32. else:
  33. cnt+=1
  34. counter +=1
  35. return gs
  36.  
  37.  
  38.  
  39. def main():
  40. #33000 34000 38000 40000
  41. cf = [400, 400, 400, 400]
  42. #cf = [333, 278, 231, 193]
  43. #cf = [35000, 40000, 45000, 50000, 0, 0, 0] # MOI VARIANT
  44. #cf = [33000, 34000, 35000, 31000]
  45. invest = 1000
  46. #invest = 116000 # MOI VARIANT
  47. discount = 0.2
  48. #discount = 0.12 # MOI VARIANT
  49.  
  50. something = 0.1 # % CHTO ETO?!?!?!?!?!
  51. npv = calc_npv(cf, invest, discount)
  52. print(f"NPV = {npv}")
  53. #rent = npv/cf[0]
  54. rent = npv/invest
  55. print(f"RENT = {rent}")
  56. if (npv > 0):
  57. print("Выгодно")
  58. else:
  59. print("Невыгодно")
  60.  
  61. mocha = calc_irr(cf, invest, discount)
  62. print(mocha)
  63.  
  64.  
  65. if __name__ == "__main__":
  66. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement