forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgapFutures_FSTX.m
35 lines (22 loc) · 900 Bytes
/
gapFutures_FSTX.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
clear;
entryZscore=0.1;
data=load('inputDataOHLCDaily_20120517', 'syms', 'tday', 'op', 'hi', 'lo', 'cl');
idx=find(strcmp('FSTX', data.syms));
op=data.op(:, idx);
hi=data.hi(:, idx);
lo=data.lo(:, idx);
cl=data.cl(:, idx);
stdretC2C90d=backshift(1, smartMovingStd(calculateReturns(cl, 1), 90));
longs= op >= backshift(1, hi).*(1+entryZscore*stdretC2C90d);
shorts=op <= backshift(1, lo).*(1-entryZscore*stdretC2C90d);
positions=zeros(size(cl));
positions(longs)=1;
positions(shorts)=-1;
ret=positions.*(op-cl)./op;
ret(isnan(ret))=0;
fprintf(1, '%s APR=%10.4f Sharpe=%4.2f\n', data.syms{idx}, prod(1+ret).^(252/length(ret))-1, mean(ret)*sqrt(252)/std(ret));
% APR= 0.1327 Sharpe=1.44
cumret=cumprod(1+ret)-1; % compounded ROE
plot(cumret);
[maxDD maxDDD]=calculateMaxDD(cumret);
fprintf(1, 'Max DD =%f Max DDD in days=%i\n\n', maxDD, round(maxDDD));