10 Optimization with Continuous Choices
This section studies continuous optimization problems under constraints, with applications to profit maximization, utility choice, and intertemporal allocation.
10.1 Karush-Kuhn-Tucker (KKT) Conditions for Constrained Optimization
10.1.1 Equality constrained optimization
Let \(f:\mathbb{R}^n\to\mathbb{R}\) and \(g:\mathbb{R}^n\to\mathbb{R}^m\) be continuously differentiable, and consider the equality-constrained maximization problem:
\[\begin{align} \max_{x} & \quad f(x) \\ \text{subject to} & \quad g(x) = c \end{align}\]
We combine the constraint into the objective function using a Lagrange multiplier \(\lambda \in R^m\), and form the lagrangian:
\[ \mathcal{L}(x, \lambda) = f(x) - \lambda^T (g(x) - c) \]
At a local optimum \(x^\ast\), the first-order condition is
\[ \nabla_x \mathcal{L}(x^{\ast},\lambda^{\ast})=0, \qquad g(x^{\ast})=c. \]
These conditions are necessary under a suitable constraint qualification, such as full row rank of the equality-constraint Jacobian at \(x^\ast\). They are not sufficient for a maximum in a general nonconcave problem.
The multiplier converts the constrained problem into a Lagrangian first-order system; it does not by itself guarantee that a candidate is an optimum.
10.1.2 Inequality constrained optimization
For the inequality-constrained problem
\[\begin{align} \max_{x} & \quad f(x) \\ \text{subject to} & \quad g(x) \le c \end{align}\]
We combine the constraint into the objective function using a Lagrange multiplier \(\lambda \in R^m\), and form the lagrangian:
\[ \mathcal{L}(x, \lambda) = f(x) - \lambda^T (g(x) - c) \]
the KKT conditions at a candidate \((x^\ast,\lambda^\ast)\) are:
\[ \nabla_x \mathcal{L}(x^{\ast},\lambda^{\ast}) = 0 \]
\[ g(x^{\ast}) \le c \]
\[ \lambda^{\ast} \ge 0 \]
\[ \left(\lambda^{\ast}\right)^T (g(x^{\ast}) - c) = 0 \]
For a local maximum, these conditions are necessary under a constraint qualification (for example, the linear independence constraint qualification). They express stationarity, feasibility, multiplier sign, and complementary slackness, respectively.
Note that we can express the gradient of the Lagrangian with respect to \(x\) as:
\[\begin{align} \nabla_x \mathcal{L}(x^{\ast},\lambda^{\ast}) &= 0 \\ \nabla_x f(x^{\ast}) - J_g(x^{\ast})^T \lambda^{\ast} &= 0 \\ \nabla_x f(x^{\ast}) &= J_g(x^{\ast})^T \lambda^{\ast} \end{align}\]
where \(J_g(x^{\ast})\) is the Jacobian matrix of the constraint function \(g\) evaluated at \(x^{\ast}\).
Equality constraints can also be represented by two inequalities, \(g(x)\le c\) and \(-g(x)\le -c\), though it is often clearer to retain their unrestricted multipliers explicitly. KKT conditions are sufficient for a global maximum when the objective is concave, the inequality constraint functions are convex, and any equality constraints are affine. Without such conditions, KKT candidates must be checked further.
10.2 The perpetual bond problem
10.2.1 The perpetual bond problem
An individual receives \(y_1\) units of income in period 1, and \(y_f\) units of income in all future periods. In each period, consumption is \(c_t\). In period 1, the individual makes a once-in-a-life time decision on investing in a perpetual bond \(b\) that will return \(r\) units of interest in all future periods. The individual can not borrow.
Assume \(0<\beta<1\), \(y_1>0\), \(y_f>0\), and \(r>0\). Given log utility:
\[ U(c_1, c_f) = \log(c_1) + \sum_{t=1}^{\infty} \beta^{t} \log(c_f) \\ \]
where \(\beta\) is the discount factor, which is less than 1. The life-time consumption and bond optimization problem can be formulated as:
\[ \max_{c_1, c_f, b} \quad U(c_1, c_f) \\ \]
subject to:
\[\begin{align*} c_1 + b &\le y_1 \\ c_f &\le y_f + r b\\ c_1, c_f & > 0\\ b &\ge 0 \end{align*}\]
10.2.2 The perpetual bond problem, from constrained to unconstrained
Often, a way to solve a constrained optimization problem with many constraints and choices is to substitute the constraints into the objective function, and then solve the resulting unconstrained optimization problem. We have an example here where we can easily turn the problem into an almost unconstrained optimization problem.
First, given log utility, we know that the two budget constraints will bind at the optimum, so we can substitute them into the objective function and replace \(c_1\) and \(c_f\). The reduced choice set is \(0 \leq b < y_1\): the upper bound ensures \(c_1>0\) and is also required for the logarithm to be defined. The optimization problem is only with respect to \(b\):
\[ \max_{b} \quad U(y_1 - b, y_f + r b) \\ \text{subject to} \quad -b \le 0 \]
We are left with a single constraint and a single choice. Note that we converted our constraint so that it is in the form of \(g(x) \le c\). We have the Lagrangian:
\[ \mathcal{L}(b, \lambda) = \log(y_1 - b) + \frac{\beta}{1 - \beta} \log(y_f + r b) - \lambda (-b) \]
where \(\lambda\) is the lagrange multiplier.
10.2.3 Single constraint KKT condition check
Given the lagrangian above, we can write out the KKT conditions for this problem. Then we walk through alternative paths of lagrange multiplier values to explore, at optimal choices, whether the constraint is binding. We are dealing with a one choice and one constraint problem here, but the condition checking below is already somewhat long. KKT-based condition checking is a very powerful way of solving problems, but should be best left for a computer to execute.
The KKT conditions are:
\[ \begin{gathered} (C1)\quad \frac{\partial \mathcal{L}}{\partial b} = -\frac{1}{y_1 - b^{\ast}} + \frac{\beta r}{(1 - \beta)(y_f + r b^{\ast})} + \lambda^{\ast} = 0\\ (C2)\quad b^{\ast} \geq 0\\ (C3)\quad \lambda^{\ast} \geq 0\\ (C4)\quad \lambda^{\ast} b^{\ast} = 0 \end{gathered} \]
There are two possible paths. Along the first path, suppose that \(\lambda^{\ast} >0\) (C3), then by C4, we must have \(b^{\ast} = 0\), which satisfy C2 as well. The individual does not invest in the bond at all. Then using \(C1\), we have:
\[\begin{align} 0 &< \lambda^{\ast} = \frac{1}{y_1} - \frac{\beta r}{(1 - \beta)(y_f)}\\ 0 &< \frac{1}{y_1} - \frac{\beta r}{(1 - \beta)(y_f)}\\ \end{align}\]
which becomes:
\[\begin{align} \left(\frac{\beta }{1 - \beta}\right) r &< \frac{y_f}{y_1}\\ \end{align}\]
If the condition above is satisfied, then the this first path provides the optimal choice, which is not to buy the perpetual bond. The condition is more likely to be satisfied if there is relative more income in each future period than in period 1, which should reduce the incentive to save via bond. The condition is more likely to be satisfied if interest rate is lower, which should reduce the incentive to save via bond. The condition is more likely to be satisfied if the discount factor is lower, which should reduce the incentive to save via bond (when \(\beta\) is zero, the left-hand-side is zero).
Note here the importance of setting the constraint as \(-b \le 0\) when constructing the lagrangian. If we plugged into the lagrangia \(-\lambda b\) (rather than \(-\lambda (-b)\)), the inequality would have have been reversed, with wrong comparative statics implications.
Consider now the second path, where \(\lambda^{\ast} = 0\) (C3), which satisfies (C4). Then using \(C1\), we have the first order condition from the unconstrained problem without the lagrange multiplier term:
\[ \frac{1}{y_1 - b^{\ast}} = \frac{\beta r}{(1 - \beta)(y_f + r b^{\ast})} \]
Solving for \(b^{\ast}\), we cross multiply and rearrange to get:
\[\begin{align} (1-\beta)y_f + (1-\beta)r b^{\ast} &= \beta r y_1 - \beta r b^{\ast} \\ % (1-\beta)y_f + (1-\beta + \beta)r b^{\ast} &= \beta r y_1 \\ (1-\beta)y_f + r b^{\ast} &= \beta r y_1 \\ % b^{\ast} &= \frac{\beta r y_1 - (1-\beta)y_f}{r}\\ b^{\ast} &= \beta y_1 - \frac{(1-\beta)}{r}y_f \end{align}\]
By C2, we must have \(b^{\ast} \geq 0\), which means that:
\[\begin{align} \beta y_1 - \frac{(1-\beta)}{r}y_f &\geq 0\\ \frac{\beta}{1-\beta}r \ge \frac{y_f}{y_1} \end{align}\]
Note that this condition here is exactly the opposite of the condition we derived in the first path. If this condition is satisfied, then the second path provides the optimal choice, which is to invest positive levels in \(b^{\ast}\).
Generally, for single constraint and single choice optimization problem, we don’t have to go through the KKT conditions, the solution can be written as the optimal constrained b choice is equal to the optimal unconstrained choice, if the unconstrained choice would have be positive, and zero otherwise. Specifically, we can write the optimal choice as:
\[\begin{align} b^{\ast} &= \max\left(0, \beta y_1 - \frac{(1-\beta)}{r}y_f\right)\\ \end{align}\]
or
\[ b^{\ast, con} = \begin{cases} b^{\ast, unc} & \text{if } b^{\ast, unc} > 0 \\ 0 & \text{otherwise } \end{cases} \quad \]
10.2.4 The perpetual bond problem, gradients with 3 choices and five constraints
The original problem has three choices and five inequality constraints. Solving this as a constrained optimization problem, we can use the KKT conditions.
First, let \(x=[c_1, c_f, b]\) by a 3 by 1 vector.
Second we rewrite the constraints so that they are all less than or equal to a constant:
\[\begin{align*} g_1(x) = c_1 + b &\le y_1 \\ g_2(x) = c_f - r b &\le y_f \\ g_3(x) = -c_1 & \le 0\\ g_4(x) = -c_f & \le 0\\ g_5(x) = -b &\le 0 \end{align*}\]
Third, we are dealing with linear constraints, so the Jacobian is just the coefficients in front of the elements of \(x\). The Jacobian of the constraints \(g(x)\) with respect to \(x\) is a 5 by 3 matrix:
\[ J_g(x) = \begin{bmatrix} 1 & 0 & 1 \\ 0 & 1 & -r \\ -1 & 0 & 0 \\ 0 & -1 & 0 \\ 0 & 0 & -1 \end{bmatrix} \]
Fourth, using properties geometric series, we can rewrite the objective function as:
\[ f(x) = U(c_1,c_f) = \log(c_1) + \frac{\beta}{1 - \beta} \log(c_f) \]
And the gradient of the scalar-valued function \(f\) with respect to \(x\) is:
\[ \nabla f(x) = \begin{bmatrix} \frac{1}{c_1} \\ \frac{\beta}{(1 - \beta)c_f} \\ 0 \end{bmatrix} \]
Fifth, note that our for KKT, we need to satisfy the following conditions:
\[ \begin{gathered} \nabla_x f(x^{\ast}) = J_g(x^{\ast})^T \lambda^{\ast}\\ \left(\lambda^{\ast}\right)^T (g(x^{\ast}) - c) = 0\\ \lambda^{\ast} \ge 0\\ g(x^{\ast}) \le c \end{gathered} \]
We can begin working on this, trying out alternative values of the lagrange multipliers and test out whether they could plausibly jointly satisfy all four sets of equations above. This can be a very cumbersome process, although the problem we are dealing with here is fairly simple.
10.2.5 The perpetual bond problem, inputs for constrained optimization solver
Rather than solving out the tree of possibilities by hand. Programs like matlab are designed to solve exactly this type of problems. Matlab requires several inputs:
- the utility objective function
- the jacobian
- the vector of values that \(g(x)\) is less than
- starting value guess for the three choices.
Given our set up, we now create matlab code that uses the matlab function fmincon to solve this constrained optimization problem. The code should define the objective function, the constraints, and call fmincon to find the optimal solution.
% Parameters
y1 = 10; % Income in period 1
yf = 5; % Income in future periods
r = 0.1; % Interest from bond
beta = 0.95; % Discount factor
% Objective function
f = @(x) -(log(x(1)) + (beta/(1-beta))*log(x(2))); % Negative for minimization
% Inequality constraints: A*x <= b
A = [1 0 1; % c1 + b <= y1
0 1 -r; % c_f - r*b <= y_f
-1 0 0; % -c1 <= 0
0 -1 0; % -c_f <= 0
0 0 -1]; % -b <= 0
b_vec = [y1; yf; 0; 0; 0];
% Initial guess
x0 = [1; 1; 1];
% Call fmincon
options = optimoptions('fmincon', 'Display', 'iter', 'Algorithm', 'interior-point');
[x_opt, fval, exitflag, output] = fmincon(f, x0, A, b_vec, [], [], [], [], [], options);
% Display results
c1_opt = x_opt(1);
cf_opt = x_opt(2);
b_opt = x_opt(3);
fprintf('Optimal c1: %.4f\nOptimal cf: %.4f\nOptimal b: %.4f\n', c1_opt, cf_opt, b_opt);10.3 Finite horizon deterministic income and consumption paths
We illustrate below writing the same problem as a problem with multiple constraint, a single constraint, and no constraint.
10.3.1 Many constraints
Assume \(0<\beta<1\) and a gross risk-free return \(1+r>0\). Individuals solve an optimal consumption and risk-free asset problem over a finite horizon of \(T\) periods, where they receive income \(y_t\) in each period \(t\) and choose consumption \(c_t\) and savings \(a_t\). Given period utility \(u(c_t)\), the problem can be written as:
\[\begin{align} \max_{\{c_t\}_{t=1}^T, \left\{a_t\right\}_{t=2}^T} \quad & \sum_{t=1}^{T} \beta^{t-1} u(c_t) \\ \end{align}\]
subject to the following constraints:
\[\begin{align} c_t + a_{t+1} &\le y_t + (1+r) a_t \quad \forall t\\ c_t &\ge 0 \quad \forall t\\ \end{align}\]
where \(a_1 = 0\) and \(a_{T+1} = 0\). There are \(T+T-1\) choices and \(2T\) constraints.
If utility is strictly increasing in consumption, then resource constraints will bind. If marginal utility approaches infinity as consumption approaches zero, then the non-negativity constraints on consumption will not bind. This eliminates the inequality constraints.
\[\begin{align} \max_{\{c_t\}_{t=1}^T, \left\{a_t\right\}_{t=2}^T} \quad & \sum_{t=1}^{T} \beta^{t-1} u(c_t) \\ \end{align}\]
subject to the following constraints:
\[\begin{align} c_t + a_{t+1} &= y_t + (1+r) a_t \quad \forall t\\ \end{align}\]
10.3.2 No constraint
Building on the assumptions just made, we can now replace consumption as a function of the savings choices.
The problem can be written as:
\[\begin{align} \max_{\left\{a_t\right\}_{t=2}^T} \quad & \sum_{t=1}^{T} \beta^{t-1} u\left( y_t + (1+r) a_t - a_{t+1} \right) \\ \end{align}\]
10.3.3 Single constraint
We can also combine the budgets together. This a problem where one could borrow or save freely in each period.
We combine the first and second periods’s budget constraints to get:
\[ c_2 + a_3 = y_2 + (1+r) (y_1 - c_1) \]
Combining the above result into the budget for period 3, we have:
\[\begin{align} c_3 + a_4 &= y_3 + (1+r) (y_2 + (1+r) (y_1 - c_1) - c_2)\\ c_3 + (1+r) c_2 + (1+r)^2 c_1 &= y_3 + (1+r) y_2 + (1+r)^2 y_1 \end{align}\]
Combining all constraints, we have the following single constraint for the entire problem:
\[ \sum_{t=1}^{T} (1+r)^{T-t} c_t = \sum_{t=1}^{T} (1+r)^{T-t} y_t \]
The utility maximization problem can be written as:
\[\begin{align} \max_{\{c_t\}_{t=1}^T} \quad & \sum_{t=1}^{T} \beta^{t-1} u(c_t) \\ \end{align}\]
subject to the following single constraint just formulated.
The lagrangian for this problem is:
\[ L(c_1, c_2, \ldots, c_T, \lambda) = \sum_{t=1}^{T} \beta^{t-1} u(c_t) + \lambda \left( \sum_{t=1}^{T} (1+r)^{T-t} y_t - \sum_{t=1}^{T} (1+r)^{T-t} c_t \right) \]
Suppose the utility function is continuously differentiable in consumption, then the derivative of the lagrangian with respect to each consumption choice is:
\[ \frac{\partial L}{\partial c_t} = \beta^{t-1} u'(c_t) - \lambda (1+r)^{T-t} = 0 \]
Using the derivative with respect to \(c_t\) and \(c_{t+1}\), we can eliminate the lagrange multiplier, and arrive at the marginal relative intertemporal utility result:
\[\begin{align} \frac{\beta^{t-1} u'(c_t)}{\left(1+r\right)^{T-t}} &= \frac{\beta^{t} u'(c_{t+1})}{\left(1+r\right)^{T-t-1}}\\ \frac{\beta^{-1} u'(c_t)}{1} &= (1+r) u'(c_{t+1})\\ \frac{u'(c_t)}{u'(c_{t+1})} &= \beta (1+r) \end{align}\]
This is the standard Euler equation for consumption smoothing over time, which states that the marginal utility of consumption today relative to the marginal utility of consumption tomorrow is equal to the product of the discount factor and one plus the interest rate.