liveBook · Manning

Budget constraint

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

A budget constraint is an equation or inequality limiting feasible spending and investment choices according to available resources.

A budget constraint limits consumption and investment by defining how wealth evolves: next-period wealth equals current wealth minus consumption, multiplied by investment returns. The formulation supports numerical optimization of discounted consumption utility over asset allocation and spending decisions. section 6.3.2

Spending and investment over time

With initial wealth of 1,000,000 over ten periods, the model chooses stock allocation and consumption percentage at each wealth–time state. Consumption reduces investable wealth before stock and bond returns apply; labor income can be added to the constraint. section 6.3.2

Listing 6.8 DP solution for the spending example
nA = 11
nC = 40
V = np.zeros((nW, T+1))
A = np.zeros((nW, T))
C = np.zeros((nW, T))  #1
EV = np.zeros((nA, nC))
W_midpts = compute_midpoints(W)

gamma = 0.95  #2
CRRA = 3  #3
def utility(c):  #4
    if (CRRA == 1):
        util = log(c)
    else:
        util = (c**(1-CRRA))/(1-CRRA)
    return util

for j in range(nW):
        V[j, T] = utility(W[j,T])  #5
        
for t in range(T-1, -1, -1):
    for j in range(nW):
        for a in range(nA):
            for c in range(nC):
                cons = (c+1)/(1.5*nC)*W[j,t]  #6
               
                W_tplus1_dist = compute_transition_probs(W[j,t]-cons, t,  #7
                 a W_midpts) 
               
                EV[a,c] = np.dot(W_tplus1_dist, utility(cons)+gamma*V[:,t+1])  #8
        V[j,t] = EV.max()
        A[j,t], C[j,t] = np.unravel_index(EV.argmax(), EV.shape)  #9

The implementation enumerates wealth states, asset allocations, and forty consumption levels, then selects actions using dynamic programming and utility values. section 6.3.2

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

How deep it goes
Defines wealth evolution and implements it through dynamic programming and Q-learning over discretized consumption and allocation actions.
Examples
Uses a ten-period, 1,000,000-wealth scenario with stock and bond returns and forty discretized consumption levels.
What it assumes
Assumes concepts of wealth, consumption, asset allocation, investment returns, utility, and discounted rewards.
What you can do after
Build a numerical spending policy that balances consumption utility against future wealth through discretized asset and consumption choices.
How it connects
Connects consumption, utility functions, asset allocation, investment returns, dynamic programming, and reinforcement learning.

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.