This app will help users by simplifying the retirement planning process down to a core set of five questions and then present the broad contours of how your wealth will grow and whether your money will be able to last you for the rest of your life.
Wow, beautiful design!! Here is some screenshots for those just passing through. I really really like the suggestions / scenarios section at the bottom. Thanks for sharing, I’ll have to share this with a few of my friends
I assume you are asking how I project wealth into the future using market returns, savings and spending:
I generate a random market return for every year of the user’s life. This is just generating a random number (in my case I’m using a mean of 0.08 and standard deviation of .14).
If a user is expected to live another 60 years, that’s 60 random numbers and that represents a possible future for the user.
I then construct 10,000 of these possible futures. In effect this constructs an array with 10,000 sub-arrays and each of these subarrays is composed of 60 random stock market returns. This is called a Monte Carlo simulation. It can easily be accomplished using the numpy python library: np.random.normal(mean, stdev, size=[num_simulations, periods]) (see random_walk_simulations() in functions.py)
Similarly I then construct a 10,000 x 60 matrix (array) containing information about user savings in each year, another matrix for user spending, another matrix for social security payments, allocation between stocks/bonds, etc.
then it’s just a matter of combining all these matrices together. See the calc_wealth_trajectory() function for this logic. I’m going to take the wealth in the prior period and calculate the wealth in the current period by multiplying the prior wealth by the current market return (incorporating the stock return/bond return) and then adding/subtracting the user’s savings/spending.
the end result is a 10,000 x 60 matrix where each element represents the wealth at that point in time in a possible future. From there you can calculate at time t what the 50th percentile is for wealth (expected scenario), of the 5th percentile (pessimistic scenario). See wealth_distributions() for this logic.
But if you’re asking how I created the chart itself, then that’s easy too. See line 382-516 of apps/home.py
@xhlu, I actually got banned from that subreddit when I tried to post. They say it violates their rules against “promotion”. Lame. Oh well, thanks again for the feedback.