Welcome to Part 2 of the series of posts dealing with how to build your own python based personal portfolio /wealth simulation model. At the end of the first post (which can be found here), we got to the point where we had modelled some inflows, some outflows, we had applied an annual salary raise to our future income flows, along with applying various tax rates to both our active income (salary) and investment income.
We had also factored in a stochastic element to our model for generating investment returns, using the historic mean monthly return and volatility of the S&P Total Return index as a proxy for the “market”. Finally, we had ended by adding a couple of lines of code that would record whether our wealth/asset value were reduced to (or below) zero at any point throughout the simulated time period; we will be using this later to help calculate our “risk of ruin”, i.e. attach probabilities to the likelihood of ending up with assets worth less than a threshold value (one that we deem unacceptable to fall below – which doesn’t have to be zero of course).
The full code snippet from the end of Part 1 is shown below for convenience (I have altered some of the outflow and inflow values back to their original levels just fyi). IMPORTANT: I have also had to include the use of the yfinance package to allow the over-riding of the Pandas DataReader packaged as at the time of writing, Pandas DataReader is currently not stable and essentially not working. The code changes are commented below to help identify them more easily.