forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexArbXLE.m
53 lines (34 loc) · 1.1 KB
/
indexArbXLE.m
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
clear;
topN=40;
load('inputData_XLEcomponents');
cls_comp=cl;
stocks_comp=stocks;
load('inputData_XLE');
xle=strmatch('XLE', stocks, 'exact');
cls_xle=cl(:, xle);
trainDataLength=250;
testDataLength=250;
trainData=[length(tday)-testDataLength-trainDataLength+1:length(tday)-testDataLength];
adf=NaN(size(cls_comp, 2), 1);
for s=1:size(cls_comp, 2)
res=cadf(cls_xle(trainData), cls_comp(trainData, s), 0, 1);
adf(s)=res.adf;
end
[foo, idx]=sort(adf, 'ascend');
idx=idx(1:topN);
stocks_comp(idx)
res=ols(cls_xle(trainData), cls_comp(trainData, idx));
res.beta
basket_MV=smartsum(repmat(res.beta', [size(cls_xle(:, 1)) 1]).*cls_comp(:, idx), 2);
basket_XLE_MV=basket_MV-cls_xle;
mean_trainData=mean(basket_XLE_MV(trainData))
std_trainData=std(basket_XLE_MV(trainData))
testData=[length(tday)-testDataLength+1:length(tday)];
plot(basket_XLE_MV(trainData));
hold on;
plot([NaN(length(trainData), 1); basket_XLE_MV(testData)], 'r');
legend('Train Data', 'Test Data');
hold off;
xlabel('Days');
ylabel('Baskt\_XLE\_MV');
title('Market value of hedged basket');