Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import sys
- def calc_npv(cf, invest, discount):
- result = 0
- r = discount
- for i in range (len(cf)):
- result += ((cf[i])/((1+r)**(i+1)))
- #print(f"{i} ({cf[i]}) : {result}")
- return int(result)
- def calc_irr(cf, invest, discount):
- counter = 0
- rate = 1
- gs = 0.1
- cnt = 0
- npv = calc_npv(cf,invest, gs)
- gs +=0.001
- if (cnt > 110):
- return -1
- else:
- cnt+=1
- while(npv > 0):
- #print(f"npv: {npv}")
- #print(f"gs: {gs}")
- npv = calc_npv(cf,invest, gs)
- gs +=0.001
- if (cnt > 110000):
- print(f"shit {gs} : {counter}")
- return -1
- else:
- cnt+=1
- counter +=1
- return gs
- def main():
- #33000 34000 38000 40000
- cf = [400, 400, 400, 400]
- #cf = [333, 278, 231, 193]
- #cf = [35000, 40000, 45000, 50000, 0, 0, 0] # MOI VARIANT
- #cf = [33000, 34000, 35000, 31000]
- invest = 1000
- #invest = 116000 # MOI VARIANT
- discount = 0.2
- #discount = 0.12 # MOI VARIANT
- something = 0.1 # % CHTO ETO?!?!?!?!?!
- npv = calc_npv(cf, invest, discount)
- print(f"NPV = {npv}")
- #rent = npv/cf[0]
- rent = npv/invest
- print(f"RENT = {rent}")
- if (npv > 0):
- print("Выгодно")
- else:
- print("Невыгодно")
- mocha = calc_irr(cf, invest, discount)
- print(mocha)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement