程序代写案例-IB3K20
时间:2022-03-16
IB3K20: Financial Optimisation
Seminar 3: Answers
Nalan Gulpinar
(Email: Nalan.Gulpinar@wbs.ac.uk)
Warwick Business School
University of Warwick
3 February 2022

Question 1: Let’s consider the following case
An investor has £1000 capital and would like to create a portfolio.
The investor considers three stocks (labelled as i = A,B,C ) to
invest in. A financial advisor suggests him to take into account the
following conditions;
No more than 50% of the capital must be invested in Stock A.
Total amount of capital to be invested in Stocks A and B
must be at most 70% of the capital.
Amount of capital to be invested in Stock C should be no less
than the investment in Stock B.
Stock returns are normally distributed with mean and variance as
Stock Return Stock A Stock B Stock C
Average 0.14 0.11 0.10
Variance 0.20 0.08 0.18
Formulate the investor’s portfolio allocation problem to maximize
expected portfolio return.
Linear Portfolio Allocation Model
Definition: Let ri denote a random variable representing the annual
return on £1 invested in stock i .
Example: If ri = 0.15, it means that £1 invested in stock i at the
beginning of the year is worth £1.15 at the end of the year.
Decision Variables: Let xi denote amount of capital invested on
stock i = A,B,C .
Annual return on portfolio (to be constructed):
rp =
rAxA + rBxB + rCxC
1000
Expected annual portfolio return:
E [rp] = r¯p =
E [rA]xA + E [rB ]xB + E [rC ]xC
1000
LP: maximize portfolio return subject to financial advisor’s
suggestions and capital investment
Portfolio Allocation Model
Decisions: xi amount of capital to invest on stock i = A,B,C
Constraints:
total capital investment
no more than 50% of the capital to invest in A
total investment in A and B to be at most 70% of the capital
investment in C to be no less than investment in B
LP(Primal) : max Zp = 0.14xA + 0.11xB + 0.10xC
s.t. xA + xB + xC = 1000
xA ≤ 500
xA + xB ≤ 700
xB − xC ≤ 0
xA, xB , xC ≥ 0
Answer 1: a) Formulate and Solve the Problem
Formulate and solve the portfolio allocation problem
Conduct the following tasks
create data file: ‘portfolio.dat’
read coefficient matrix of constraints from file:
‘portfolio.txt’
state each constraint explicitly in model file:
‘portfolio.mod’
write constraints as a set of equations in model file:
‘portfolio-mat.mod’
run commands:
‘portfolio.run’ and ‘portfolio-mat.run’
Model File (portfolio.dat)
Model File (portfolio.mod)
AMPL Commands File (portfolio.run)
Output: Optimal Allocation
ampl: include portfolio.run;
Gurobi 9.5.0: optimal solution; objective 122
1 simplex iterations
x [*] :=
1 500
2 200
3 300
;
PortfolioReturn = 122
ampl:
Model File (portfolio-mat.mod)
Output: Optimal Allocation
ampl: include portfolio-mat.run;
Gurobi 9.5.0: optimal solution; objective 122
1 simplex iterations
x [*] :=
1 500
2 200
3 300
;
PortfolioReturn = 122
subject to constraints{i in M} : sum{j in N} A[i,j]*x[j] <= b[i];
constraints [*] :=
1 0.1
2 0.03
3 0.01
4 0
;
ampl:
Answer 1: b) Use of ‘FOR’ and ‘LET’ commands
Generate new stock returns
Use built-in random number generation function:
Normal(µ, σ) with mean (µ), variance (σ) of stock returns
Resolve the problem and display new stock returns and output
Let’s create ‘portfolio2.run’ file
Use of ‘FOR’ and ‘LET’: (portfolio2.run)
Output (‘FOR’ and ‘LET’)
ampl: include portfolio2.run;
option randseed 2671633739;
Gurobi 9.5.0: optimal solution; objective 107.1354715
: r x :=
1 0.116625 500
2 0.0384438 0
3 0.0976458 500
;
PortfolioReturn = 107.135
ampl: include portfolio2.run;
option randseed 2671633849;
Gurobi 9.5.0: optimal solution; objective 180.7101666
1 simplex iterations
: r x :=
1 0.305605 500
2 0.102447 200
3 0.0247272 300
;
PortfolioReturn = 180.71
Answer 1: c) Use of ‘IF THEN’ command
if () then else
Make sure that you take negative of return value if the
generated value is negative
Create ‘portfolio3.run’
Solve the problem with new data set.
Use of ‘IF THEN’ (portfolio3.run)
Output (‘IF THEN’)
ampl: include portfolio3.run;
option randseed 2671673327;
Gurobi 9.5.0: optimal solution; objective 213.1571124
1 simplex iterations
: r x :=
1 0.34367 500
2 0.166509 200
3 0.0267341 300
;
PortfolioReturn = 213.157
ampl:
Answer 1: d) Use of ‘REPEAT UNTIL’ command
repeat until ;
Make sure that stock returns generated are nonnegative
Create ‘portfolio4.run’
Solve the problem with new data set.
Use of ‘REPEAT UNTIL’ (portfolio4.run)
Answer 1: e) Construct Dual Problem
Let yj for j = 1, · · · , 4 denote dual variables corresponding to
constraints of the primal problem
LP(Dual) : min Zd = 1000y1 + 500y2 + 700y3 + 0y4
s.t. y1 + y2 + y3 ≥ 0.14
y1 + y3 + y4 ≥ 0.11
y1 − y4 ≥ 0.10
y1, free
y2, y3, y4 ≥ 0.
Homework: Write AMPL codes and solve the optimisation problem

essay、essay代写