-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMonthlyReturns.gms
45 lines (35 loc) · 1.09 KB
/
MonthlyReturns.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
$TITLE Final project
* Compounds 4-week period returns
$eolcom //
option optcr=0.0001;
SETS
Date 'Dates'
Asset 'Assets'
p /p1*p49/ //49 4-week periods for out-of-sample testing
Scenarios 'Scenarios'
;
ALIAS(Date,t);
ALIAS(Asset,i);
PARAMETER
Return(t,i) 'historical return weekly'
ReturnsMonth(p,i) 'historical return monthly'
;
// LOAD DATA FILE
$GDXIN out-ETFRet
$LOAD Asset, Date, Return
$GDXIN
DISPLAY t, i, Return;
* Turn historical returns into 4-weeks period
loop(p,
loop(t$(ord(t) le 4*ord(p)+ 97 and ord(t) gt 4*(ord(p)-1)+97),
if (ord(t) eq 4*ord(p)-3+97,
ReturnsMonth(p, i) = 1 + Return(t,i);
else
ReturnsMonth(p, i) = (1 + Return(t,i))*ReturnsMonth(p, i);
);
);
ReturnsMonth(p, i) = ReturnsMonth(p, i)-1;
);
display ReturnsMonth // monthly historical returns for the backtesting
EXECUTE_UNLOAD 'ReturnMonthly.gdx', ReturnsMonth;
*EXECUTE 'gdxxrw.exe ReturnsMonthly.gdx O=ReturnsMonthly.xls par=ReturnsMonth rng=sheet1!a1' ;