fin500j topic 5 1 fall 2010 olin business school fin500j: mathematical foundations in finance topic...
TRANSCRIPT
Fin500J Topic 5 1Fall 2010 Olin Business School
Fin500J: Mathematical Foundations in Finance
Topic 5: Numerical Methods for Optimization
Philip H. DybvigReference: Optimization Toolbox User’s Guide in Matlab, 2008 by the
MathWorks, Inc.Slides designed by Yajun Wang
x
f(x)
Recall, with optimization, we are seeking f '(x) = 0
Fin500J Topic 5 2Fall 2010 Olin Business School
f '(x) = 0f "(x)< 0
f '(x) = 0f "(x)>0
10sin2)(
2xxxf Find the maximum of
Fin500J Topic 5 3Fall 2010 Olin Business School
05
cos2)(' x
xxf
To solve the root problem for
and the second condition is satisfied at the root
05
1*sin2*)('' xxf
Fin500J Topic 5 Fall 2010 Olin Business School 4
-6 -4 -2 0 2 4 6-5
-4
-3
-2
-1
0
1
2
x
y=2s
inx-
x2 /10
We can solve f '(x) =0 by Bisection using initial interval [1,2], Newton’s with initial point 1.2 or Secant method with initial points 1.2 and 2 presented in Topic 3.
We can also solve it in Matlab.
>> f=@(x) 2*cos(x)-1/5*x;
>> fzero(f,[1,2]) ans =1.4276
Objectives : Using Optimization Toolbox in Matlab to
Solve unconstrained optimization with multiple variables
Solve linear programming problemSolve quadratic programming problem (for example:
optimal portfolio)Solve nonlinear optimization with constraintsMostly, we will focus on minimization in this topic,
max f(x) is equivalent to min –f(x)
Fin500J Topic 5 5Fall 2010 Olin Business School
Linear Programming/Quadratic Programming/Nonlinear Programming
If f(x) and the constraints are linear, we have linear programming
If f(x) is quadratic, and the constraints are linear, we have quadratic programming
If f(x) in not linear or quadratic, and/or the constraints are nonlinear, we have nonlinear programming
Fin500J Topic 5 6Fall 2010 Olin Business School
• Unconstrained Minimization Problem: min f(x1, x2,…xn)
• Optimality Condition: x* is a local minimum if
• Example:
•What values of x make
Fin500J Topic 5 7Fall 2010 Olin Business School
definite. positive is and 0)( 2* )f(xxf *
,ee
eee)(
,eeef(x)min
1x1x
1x-1x1x
1-x1x1x
2121
12121
12121
xx
xx
xx
xf
?0)( xf
Fin500J Topic 5 Fall 2010 Olin Business School 8
Step 1: Write an M-file objfun.m and save under the work path of matlab
function f=objfun(x) f=exp(x(1)+x(2)-1)+exp(x(1)-x(2)-1)+exp(-x(1)-1);
Step 2: >>optimtool in the commend window to open the optimization toolbox
Fin500J Topic 5 Fall 2010 Olin Business School 9
We use the function fminunc to solve unconstrained optimization problem “objfun”
Fin500J Topic 5 Fall 2010 Olin Business School 10
).()(-x
:case variableMultiple.)(
)(x
)()()()(
12
''
'
'''''
kk
k
k
kkkk
xfxf
xf
xf
x
xf
x
xfxxfxf
Fin500J Topic 5 Fall 2010 Olin Business School 11
Newton’s method may fail if Hessian is not positive definite
Fin500J Topic 5 Fall 2010 Olin Business School 12
The function “fminunc” uses BFGS (Broyden, Fletcher, Goldfarb and Shanno) Hessian Update in the Quasi-Newton algorithm. The formula given by BFGS is
Fin500J Topic 5 13Fall 2010 Olin Business School
Both the objective function and the constraints are linear
Example: maximizing profit or minimizing costObjective function Max or Min Z = c1x1 +c2x2 +…..cnxn
where cj = payoff of each unit of the jth activity xj = magnitude of the jth activityThe constraints can be represented by ai1x1 +ai2x2+…..ainxn bi
where aij = amount of the ith resource that is consumed for each
unit of the jth activity, bi = amount of the ith resource available
Finally, we add the constraint that all activities have a positive value, xi 0
Total Profit = 150 x1 + 175 x2
Maximize Z = 150 x1 + 175 x2Objective function
Resource Regular Premium Resource Availability
120
Storage 9 6(tonne)
Profit (/tonne) 150 175
77
10 8
Product
Raw Gas
(m3/tonne)
Production Time (hr/tonne)
7 11
Fin500J Topic 5 14Fall 2010 Olin Business School
x1 = amount of regular and x2 = amount of premium
7x1 + 11x2 77 (material constraint)10x1 + 8x2 120 (time constraint)x1 9 (storage constraint)x2 6 (storage constraint)x1,x2 0 (positivity constraint)
(5) x1,x2 0
Fin500J Topic 5 15Fall 2010 Olin Business School
(1) 7x1 + 11x2 77→x2 -7/11 x1 +7
(2) 10x1 + 8x2 120→ x2 -5/4x1 + 15
(3) x1 9
(4) x2 6
Now we need to add the objective function to the plot. Start withZ = 0 (0=150x1 + 175x2)and Z = 500 (500=150x1 + 175x2)
Fin500J Topic 5 16Fall 2010 Olin Business School
Z=1200Z=1550
Still in feasible regionx1*= 9x2* 1.5
Fin500J Topic 5 17Fall 2010 Olin Business School
Step 1: >>optimtool in the commend window to open the optimization
toolbox Step 2: Define matrices A, Aeq and
the vectors f, b, lb, ub
Example:
Fin500J Topic 5 18Fall 2010 Olin Business School
File->export to workspace
can export the results including lambda,etc.
Fin500J Topic 5 19Fall 2010 Olin Business School
Step 1: >>optimtool in the commend window to open the optimization
toolbox Step 2: Define matrices H,A and the vectors f, b
Fin500J Topic 5 21Fall 2010 Olin Business School
H=[0.017087987 0.003298885 0.001224849; 0.003298885 0.005900944 0.004488271; 0.001224849 0.004488271 0.063000818]
f=[0; 0; 0]A=[1 1 1; -0.026 -0.008 -0.074;
-1 0 0; 0 -1 0; 0 0 -1]b=[1000; -50; 0; 0; 0]
The function ‘quadprog ’ uses an active set strategy. The first phase involves the calculation of a feasible point. The second phase involves the generation of an iterative sequece of feasible points that converge to the solution.
Fin500J Topic 5 23Fall 2010 Olin Business School
Find x that solves
Step 1: Write an M-file objfunc.m for the objective function. function f=objfunc(x) f=exp(x(1))*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1);
Step 2: Write an M-file confun.m for the constraints. function [c, ceq]=confun(x) %Nonlinear inequality constraints c=[1.5+x(1)*x(2)-x(1)-x(2); -x(1)*x(2)-10]; %Nonlinear equality constraints ceq=[]; Step 3: >>optimtool to open the optimization toolbox
Fin500J Topic 5 Fall 2010 Olin Business School 25
The basic idea is analogous to Newton’s method for unconstrained optimization.
In unconstrained optimization, only the objective function must be approximated, in the NLP, both the objective and the constraint must be modeled.
An sequential quadratic programming method uses a quadratic for the objective and a linear model of the constraint ( i.e., a quadratic program at each iteration)
,...m.mi(x)g
.,...mi(x)g
f(x),
ei
ei
x
10
10
subject to
min