MI DynamicOptimization
MI DynamicOptimization
Josep Pijoan-Mas
1 Introduction
2 Calculus of Variations
1 Introduction
2 Calculus of Variations
Introduction
● Most of the models we will see in Macro I will be set up in continuous time
→ This
This week
week we’ll study the mathematical tools to solve these types of problems
week:
● Then, the solution of a dynamic optimization problem consists of picking, among all
the admissible pairs, the one that maximizes the objective function
– The payoff fctn is the period utility w/ exponential discounting: f (t, yt , xt ) ≡ e−ρt u(ct )
– The law of motion for the state is the resource constraint: k˙t = g(t, xt , yt ) ≡ ktα − δt kt − ct
J. Pijoan-Mas Macroeconomics I (CEMFI 2024-2025) 3/48
Introduction Calculus of Variations Optimal Control Dynamic Programming
ẋt = g(t, xt , yt )
● Yet, the methods are simple, easy to implement, and deliver elegant solutions
Methods
2 Optimal Control
– This method can do everything economists need from calculus of variations, and more
– This will be the most useful method in the deterministic models we will see in the course
– It uses Hamiltonians
1 Introduction
2 Calculus of Variations
Calculus of Variations
● It was developed for a simpler version of problem (1a)-(1d):
T
max W (x) ≡ ∫ f (t, xt , ẋt ) dt (2a)
x 0
subject to xt ∈ X , ∀t ∈ [0, T ] (2b)
x0 = x (2c)
1 Introduction
2 Calculus of Variations
c) (x∗ , y ∗ ) form an admissible pair that is a solution to problem (1a)-(1d); that is:
W (x∗ , y ∗ ) ≥ W (x, y), ∀ admissible pairs (x, y)
∗ ∗
→ It is important that (x , y ) never hits the boundaries and does not have discontinuities
(Not a strong assumption for us as none of the models in this course will have corner solutions)
● Moreover, define the objective function along the admissible variation as:
T
W (ε) ≡ W (x(ε), y(ε)) = ∫ f (t, xt (ε), yt (ε)) dt (3)
0
→ We have transformed the functional W(x, y) into a function W(ε)
● Since (x∗ , y ∗ ) is optimal and (x(ε), y(ε)) is feasible for all ε ∈ [−εη , εη ], then:
● Local optimality requires that W(0) does not change when changing ε slightly:
∂
W(ε)∣ = 0, ∀η (4)
∂ε ε=0
J. Pijoan-Mas Macroeconomics I (CEMFI 2024-2025) 9/48
Introduction Calculus of Variations Optimal Control Dynamic Programming The Variational Argument General Theorems Exponential Discounting A Recipe
● For any continuously differentiable function λ ∶ [0, T ] → R, we can write (3) as:
T
W(ε) = ∫ [f (t, xt (ε), yt (ε)) + λt [g(t, xt (ε), yt (ε)) − ẋt (ε)]] dt (5)
0
● The goal is to obtain the conditions that ensure that the local optimality (4) holds
→ They are the necessary conditions for optimality
● Second, differentiate with respect to ε (use the Leibniz’s and chain rules):
∂W(ε) T ∂ ∂ ∂xt (ε)
= ∫ [ f (t, xt (ε), yt (ε)) + λt g(t, xt (ε), yt (ε)) + λ̇t ] dt
∂ε 0 ∂x ∂x ∂ε
T ∂ ∂ ∂yt (ε)
+ ∫ [ f (t, xt (ε), yt (ε)) + λt g(t, xt (ε), yt (ε)) ] dt
0 ∂y ∂y ∂ε
´¹¹ ¹ ¹ ¹ ¸ ¹ ¹ ¹ ¹ ¹¶
ηt
∂xT (ε)
− λT
∂ε
J. Pijoan-Mas Macroeconomics I (CEMFI 2024-2025) 11/48
Introduction Calculus of Variations Optimal Control Dynamic Programming The Variational Argument General Theorems Exponential Discounting A Recipe
∂W(ε)
∣ = 0, ∀η
∂ε ε=0
∂ ∂
f (t, x∗t , yt∗ ) + λt g(t, x∗t , yt∗ ) = 0 (7a)
∂y ∂y
∂ ∂
λ̇t = − ( f (t, x∗t , yt∗ ) + λt g(t, x∗t , yt∗ )) (7b)
∂x ∂x
(For problems with given terminal condition xT = x, λT = 0 is not needed as ∂xT (0)/∂ε = 0)
● In addition, we have the lof of motion of the state, ẋ∗t = g(t, x∗t , yt∗ )
J. Pijoan-Mas Macroeconomics I (CEMFI 2024-2025) 13/48
Introduction Calculus of Variations Optimal Control Dynamic Programming The Variational Argument General Theorems Exponential Discounting A Recipe
Summing up
– Condition (7a) imposes that yt is chosen such that the marginal increase in the return
function equals the marginal loss due to lowering the state
– Condition (7b) provides the law of motion for the shadow value of the state variable
● What’s missing? → Need to know whether these conditions are also sufficient
The Hamiltonian
● The necessary and sufficient conditions for Problem (1a)-(1d) are encapsulated in
several theorems
● Let’s assume an infinite horizon, T = ∞ (as in all the models we’ll see in this course)
– This requires to impose a lower bound on the (free) terminal condition: lim bt xt ≥ x
t→∞
(for some b ∶ R+ → R with lim bt < ∞, and x < ∞ given)
t→∞
(the case bt = 1 ∀t is perfectly feasible)
Note: this is essentially re-stating the necessary conditions from the variational argument
● They form a system of two differential equations, we need two boundary conditions
– The initial condition x0 = x
– When a terminal condition is not given, we need a Transversality Condition (TVC)
- In many problems limt→∞ λt xt = 0 properly generalizes the case λT = 0
- But more generally, the TVC states that the Hamiltonian evaluated at (x∗ , y ∗ ) satisfies:
lim H(t, x∗t , yt∗ , λt ) = 0
t→∞
Sufficiency Conditions
Mangasarian (1966)
● Assume:
– Problem (1a)-(1d) has an interior solution, (x∗t , yt∗ ) ∈ int(X × Y) ∀t
– (x∗ , y ∗ ) satisfies Pontryagin’s necessary conditions, (8a)-(8c)
Sufficiency Conditions
Arrow (1968)
● Given the costate function λ ∶ R+ → R, define the maximized Hamiltonian as:
M(t, xt , λt ) ≡ max H(t, xt , yt , λt )
yt ∈Y
● Assume:
– Problem (1a)-(1d) has an interior solution, (x∗t , yt∗ ) ∈ int(X × Y) ∀t
– (x∗ , y ∗ ) satisfies Pontryagin’s necessary conditions, (8a)-(8c)
Sufficiency Conditions
Comments
● Arrow’s (1968) theorem is more general than Mangasarian’s (1966)
(Mangasarian ⇒ Arrow)
– This is because if a function H(t, x, y, λ) is jointly (strictly) concave in (x, y), then
M(t, x, λ) ≡ maxy H(t, x, y, λ) is (strictly) concave in x
– But in typical econ problems, it is harder to verify Arrow’s conditions than Mangasarian’s
- It is easy to check for concavity in H, not so much in M
– For example, as H = f + λg :
- Mangasarian’s sufficiency follows if both f and g are concave in (xt , yt ), provided λt ≥ 0
- The condition that λt ≥ 0 everywhere, in turn, is typically guaranteed
∂ ∂
(For instance, if f (t, x∗t , yt∗ , λt ) ≥ 0 and g(t, x∗t , yt∗ , λt ) ≤ 0, then λt ≥ 0 )
∂y ∂y
J. Pijoan-Mas Macroeconomics I (CEMFI 2024-2025) 20/48
Introduction Calculus of Variations Optimal Control Dynamic Programming The Variational Argument General Theorems Exponential Discounting A Recipe
Extensions
● Multidimensional problems
– The Maximum Principle and Mangasarian and Arrow sufficiency conditions also apply
- We have Ky (8a) conditions and Kx (8b)-(8c) conditions
● Discontinuous controls
– The Maximum Principle and Mangasarian and Arrow sufficiency conditions only apply
whenever y ∗ is a continuous function of time
– Pontryagin provided generalizations where the control is allowed to have discontinuities
– Discontinuous solutions are rare cases in macroeconomics w/ RA, so we will ignore this
Discounting
● So far, we have not talked about a key object in economics: time discounting
– In previous slides, discounting entered implicitly in the payoff function f (t, xt , yt )
– t indicates how the return function changes over time for given values of xt and yt
● One type of discounting that elicits this type of behavior is exponential discounting
– This is the analogue of proportional discounting in discrete time
– We will have a “discount rate”, ρ ∈ (0, ∞), instead of a “discount factor”, β ∈ (0, 1)
● Technical note:
Technical note:
– Exponential discounting is necessary, but not sufficient, to get time consistency
– For that, we also need a time-autonomous constraint, i.e. g(xt , yt ) and not g(t, xt , yt )
● Let’s partition time [0, T ] into T /∆t equally spaced discrete subintervals of length ∆t
– For each sub-period of length ∆t, the discount factor is ρ∆t
● With exponential discounting, and from a time-0 perspective, we can write the payoff
function as follows:
f (t, xt , yt ) ≡ e−ρt f (xt , yt )
● Hence, the canonical problem w/ exponential discounting and infinite horizon is:
∞
max W (x, y) ≡ ∫ e−ρt f (xt , yt ) dt (9a)
x,y 0
subject to ẋt = g(t, xt , yt ) (9b)
yt ∈ Y, xt ∈ X , ∀t ∈ R+ (9c)
x0 = x given, and lim bt xt ≥ x (9d)
t→∞
● The term in square brackets is called the current-value Hamiltonian (denoted w/ hat):
̂ xt , yt , µt ) ≡ f (xt , yt ) + µt g(t, xt , yt )
H(t,
● We can re-work our theorems so they can be used for the current-value Hamiltonian
∂ ̂
H(t, x∗t , yt∗ , µt ) = 0 (10a)
∂y
∂ ̂
H(t, x∗t , yt∗ , µt ) = ρµt − µ̇t (10b)
∂x
∂ ̂
H(t, x∗t , yt∗ , µt ) = ẋt (10c)
∂µ
̂ x∗t , yt∗ , µt ) = 0
lim e−ρt H(t, (10d)
t→∞
[continued]
● Moreover, suppose:
1 f (xt , yt ) is weakly monotone in (xt , yt ), and g(t, xt , yt ) is weakly monotone in
(t, xt , yt ).
2 ∃m > 0 s.t. ∣ ∂y
∂
g(t, xt , yt )∣ ≥ m, for all admissible pairs (xt , yt ).
3 ∃M < ∞ s.t. ∣ ∂y
∂
f (xt , yt )∣ ≤ M , ∀(x, y).
∗ ẋt
4 Either lim xt < ∞ or lim ( ) < ∞.
t→∞ t→∞ x∗t
● The Maximum Principle with exponential discounting is similar to the general one
A recipe
Suppose Problem (9a)-(9d) with exponential discounting and infinite time horizon has an interior
solution (x∗ , y ∗ ), and conditions (1)-(4) of Theorem 4 hold. We characterize the solution as follows:
Present-value Hamiltonian
Present-value Hamiltonian Current-value Hamiltonian
Current-value Hamiltonian
∂ ∂ ̂
H(t, x∗t , yt∗ , λt ) = 0 H(t, x∗t , yt∗ , µt ) = 0
∂y ∂y
∂ ∂ ̂
H(t, x∗t , yt∗ , λt ) = − λ̇t H(t, x∗t , yt∗ , µt ) = ρµt − µ̇t
∂x ∂x
∂ ∂ ̂
H(t, x∗t , yt∗ , λt ) = ẋt H(t, x∗t , yt∗ , µt ) = ẋt
∂λ ∂µ
lim λt x∗t = 0 lim e−ρt µt x∗t = 0
t→∞ t→∞
1 Introduction
2 Calculus of Variations
● In deterministic models, the tools provided by optimal control theory are great
(by “deterministic models” we mean models without uncertainty: no shocks)
● However, the recursive formulation is very useful when dealing with stochastic models
(by “stochastic models” we mean models with uncertainty: shocks)
● More generally we can define Vτ (xτ ) as the optimal value at time 0 of the problem
starting at time τ with some state xτ
J. Pijoan-Mas Macroeconomics I (CEMFI 2024-2025) 31/48
Introduction Calculus of Variations Optimal Control Dynamic Programming Deterministic Case Stochastic Case
● Then, we have:
t
V0 (x0 ) = ∫ f (s, x∗s , ys∗ ) ds + Vt (x∗t ) , ∀t ≥ 0 (14)
0 ´¹¹ ¹ ¹ ¸¹¹ ¹ ¹ ¶
continuation value
Interpretation:
● The optimal sequence (x∗ , y ∗ ) has the property that, at any time t ≥ 0, the
subsequence (x∗s , ys∗ ∶ s ≥ t) is also the solution of the time-0 planner to the
optimization problem starting at time t with initial state x∗t
● Now, take Problem (13a)-(13d) and split the objective function (13a) into two stages
⎧ ⎫
⎪ t
⎪ ∞ ⎪
⎪
V0 (x0 ) = max ⎨ ∫ f (s, xs , ys ) ds + max ∫ f (s, xs , ys ) ds ⎬
(xs ,ys ∶s∈[0,t)) ⎪
⎪ 0 (xs ,ys ∶s≥t) t ⎪
⎪
⎩ ´¹¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¸¹¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¶ ⎭
Vt (xt )
where Vt (xt ) is the value today of the continuation problem at time t with state xt resulting from the
optimal choices (x∗ ∗
s , ys ∶ s ∈ [0, t]) and the law of motion (13b)
⇒ We have made the problem recursive, i.e. “break it down” into smaller subproblems
● The HJB is the time derivative of the recursive representation of the value function
→ The principle of optimality states that the choice of the optimal pair (x∗ , y ∗ ) is independent
from the time t at which we partition the problem into two.
⇒ Hence, the optimal pair (x∗ , y ∗ ) must satisfy that when increasing t, the gain in terms of the
return function f (t, x∗t , yt∗ ) must equal the loss in terms of the continuation value, which is
∂Vt (x∗
t)
given by the direct effect of the passage of time ∂t
plus the effect due to the change in
∂Vt (x∗
t)
the state, ∂xt
ẋt
● Let us focus on the type of problem that will be most common in this course:
1 Exponential discounting, i.e. f (t, xt , yt ) = e−ρt f (xt , yt )
2 Time-autonomous constraint, i.e. ẋt = g(xt , yt ) instead of ẋt = g(t, xt , yt )
Most (if not all) of the problems we see in this course will be of this type
Time consistency
● That is, the planner does not gain anything from revising the plan at any future date
(What was optimal at time t′ from the perspective of time t is still optimal when arriving at time t′ )
● Time-consistent problems are much more straightforward to work with and satisfy all
the standard axioms of rational decision-making.
● Equation (18), or some form of it, is ubiquitous in (continuous-time) macro and finance
J. Pijoan-Mas Macroeconomics I (CEMFI 2024-2025) 38/48
Introduction Calculus of Variations Optimal Control Dynamic Programming Deterministic Case Stochastic Case
Note that the object to be maximized is the current value Hamiltonian when µt = vx (xt )
– We will see some such examples in Topic IV of the course (endogenous growth)
(With uncertainty coming from the assumption that R&D does not always succeed)
(Wiener processes are NOT part of the material for this course)
Def. A counting process is a stochastic process (Nt ∶ t ∈ R+ ) that records the number of events
(or “arrivals”) that occurred within some interval (0, t], and that satisfies the following
properties:
1 Nt ∈ Z+ ≡ N ∪ {0}, i.e. Nt must be a non-negative integer number
2 ∀t ≥ s, Nt ≥ Ns , i.e. events do not “disappear”
3 ∀t > s, Nt − Ns denotes the number of arrivals within the interval (s, t]
(α∆)m e−α∆
Pr[Nt+∆ − Nt = m] = , for any ∆ ≥ 0
m!
which has mean E [Nt+∆ − Nt ] = α∆
(Hence, the average number of events increases with the length ∆ of the time interval and with the parameter α defining
the rate of arrival of events)
● Rates. We can also express these probabilities in rates per unit of time
– Pr[N∆ = 0]/∆ = o(∆)/∆ + 1/∆ − α
– Pr[N∆ = 1]/∆ = o(∆)/∆ + α
– Pr[N∆ ≥ 2]/∆ = o(∆)/∆
– The length of time without events does not predict the occurrence of the next one
(So buses arriving at a bus stop are probably not Poisson)
2 The distribution for the length of time periods between arrivals is exponential:
– Let {tn }∞
n=1 be the sequence of interarrival times.
(times elapsed between consecutive arrivals, i.e., points in time at which a worker gets a job offer)
– Then, {tn }∞
n=1 are identically distributed exponential random variables with mean 1/α:
−αt
Pr[tn ≤ t∣{tj }j=1 ] = 1 − e ∀n ∈ Z+ , ∀t > tn−1
n−1
,
● Let’s derive the HJB equation of this stochastic problem following a different procedure
J. Pijoan-Mas Macroeconomics I (CEMFI 2024-2025) 46/48
Introduction Calculus of Variations Optimal Control Dynamic Programming Deterministic Case Stochastic Case
● Divide both sides by ∆, take the limit as ∆ → 0, and write it all at time t:
∂v(at )
ρv(at ) = max {u(ct ) + ȧt + δ (v(0) − v(at )) }
ct >0 ∂at ´¹¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¸¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¹ ¶
change in value due
to bankruptcy shock
● A particular form of this HJB equation is when the problem is such that v(0) = 0:
∂v(at )
(ρ + δ)v(at ) = max {u(ct ) + ȧt }
ct >0 ∂at
(the effective discount is given by the time discount ρ plus the probability disocunt δ , as at the stochastic rate δ the value
function goes to zero)