matlab代写-BUS 801
时间:2021-02-20
Dr Phil Goddard Exercises Email: phil@goddardconsulting.ca

BUS 801 – Financial Programming Fundamentals 1








Optimization Exercises







This document contains a number of exercises designed to improve your programming skills as they relate to
solving optimization problems.

Notes:

• For the purposes of BUS801 it is recommended that you use MATLAB to code the exercises. However,
in general for most of the exercises any programming language that has access to an optimization library
could be used.

• For all the exercises you should use a function from the MATLAB Optimization Toolbox to perform the
actual optimization.



Dr Phil Goddard Exercises Email: phil@goddardconsulting.ca

BUS 801 – Financial Programming Fundamentals 2


Exercise 1: Minimize a function of 2 variables ......................................................................................................3
Exercise 2: Minimize a function of 3 variables ......................................................................................................3
Exercise 3: Find the minimum of a polynomial .....................................................................................................3
Exercise 4: Find the zero of a polynomial ..............................................................................................................3
Exercise 5: Portfolio Optimization .........................................................................................................................4


Dr Phil Goddard Exercises Email: phil@goddardconsulting.ca

BUS 801 – Financial Programming Fundamentals 3


Exercise 1: Minimize a function of 2 variables

Given the function of 2 variables,

(, ) = 32 − 4 + 22 + + 10 + 5

a) Calculate values for x and y that minimize f(x,y).

b) Recalculate values for x and y if there is a constraint such that x + y = 1.


Exercise 2: Minimize a function of 3 variables

Given the function of 3 variables,

(, , ) = + +

Calculate the minimum of (, , ) if the variables are subject to the constraint

(, , ) = 2 + 2 + 2 = 1.

Exercise 3: Find the minimum of a polynomial

Given a vector which represents the coefficients of an nth order polynomial y = f(x), write a function to calculate
the value of x that minimizes f(x).

Plot the function to visually check that the optimizer has found the minimum. If it hasn’t found the minimum you
expect then explain why.

Exercise 4: Find the zero of a polynomial

Given a vector which represents the coefficients of an nth order polynomial y = f(x), write a function to calculate
the value of x where the polynomial has a zero, i.e. f(x) = 0.

Plot the function to visually check that the optimizer has found the minimum. If it hasn’t found the minimum you
expect then explain why.


Dr Phil Goddard Exercises Email: phil@goddardconsulting.ca

BUS 801 – Financial Programming Fundamentals 4


Exercise 1: Portfolio Optimization

The return and variance of a portfolio are given by = and = Σ respectively, where
is a vector of asset weights; is a vector of historical returns for each asset; and Σ is a matrix of
historical covariance.

Given a portfolio with historical returns = [0.5 0.1 0.2 0.4] and covariance

Σ = [
2 0.5 −1 −1
1 4 1 −0.5
−1 1 6 0.1
−1 −0.5 0.1 8
]

and assuming that there is no short selling or leverage allowed (that is 0 ≤ ≤ 1, for all i) and that
all assets are fully invested (that is ∑

1 = 1),

a) Calculate weights for the portfolio that would provide the highest return. What is the risk of
this portfolio?

b) Calculate weights for the portfolio that would provide the minimum risk. What is the return
of this portfolio?

c) Create a vector of expected returns between the maximum return, and the return of the
portfolio with the minimum risk. For each of these returns, calculate the weights of the
portfolio giving that return and having minimum risk.

d) Plot the efficient frontier (that is, the return versus risk, for the assets).






























































































































学霸联盟


essay、essay代写