domingo, 26 de octubre de 2014

Net Present Value with variable and constant interest

Finally here you are the complete program under python (v2.7 & 3.x)to calculate the Net Present Value for a single project. Surely, it exists math and economical libraries to perform this operation, but by now I am trying to learn how to use this language and learning how to think algorithmically too.

The next step for this small project is mount it in window and make a desktop program for windows and carry out comparisons among different investment projects. And then... and then...



### PROGRAM TO CALCULATE THE NET PRESENT VALUE 
### WITH CONSTANT AND VARIABLE INTEREST


#### DATA ####

t_in=raw_input("costant interest? y /n")
t = int(raw_input("Number of years?:"))
x = float(raw_input("initial investment?:"))
van = -x


#### CONSTANT INTEREST ####

if t_in == "y":
    i = float(raw_input("interest(%):"))
    for j in range(1, t + 1):
        print "flujo caja ano", j
        f = float(raw_input())
        ret = f / ((1 + (i / 100)) ** j)
        van += ret

#### VARIABLE INTEREST ####

if t_in =="n":
    print "Interest is not constant"
    prod = 1

    for j in range(1, t + 1):
        print "Cashflow year", j
        cf = float(raw_input())
        print "Interest year", j
        i = float(raw_input(""))
        prod *= (1+(i/100)) # Productory
        van += cf/prod      # Sumatory

##### RESULTS #####

print "Net present value is:", van
if van >= 0:
print "You can invest"
elif van < 0:
print "Do not invest"
elif van = 0

print "Use more indicators"

No hay comentarios:

Publicar un comentario