portfolio optimization, put call model

Hello everyone,

I am very new to GAMS and managed to construct one model so far!! :smiley: But now I want to change the variable that has to maximized and find out the corresponding values… sounds complicated, I know. It is a linear problem, I have 25 stocks, monthly returns for 168 periods and use this historic data to infer possible stock price developments for the future. Now I want GAMS to maximize possible return and minimize risk , subject to constraints: sum of all investments is 1, the scalar omega is the maximum percentage one is willing to lose and cannot be set below zero, of course. The higher omega, the higher the expected return and risk.

Here is my code:

*$TITLE formulation for a portfolio management model

  • define runtime control parameters
    $OFFSYMXREF
    $OFFSYMLIST
    OPTION LIMCOL=0;
    OPTION LIMROW=0;
    OPTION SOLPRINT=OFF;

  • select optimization solver
    $offlisting;
    OPTION ITERLIM=100000;
    OPTION RESLIM=100000;
    OPTION LP=GUROBI;

    \

  • define the set of asset classes

Define sets

SET class the investment asset classes / S1*S25 /;

SET n / n1*n168 /;

Define Tables, parameters, scalars*

$INCLUDE spreturns.txt
$INCLUDE benchmark.txt

parameter Prob(n) Scenario probabilities;
loop(n, Prob(n)=1/168);


SCALARS
Omega Bound on the expected downside loss /0.055267/ ;

Define variables*


VARIABLES
downside downside losses
yPos(n) Positive deviations
yNeg(n) Negative deviations
hold(class) proportions of asset classes invested at root node
z Objective function value;

POSITIVE VARIABLES yPos, yNeg, hold;


EQUATIONS
downloss downside losses
init_balance asset balance constraint at the root
ObjDef Objective function
Dev(n) Equations defining the deviations ;
Conneg Constraint to bound the expected value of the negative deviations ;

downloss… downside =E= SUM(n, Prob(n) * yNeg(n));

init_balance… sum(class, hold(class)) =E= 1.0;

Conneg … SUM(n, Prob(n) * yNeg(n)) =L= Omega;

Dev(n)… yPos(n) - yNeg(n) =E= sum(class, hold(class)*Ret(n,class)) - index(n);

ObjDef … z =E= SUM(n, Prob(n) * yPos(n));

model portfolio / all /;

file resultsputcall25;
resultsputcall25.ap=1;

SOLVE portfolio USING LP MAXIMIZING z ;

put resultsputcall25;
resultsputcall25.nd=5;
put z.l, downside.l /;
put/;
loop(class, put CLASS.tl, hold.l(class) / );


Now I want GAMS to find the portfolio with the highest possible return and give me the corresponding omega, find the portfolio with the lowest omega, and the portfolio with the average return of these 2 portfolios and the corresponding omega.

the files spreturns and benchmark are attached…

So please feel free to ask back questions since I don’t really know what else I have to write for you to understand my question and the problem :wink:

Thank you so much!
best regards,
Nils


benchmark.txt (1.95 KB)
spreturns.txt (27.4 KB)

Nils,

I think you might want to think about a formulation to ensure that either yPos(n) or yNeg(n) holds a non-zero value (e.g. MIP/SOS2 formulation).

Towards your question of how to solve the model with different settings/objectives, please find attached a slightly modified version of your code that illustrates how to solve the model iteratively.
To minimize Omega you can make it a variable. By using Omega.fx = 0.055267; you can give it a fixed value and solve your model as you did before.

Hope this helps.

Regards,
Fred

On Wednesday, January 6, 2016 at 10:32:27 PM UTC+1, Nils wrote:

Hello everyone,

I am very new to GAMS and managed to construct one model so far!! :smiley: But now I want to change the variable that has to maximized and find out the corresponding values… sounds complicated, I know. It is a linear problem, I have 25 stocks, monthly returns for 168 periods and use this historic data to infer possible stock price developments for the future. Now I want GAMS to maximize possible return and minimize risk , subject to constraints: sum of all investments is 1, the scalar omega is the maximum percentage one is willing to lose and cannot be set below zero, of course. The higher omega, the higher the expected return and risk.

Here is my code:

*$TITLE formulation for a portfolio management model

  • define runtime control parameters
    $OFFSYMXREF
    $OFFSYMLIST
    OPTION LIMCOL=0;
    OPTION LIMROW=0;
    OPTION SOLPRINT=OFF;

  • select optimization solver
    $offlisting;
    OPTION ITERLIM=100000;
    OPTION RESLIM=100000;
    OPTION LP=GUROBI;

    \

  • define the set of asset classes

Define sets

SET class the investment asset classes / S1*S25 /;

SET n / n1*n168 /;

Define Tables, parameters, scalars*

$INCLUDE spreturns.txt
$INCLUDE benchmark.txt

parameter Prob(n) Scenario probabilities;
loop(n, Prob(n)=1/168);


SCALARS
Omega Bound on the expected downside loss /0.055267/ ;

Define variables*


VARIABLES
downside downside losses
yPos(n) Positive deviations
yNeg(n) Negative deviations
hold(class) proportions of asset classes invested at root node
z Objective function value;

POSITIVE VARIABLES yPos, yNeg, hold;


EQUATIONS
downloss downside losses
init_balance asset balance constraint at the root
ObjDef Objective function
Dev(n) Equations defining the deviations ;
Conneg Constraint to bound the expected value of the negative deviations ;

downloss… downside =E= SUM(n, Prob(n) * yNeg(n));

init_balance… sum(class, hold(class)) =E= 1.0;

Conneg … SUM(n, Prob(n) * yNeg(n)) =L= Omega;

Dev(n)… yPos(n) - yNeg(n) =E= sum(class, hold(class)*Ret(n,class)) - index(n);

ObjDef … z =E= SUM(n, Prob(n) * yPos(n));

model portfolio / all /;

file resultsputcall25;
resultsputcall25.ap=1;

SOLVE portfolio USING LP MAXIMIZING z ;

put resultsputcall25;
resultsputcall25.nd=5;
put z.l, downside.l /;
put/;
loop(class, put CLASS.tl, hold.l(class) / );


Now I want GAMS to find the portfolio with the highest possible return and give me the corresponding omega, find the portfolio with the lowest omega, and the portfolio with the average return of these 2 portfolios and the corresponding omega.

the files spreturns and benchmark are attached…

So please feel free to ask back questions since I don’t really know what else I have to write for you to understand my question and the problem :wink:

Thank you so much!
best regards,
Nils


modified.gms (2.73 KB)