Struggling with two-stage stochastic model implementation
Posted: Wed Sep 22, 2021 9:20 pm
Hello!
Being new to GAMS I´m struggling with implementation of a simple two stage model, especially the EMP annotation part.
The model is described in the picture: Variable r-2 - stock returns - is random and I want to approximate it by scenarios. lambda_2 and alpha are constants.
I started with the following code, but I can´t get the EMP part right probably:
Is my overall approach right and could you please help me to continue? The next step for me is to extend the model for multiple stages, but I guess it won´t be much different.
Thank you!
Being new to GAMS I´m struggling with implementation of a simple two stage model, especially the EMP annotation part.
The model is described in the picture: Variable r-2 - stock returns - is random and I want to approximate it by scenarios. lambda_2 and alpha are constants.
I started with the following code, but I can´t get the EMP part right probably:
Code: Select all
$title Two stage asset allocation model
Sets n "assets" / att, gmc, usx /
j "scenarios" / s1*s4 / ;
Table r_scenarios(j,n) "scenario returns from assets"
att gmc usx
s1 1.300 1.225 1.149
s2 1.103 1.290 1.260
s3 1.216 1.216 1.419
s4 0.954 0.728 0.922 ;
Parameters
r(n) "return from assets"
p(j) "probability" / #j [1/card(j)] / ;
Scalars lambda_2 "mean-risk ratio" / 0.5 /
alpha "CVaR level" / 0.05/ ;
Variables
Q_1 "objective"
x_1(n) "first stage weights"
x_2(n) "second stage weights"
u_1 "first stage CVaR minimizer"
R_2 "recoursive part"
Q_2 "second stage objective" ;
Positive Variables x_1, x_2;
Equations
Q_1_equation "objective function"
budget_first "budget constraint for x_1"
R_2_equation "R_2 equation"
Q_2_equation "second stage objective function"
budget_second "budget constraint for x_2"
take_max "max(Q_2 - u_1, 0)";
Q_1_equation.. Q_1 =e= - sum(n, x_1(n)) + lambda_2 * u_1 + R_2;
budget_first.. sum(n, x_1(n)) =e= 1;
R_2_equation.. R_2 =e= (1-lambda_2)* Q_2 + (lambda_2 / alpha) * (Q_2 - u_1)
Q_2_equation.. Q_2 =e= - sum(n, x_2(n))
budget_second.. sum(n, x_2(n)) =e= sum(n, x_1(n)*r(n))
take_max.. Q_2 - u_1 =g= 0
Model portfolio / all /;
* EMP Annotations
File emp / '%emp.info%' /;
emp.nd=4;
put emp '* problem %gams.i%'
/ 'stage 2 ?????'
/ "jrandvar r('att') r('gmc') r('usx')"
loop(j,
put / p(j) r_scenarios(j,"att") r_scenarios(j,"gmc") r_scenarios(j,"usx"));
putclose emp;
Thank you!