Retirement Plan




def balance(years: int, yearly_invest_base: float, interest_rate, yearly_invest_increase_rate):
    yearly = [yearly_invest_base * (1 + yearly_invest_increase_rate) ** i for i in range(years-1, -1, -1)]
    print('Invest each year: ', yearly[::-1])

    for i in range(1, years):
        yearly[i] = yearly[i] * (1 + interest_rate) ** i

    print('Each year final: ', yearly[::-1])

    return sum(yearly)


print('Goal: ', balance(10, 15, 0.08, 0.08))

The ouptput:

Invest each year:  [15.0, 16.200000000000003, 17.496000000000002, 18.895680000000002, 20.407334400000003, 22.03992115200001, 23.803114844160007, 25.707364031692812, 27.76395315422824, 29.9850694065665]
Each year final:  [29.9850694065665, 29.985069406566502, 29.985069406566502, 29.985069406566495, 29.9850694065665, 29.9850694065665, 29.985069406566495, 29.9850694065665, 29.985069406566502, 29.9850694065665]
Goal:  299.850694065665

Leave a Reply

Your email address will not be published. Required fields are marked *