liveBook · Manning

Wealth path

As explained in Build a Robo-Advisor with Python (From Scratch)

A wealth path is a chronological sequence of portfolio wealth values representing one simulated financial trajectory.

A wealth path is a chronological sequence of portfolio wealth values representing one simulated financial trajectory. In a Monte Carlo model, a two-dimensional array stores many paths: each row is a simulation and each column is a year, beginning with initial wealth. section 5.5

Retirement simulation

With $1.2 million initially, annual spending of $60,000, 2% inflation, and normally distributed portfolio returns averaging 6% with 12% standard deviation, each path updates wealth after spending and investment returns. Thirty-year paths reveal whether the retiree reaches bankruptcy; the illustrated simulation estimates a 48.09% bankruptcy probability. section 5.5

Listing 5.4 Simulating paths of wealth
np.random.seed(123)
num_years = 30
num_sims = 10000
mean = 0.06
stdev = 0.12
spending_0 = 60000
W0 = 1200000

inflation = 0.02

ret = np.random.normal(loc=mean, scale=stdev, size=(num_sims, num_years+1))

W = np.empty(shape=[num_sims, num_years+1])
W[:,:] = np.NaN
W[:,0] = W0  #1

count_bankrupt = 0  #2

for sim in range(num_sims):
    spending = spending_0
    for year in range(1, num_years+1):
        # Check whether you run out of money
        next_period_wealth = (W[sim, year-1] - spending) * (1 + ret[sim, year])  #3
        if next_period_wealth < 0:
            count_bankrupt += 1
            break
        else:
            W[sim, year] = next_period_wealth
        spending = spending * (1 + inflation)  #4

plt.xlabel('Year')
plt.ylabel('Wealth')
plt.plot(W[0:10,:].T);  #5

Inspect the complete Python implementation for generating wealth paths, detecting bankruptcy, and plotting sample trajectories. section 5.5

Wealth paths also determine how an allocation policy should respond over time. A dynamic-programming solution evaluates good, medium, and bad paths, showing that optimal stock exposure can decline as wealth advances toward a goal or rise when wealth falls behind. section 6.2.1

How Build a Robo-Advisor with Python (From Scratch) covers it

How deep it goes
Explains array storage, annual wealth updates, bankruptcy counting, plotting, and dynamic-programming transitions, while simplifying returns and spending assumptions.
Examples
Demonstrates thirty-year retirement trajectories and good, medium, and bad wealth paths for goals-based investing.
What it assumes
Assumes familiarity with portfolio returns, spending, probability, and arrays while introducing the trajectory representation through executable examples.
What you can do after
Apply via Python to simulate wealth trajectories, plot sample paths, estimate bankruptcy probability, and evaluate wealth-dependent allocations.
How it connects
Connects Monte Carlo simulation with bankruptcy probability, dynamic programming, transition probabilities, asset allocation, and glide paths.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Robo-Advisor with Python (From Scratch). The section links point to the parts of the book it draws on.