Lec 3 A Review of Optimization Methods20180827013351
Lec 3 A Review of Optimization Methods20180827013351
August 2018
Outline of the Course
Lectures 1 and 2 (3 hours, in class):
Linear and non-linear functions on
Limits, continuity, differentiability, rules to compute
derivatives, approximation with differentials
Logarithmic and exponential functions
Introduction to integration
Lecture 3 (1.5 hours, in the lab):
Review of matrix algebra with applications in excel
Lectures 4 and 5 (3 hours, 1.5 of which in the lab):
Introduction to optimization: functions of one variable
Generalization: functions of several variables
Use of Excel Solver to tackle constrained optimization
2
A Review of Optimization Methods
Optimization: Statement of the Problem (1/2)
Optimization == maximizing (or minimizing) some objective
function, y = f(x), by picking one or more appropriate values of
the control (aka choice) variable x
The most common criterion of choice among alternatives in
economics (and finance) is the goal of maximizing something
(like the profit of a firm) or minimizing something (like costs or
risks)
For instance, think of a risk-averse investor who wants to
maximize a mean-variance objective by picking an
appropriate set of portfolio weights
Maxima and minima are also called extrema and may be
relative (or local, that is, they represent an extremum in the
neighborhood of the point only) or global
Key assumption: f(x) is n times continuously differentiable
3
A Review of Optimization Methods
Optimization: Statement of the Problem (2/2)
In the leftmost graph, optimization is trivial: the function is a
constant and as such all points are at the same time maxima
and minima, in a relative sense
In the second plot, f(x) is monotonically increasing, there is no
finite maximum, if the set of nonnegative real numbers is the
domain (as the picture implies)
The points E and F on the right are examples of a relative
(local) extrema
A function can well have several relative extrema, some of
which may be maxima while others are minima
4
A Review of Optimization Methods
Candidate points: The First-Derivative Test (1/2)
As a first step we want to identify the “candidate” points to solve
the optimization problem, i.e., all the local extrema
Indeed, global extrema must also be local extrema or end points
of f(x) on its domain
• If we know all the relative maxima, it is necessary only to select the
largest of these and compare it with the end points in order to
determine the absolute maximum
Key Result 1 (First-Derivative Test): If a relative extremum of the
function occurs at x = x0, then either f'(x0) = 0, or f'(x0) does not
exist; this is a necessary condition (but NOT sufficient)
5
A Review of Optimization Methods
Candidate points: The First-Derivative Test (2/2)
Key Result 1 Qualified: If f’(x0) = 0 then the value of f(x0) will be:
(a) A relative maximum if the derivative f'(x) changes its sign
from > 0 to <0 from the immediate left of the point x0 to its
immediate right
(b) A relative minimum if f'(x) changes its sign from negative
to positive from the immediate left of x0 to its immediate right
(c) Neither a relative maximum nor a relative minimum if f'(x)
has the same sign on both the immediate left and right of point
x0 (inflection point)
NOTE: we are assuming that the function
is continuous and possesses continuous
derivatives => for smooth functions,
relative extreme points can occur only
when the first derivative has a zero value Inflection point
6
A Review of Optimization Methods
One Example
7
A Review of Optimization Methods
Concavity, Convexity, and Second-Order Derivatives
A strictly concave (convex)
function is such that if we pick any
pair of points M and N on the
function and join them by a Inflection point
straight line, the line segment MN
Concave Convex
must lie entirely below (above)
the curve, except at points M and
N
if the limits exists. Only the ith variable changes, while the others
stay constant
𝐱𝟎
13
A Review of Optimization Methods
Second Order Derivatives and Hessians (1/2)
If the n partial derivative functions of f are continuous
functions at the point in we say that f is continuously
differentiable at
If all the n partial derivatives are themselves
differentiable we can compute their partial derivatives
; ;
Hessian matrix is
16
A Review of Optimization Methods
Optimization: the case of n-variable functions
Now we are ready to generalize optimization to the case of n-
variable functions
The strategy remains looking for critical points (relative
extrema) and then try to isolate global ones among them
is a critical point for f if it fulfills
,
which means that
( , for each i
3𝑥 3𝑦 0
Solving that is non-trivial and time consuming
You get three critical points:
A(0,0); B( , ; C( , )
Step 2: compute the Hessian matrix
36𝑥 6𝑦 6𝑥
𝐷 𝑓
6𝑥 6𝑦
We need to check it at A, B, and C
21
A Review of Optimization Methods
Example of Unconstrained Optimization (2/2)
As an example, I will only check the sign of the Hessian at
C( )
9 3 3 6 3
𝐷 𝑓
3 3 3 3
𝐴 6 0
𝐴 6𝑥3 3 3 9 0
Then the Hessian matrix is positive definite and the point is a local
minimum
This is an easy problem and yet you see how computationally intense
it is
Sometimes the solution shall ben find numerically anyway
Things get even worse when we introduce constraints (equality
constraints, inequality constraints or both)
We shall now introduce Excel solver
22
A Review of Optimization Methods
Excel Solver (1/3)
The Solver is an analysis tool available as an additional package
into Excel
If you do not have it already installed in your Excel you can
download it as Excel add-in from the Excel options
Once you have installed it, you find it under the tab “Data”
The Solver is able to solve optimization problems for you (even
with a number of equality/inequality constraints, as we shall
see later on)
Essentially, it maximizes (minimizes) the value obtained into an
objective cell in which you have to specify a certain function…
…by changing a set of cells (control variables) that you specify
elsewhere as an array in the worksheet
23
A Review of Optimization Methods
Excel Solver (2/3)
OBJECTIVE FUNCTION:
In the cell A6 write a value (almost whatever) for x and in
B6 write a value for y
The values are only used to initialize the search (in some
situations it may matter where you initialize the search, but
typically the nature of the problem that you are solving
suggests reasonable values)
For instance, when finding optimal weights for a
portfolio I typically start from equal weights
Then write the functions f
into the cell C6
24
A Review of Optimization Methods
Excel Solver (3/3)
Now open the Solver:
OBJECTIVE CELL
Choose if you
want to look
CONTROLS
for a min or
for a max
For now we
are not
putting
constraints
SOLVE IT
25
A Review of Optimization Methods
Hints of Constrained Optimization (1/2)
Up to these points, all control variables have been independent
of each other: the decision made regarding one variable does
not impinge upon the choices of the remaining variables
• E.g., a two-product firm can choose any value for Q1 and any Q2 it
wishes, without the two choices limiting each other
• If the firm in the example is somehow required to fulfill a restri-
ction (e.g., a production quota) in the form of Q1 + Q2 = k, how-
ever, the independence between the choice variables will be lost
• The new optimum satisfying
the production quota constitu-
tes a constrained optimum, which,
in general, may be expected to
differ from the free optimum
Key Result : A constrained maxi-
mum can never exceed the free
maximum
26
A Review of Optimization Methods
Hints of Constrained Optimization (2/2)
In general, a constrained maximum can be expected to achieve a
lower value than the free maximum, although, by coincidence, the
two maxima may happen to have the same value
o We had added another constraint intersecting the first constraint at
a single point in the xy plane, the two constraints together would
have restricted the domain to that single point
o Then the locating of the extremum would become a trivial matter
• In a meaningful problem, the number and the nature of the
constraints should be such as to restrict, but not eliminate, the
possibility of choice
o Generally, the number of constraints should be less than the
number of choice variables
Under C < N equality constraints, when we can write a sub-set
of the choice variables as an explicit function of all others, the
former can be substituted out:
, ,…,
27
A Review of Optimization Methods
Hint: Lagrange Multiplier Method (1/2)
becomes:
, ,…,
an unconstrained problem
However, the direct substitution method cannot be applied
when the C constraints do not allow us to re-write the objective
functions in N – C free control variables
• Even if some of the variables become implicit functions of others,
it would be complex to proceed because the objective would
become “highly composite”
In such cases, we often resort to the method of Lagrange
(undetermined) multipliers
• The goal is to convert a constrained extremum problem into a
form such that the first-order condition of the free extremum
problem can still be applied
• For instance, consider an objective function z = f(x.y) subject to
the constraint g(x,y)=c where c is a constant
28
A Review of Optimization Methods
Lagrange Multiplier Method (2/2)
The Lagrangian problem is:
max 𝑓 𝑥, 𝑦 𝜆𝑐 𝑔 𝑥, 𝑦
, ,
29
A Review of Optimization Methods
Excel Solver for constrained optimization (1/2)
Lagrange multiplier method gives us critical (candidate) points,
but also in this case we need to check second order conditions
This requires to check positive (negative) definiteness of large
square matrices (bordered Hessian matrices) – we shall skip
the details
Again, the Excel Solver may help us!
First of all, the Solver easily solves “Kuhn-Tucker” type of
problems (that is, problems in which choice variables are
restricted to only take positive values)
It is sufficient to tick the box “make all unconstrained variable
positive)
Try with the problem we did before (the new minimum will be
at (0,0), quite intuitively)
30
A Review of Optimization Methods
Excel Solver for constrained optimization (2/2)
Now let us add constraints to our problem
Click on “add” to add equality / inequality constraints
31
A Review of Optimization Methods
Exercises
Solve the following exercises using Excel Solver
32
A Review of Optimization Methods