def annual_savings_lst(vars, years): res = [0 for i in range(years)] bruto_salary = vars['Bruto Salary'] net_salary = core.net_income(bruto_salary) rent = vars['Rent'] for i in range(years): res[i] = int(0.1 * bruto_salary + vars['Savings Rate From Net'] * net_salary - rent) * 12 rent *= (1 + vars['Rent Growth']) bruto_salary *= (1 + vars['Salary Growth']) net_salary *= (1 + vars['Salary Growth']) return res # run function # print(assets(0)) # rent_savings()
import core bruto_income = float(input("enter (bruto) salary ")) net_income = core.net_income(bruto_income) savings = core.savings(bruto_income) print("net income is: " + str(int(net_income)) + "\nsavings are " + str(int(savings)))
def assets(vars): #timeperiod=vars.vars['YEARS_TO_FUTURE']): vars_module.validate_vars(vars) # input validation if vars['Rent'] > core.net_income(vars['Bruto Salary']) * vars[ 'Savings Rate From Net']: # input validation return 0 # can't afford rent. Saving Rate From Net var is to small or rent is too high #monthly_savings_before_purch = int(0.1 * vars['Bruto Salary'] + vars['Savings Rate From Net'] * net_salary # - vars['Rent']) #annual_savings_before_purch = 12 * monthly_savings_before_purch prepurch_savings_return = prepurch_savings_return_calc( vars['Years To Save']) annual_savings = annual_savings_lst(vars, vars['Years To Future']) results_lst = [0 for i in range(vars['Years To Future'] + 1)] compound_interest(vars['Start Amount'], vars['Years To Future'], prepurch_savings_return,\ additions_lst=annual_savings, results_lst= results_lst) # results_lst is a list of length Years To Future + 1, now holds the savings amount for each year # before purchase, until Years To Future # now we need to calculate years_save = minimum years we need to save to have enough for minimum down payment years_save = -1 for i in range(vars['Years To Future']): if results_lst[i] >= 0.25 * house_value_calc(vars, i): years_save = i break if years_save == -1: return 0 # can't afford home, will never save enough for down payment years_save = max(years_save, vars['Years To Save']) ''' # savings_amnt is results_lst[ # prepurch_savings_return = 0.05 purch_price = house_value_calc(vars, vars['Years To Save']) # price of house at purchase time #savings_before_purch = compound_interest(vars['Start Amount'], vars['Years To Save'], prepurch_savings_return,\ # annual_savings_before_purch, vars['Salary Growth']) # take care of case when starting amount is less than 25% of house price (minimum down payment), # save until have enough for down payment years_save = vars['Years To Save'] # number of years to save for minimum down payment amnt = savings_before_purch house_price = purch_price if savings_before_purch < 0.25 * purch_price: # minimum down payment is 25% while amnt < 0.25 * house_price: prepurch_savings_return = prepurch_savings_return_calc(years_save) years_save += 1 amnt = compound_interest(vars['Start Amount'], years_save, prepurch_savings_return,\ annual_savings_before_purch, vars['Salary Growth']) house_price = house_value_calc(vars, years_save) if years_save == vars['Years To Future']: return 0 # can't afford the home ''' ''' may want to add this: if input is less than the minimum num of years to save for down payment, return 0 if vars['years_save'] < years_save: return 0 # need to save more years in order to buy home ''' #years_save now depicts vars['years_save'] + additional years to save for minimum down payment if vars['Years To Future'] <= years_save: # didn't buy home yet #return int(compound_interest(vars['Start Amount'], vars['Years To Future'], prepurch_savings_return,\ # annual_savings_before_purch, vars['Salary Growth'])) return results_lst[vars['Years To Future']] ''' if years_save >= vars['Years To Future']: # also didn't buy home yet, but waited longer, change investment return return int(compound_interest(vars['Start Amount'], vars['Years To Future'], vars['Long Term Savings Return'],\ annual_savings_before_purch, vars['Salary Growth'])) ''' if years_save >= vars['Years To Future']: return 0 # didn't have enough time to buy home purch_price = house_value_calc(vars, years_save) savings_amnt_at_purchase = results_lst[years_save] # annual mortgage payment = monthly savings before purch. + rent fee (no longer need to pay rent) # - keren hishtalmut savings #mortgage payment is effected by salary growth, not by rent growth mortgage_payment = net_salary_after_time( vars, years_save) * vars['Savings Rate From Net'] * 12 mortgage_amnt = purch_price - savings_amnt_at_purchase #print('house price ', int(house_price), 'amount ', int(amnt), 'mortgage amnt ', int(mortgage_amnt), 'years save ', years_save) # print("mortgage amount: " + str(mortgage_amnt)) # should maybe change mortage payment to be list of mortgage payment, because payment is effected by salary growth # and by rent growth mortgage_len = mortgage_calc(vars, mortgage_amnt, mortgage_payment, payment_increase_rate=vars['Salary Growth']) if mortgage_len == -1: return 0 #will never be able to pay off mortgage if vars['Years To Future'] <= years_save + mortgage_len: #means bought house, but still hasn't paid off mortgage # the timeperiod arg may be need to be fixed # assets value = (house value at YEARS_TO_FUTURE) - (mortgage left to pay) return int( house_value_calc(vars, vars['Years To Future']) - mortgage_calc(vars, mortgage_amnt, mortgage_payment, vars['Years To Future'] - years_save, vars['Salary Growth'])) # timeperiod > years to save + mortgage length # print("years to pay mortgage: " + str(mortgage_len)) # how much would have paid if still renting #rent_after_mortgage = compound_interest(vars['Rent'], years_save + mortgage_len, # vars['Rent Growth']) # might need to update to make salary increase at certain rate over time #monthly_savings_after_mortgage = vars['Savings Rate From Net'] * net_salary_after_time(vars,\ # years_save + mortgage_len)\ # + rent_after_mortgage #annual_savings_after_mortgage = 12 * monthly_savings_after_mortgage #print(timeperiod, years_save, mortgage_len, years_down_payment) #print( timeperiod - (years_save + mortgage_len + years_down_payment), annual_savings_after_mortgage) annual_savings_after_mortgage = net_salary_after_time(vars, vars['Years To Future']) * \ vars['Savings Rate From Net'] * 12 savings_after_mortgage = compound_interest( 0, vars['Years To Future'] - (years_save + mortgage_len), vars['Long Term Savings Return'], const_additions=annual_savings_after_mortgage, additions_increase_rate=vars['Salary Growth']) # print("savings before purchase: " + str(savings_before_purch)) # print("savings after mortgage: " + str(savings_after_mortgage)) # print("house worth after 50 years: " + str(end_price)) # print("total assets value: " + str(assets_value)) return int( house_value_calc(vars, vars['Years To Future']) + savings_after_mortgage)
def net_salary_after_time(vars, timeperiod): return core.net_income( compound_interest(vars['Bruto Salary'], timeperiod, vars['Salary Growth']))
import core import matplotlib.pyplot as plt import numpy as np x = np.arange(0.0, 50000.0, 10000.0) y = [core.savings(i) for i in x] z = [core.net_income(i) for i in x] l = [int(y[i] + z[i]) for i in range(len(y))] plt.plot(x, y, label='Savings') plt.plot(x, z, label='Net Income') plt.plot(x, l, label='Total: Savings + Net') plt.legend(loc='upper left') plt.xlabel('Gross Salary') plt.ylabel('₪') plt.savefig("graph1.png") plt.show()