-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTargets_Sub.gms
168 lines (122 loc) · 4.5 KB
/
Targets_Sub.gms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
$TITLE Final Project
* Generates targets based on given index or ETF
$eolcom //
option optcr=0.0001;
SETS
Date 'Dates'
Asset 'Assets'
Periods 'Amount of 4-week intervals'
Scenarios 'Scenarios'
;
ALIAS(Date,t);
ALIAS(Periods,p);
ALIAS(Scenarios,s);
****Loading Data file.***
$GDXIN RollingScenarios250
$LOAD Asset Periods Scenarios
$GDXIN
**** SELECT THE INDEX OR ETF BASED ON WHICH TO GENERATE TARGETS ****
set subAsset(Asset) /EDEN/ //tracking MSCI Denmark
ALIAS(subAsset,i);
$onMulti
PARAMETER
ScenarioReturnP(i,s,p) 'Return of index i, at date t, in scenariointerval p'
ReturnsMonth(p,i)
;
****Loading Data file.***
$GDXIN RollingScenarios
$LOAD ScenarioReturnP
$GDXIN
$GDXIN ReturnMonthly
$LOAD ReturnsMonth
$GDXIN
DISPLAY i, Periods, Scenarios, ScenarioReturnP, ReturnsMonth;
SCALARS
Budget 'Nominal investment budget'
alpha 'Confidence level'
Lambda 'Risk aversion parameter'
CVaRLim 'CVaR limit'
ExpRetLim 'Expected Return Limit'
;
// DEFINE BUDGET AND ALPHA
Budget = 100000.0;
alpha = 0.95;
PARAMETERS
pr(s) 'Scenario probability'
Rp(i,s,p) 'Final values "R_is" for ord(p)th rolling'
EPp(i,p) 'Expected final values "mu_i" for ord(p)th rolling'
R(i,s) 'Auxiliary parameter for final values'
EP(i) 'Auxiliary parameter for Expected final values'
;
// DEFINITIONS
pr(s) = 1.0 / CARD(s);
Rp(i,s,p) = 1 + ScenarioReturnP(i,s,p);
EPp(i,p) = SUM(s, pr(s) * Rp(i,s,p));
PARAMETER x_old(i);
POSITIVE VARIABLES
x(i) 'Holdings of assets in proportions'
VaRDev(s) 'Measures of the deviation'
;
VARIABLES
Losses(s) 'The scenario loss function'
VaR 'The alpha Value-at-Risk'
CVaR 'The alpha Conditional Value-at-Risk'
ExpectedReturn 'Expected return of the portfolio'
obj 'Objective function value'
;
EQUATIONS
BudgetCon 'Equation defining the budget constraint'
ReturnCon 'Equation defining the portfolio expected return'
LossDefCon(s) 'Equation defining the losses'
VaRDevCon(s) 'Equation defining the VaRDev variable'
CVaRDefCon 'Equation defining the CVaR'
ObjectivFunc 'Lambda formulation of the MeanCVaR model'
;
*--s.t.-----------
BudgetCon .. sum(i, x(i)) =E= Budget;
ReturnCon .. ExpectedReturn =E= sum(i, EP(i)*x(i));
LossDefCon(s) .. Losses(s) =E= -1*sum(i, R(i, s)*x(i) );
VaRDevCon(s) .. VaRDev(s) =G= Losses(s) - VaR;
CVaRDefCon .. CVaR =E= VaR + (sum(s, pr(s)*VarDev(s) ) )/(1 - alpha);
*--Objective------
ObjectivFunc .. Obj =E= (1-lambda)*ExpectedReturn - lambda*CVaR;
*--Model-----------
MODEL CVaRModel 'The Conditional Value-at-Risk Model' /BudgetCon, ReturnCon, LossDefCon, VaRDevCon, CVaRDefCon/;
*--CVaR----------------------
PARAMETERS
ExpectedReturnp(p) 'Expected return for ord(p)th rolling'
VaRp(p) 'Value-at-risk for ord(p)th rolling'
CVaRp(p) 'Conditional-Value-at-risk for ord(p)th rolling'
RunningBudget(p) '1/N portfolio performance'
;
// THE FIRST PERIOD
X.fx(i) = Budget/card(i);
display X.l;
R(i,s) = Rp(i,s,"p0");
EP(i) = SUM(s, pr(s) * R(i,s));
SOLVE CVaRModel Minimazing CVaR using LP;
ExpectedReturnp("p0") = (ExpectedReturn.l/Budget) - 1;
CVaRp("p0") = CVaR.l/Budget;
RunningBudget("p0")=Budget;
display x.l
// REBALANCING
LOOP(p$(ord(p)>=2),
R(i,s) = Rp(i,s,p);
EP(i) = SUM(s, pr(s) * R(i,s));
x_old(i)=x.l(i)*(1+ReturnsMonth(p,i));
Budget=sum(i,x_old(i));
RunningBudget(p)=Budget;
x.fx(i)=x_old(i);
SOLVE CVaRModel MINIMIZING CVaR using LP;
CVaRModel.SOLPRINT = 2;
ExpectedReturnp(p) = (ExpectedReturn.l/sum(i,x.l(i)))-1;
CVaRp(p) = CVaR.l/sum(i,x.l(i));
);
parameter SummaryReport(*,*);
* Store results by rows
SummaryReport('ExpectedReturn',p) = ExpectedReturnp(p);
SummaryReport('CVaR',p) = CVaRp(p);
SummaryReport('EqualWeightPortfolio',p)= RunningBudget(p);
display SummaryReport
EXECUTE_UNLOAD 'Denmark_TargetsRolling.gdx' SummaryReport;
*EXECUTE 'gdxxrw.exe Sub_TargetsRolling.gdx O=SP500_TargetsRolling.xls par=SummaryReport rng=sheet1!a1';