
# The salary you want to retire on (today's equavalent).  It'll be automatically adjusted for inflation                                                                            
TODAYS_EQUIVALENT_SALARY = 50000

INFLATION = .03
AVG_INTEREST = .08
CURRENT_AGE = 0
RETIREMENT_AGE = 65

import locale
locale.setlocale( locale.LC_ALL, '' )


# Calculate how much money you need when...                                                                                                                                        

total_years = RETIREMENT_AGE - CURRENT_AGE
future_salary = TODAYS_EQUIVALENT_SALARY * pow( 1 + INFLATION, total_years)

def dollars(num):
    return locale.currency(num, grouping=True)

print "\n\nWelcome to the Reverse Financial Calculator!\n"
print "%s is %s when you are %d" % ( dollars(TODAYS_EQUIVALENT_SALARY), dollars(future_salary), RETIREMENT_AGE )


total_savings_needed = future_salary/AVG_INTEREST;
print "To make that much money on %f%% interest you must have a savings of %s" % (AVG_INTEREST * 100, dollars(total_savings_needed))

print
print "You can stop saving up if you reach a total savings of one of these figures at the corresponding age."


print "AGE    STOP AT"
for i in range(total_years + 1):
    stop_at = total_savings_needed/pow(1+AVG_INTEREST, total_years - i)
    series = range(i+1)
    series = [pow(1 + AVG_INTEREST, y) for y in series]
    per_year = stop_at/(sum(series) or 1.0)

    starting_late = ', '.join([dollars(stop_at/(sum(series[:j]) or 1.0)) for j in range(4)])

    print "%2d     %12s  %s/year" % ( i + CURRENT_AGE, dollars(stop_at), dollars(per_year))
