-
Notifications
You must be signed in to change notification settings - Fork 0
/
performanceLCEPortfolio.m
120 lines (84 loc) · 2.31 KB
/
performanceLCEPortfolio.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
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
clear;
LL=1005;
b={'AAPL','ORCL','CSCO','INTC','QQQ','BAC','GE','F','C','SPY'};
l=500;
load 'AAPL_prediction_error';
load 'AAPL_gains';
X=AAPL_prediction_error;
G=AAPL_gains;
for i=2:10
symbol=char(b(i));
name=[symbol '_prediction_error'];
v = genvarname(name);
name1=[symbol '_gains'];
gains = genvarname(name1);
eval(['load ' v ]);
eval(['load ' gains]);
eval(['X=[X,' v '];']);
eval(['G=[G,' gains '];']);
end
% correlation= corrcoef(X);
w=zeros(1,10);
portfolio=zeros(10,LL-l);
invest=0;
daily_profit=zeros(1,LL-l);
cum_profit=zeros(1,LL-l);
GE=G+X;
for i=(l+1):LL
correlation= corrcoef(X((i-l):(i-1),1:10));
standard_deviation=std(X((i-l):(i-1),1:10));
w=((correlation\(transpose(GE(i,1:10)./standard_deviation)))/((GE(i,1:10)./standard_deviation)*(correlation\(transpose(GE(i,1:10)./standard_deviation)))))'./standard_deviation;
% w=zeros(1,10);
% w(9)=1;
if(w*(GE(i,1:10)')<0)
w=-w;
end
% suiji=rand(1);
% if(suiji>0.5)
% w(9)=1;
% else
% w(9)=-1;
% end
invest=0;
for j=1:10
if(w(j)>=0)
invest=invest+w(j);
else
invest=invest+4*abs(w(j))/3;
end
end
for j=1:10
if(w(j)>=0)
portfolio(j,i)=w(j)/invest;
else
portfolio(j,i)=-4*abs(w(j))/(3*invest);
end
end
if(invest ~=0 && GE(i,1:10)*(w')/invest>0.001)
%&& GE(i,1:10)*(w')/(sqrt(w*cov(GE)*w'))>0)
daily_profit(i-l)=G(i,1:10)*(w')/invest;
end
% cum_profit(1)=daily_profit(1);
if(i>l+1)
if(daily_profit(i-l)>-0.00)
cum_profit(i-l)=cum_profit(i-l-1)+daily_profit(i-l);
else
cum_profit(i-l)=cum_profit(i-l-1)-0.003;
end
end
end
save cum_profit;
save daily_profit;
save correlation;
save standard_deviation;
save portfolio;
x=1:1:(LL-l);
plot(x,4*cum_profit)
xlabel('trading day')
ylabel('Cumulative Profit')
title('Non Compound Cumulative Profit in the 900 trading days from 2008 to 2012 ')
a=zeros(1,304);
for i=1:304
a(i)=cum_profit(i+1)-cum_profit(i);
end
Sharpe=16*mean(a)/std(a)