Oct 27

Posted by abiao at 21:54 | Code » Matlab | Comments(1) | Reads(31814)

Anyway, it is your turn to compare them.  I write M files of several selected quantitative trading strategies from the book I have played, be aware although I wrote carefully, i dont gurantee the correct of them, and i didn't optimize the code, either, sorry.

Moving Average: long when x day moving average crosses above y day moving average, short when x day moving average crosses below y day moving average
pos=zeros(size(price,1),1);
lag = [zeros(y-1,1); lag];

Volatility Breakouts:
m = size(price,1);
pos=zeros(m,1);
for i = 2:m
%put here the way to calculate variance C
UpperTrigger = price(i-1)+multiplier*sqrt(C);
LowerTrigger = price(i-1)-multiplier*sqrt(C);
if price(i)>=UpperTrigger pos(i) = 1;
elseif price(i)<=LowerTrigger pos(i) = -1;
end
end

stochastic indicator:
stosc = stochosc(highp, lowp, closep, kperiod, dperiod); %embedded Matlab function
m = size(highp,1);
pos=zeros(m,1);
inx1 = find(stosc(:,1)>=30);
inx2 = find(stosc(:,1)>=stosc(:,2));
pos(intersect(inx1,inx2)) = 1;
inx1 = find(stosc(:,1)<=80);
inx2 = find(stosc(:,1)<=stosc(:,2));
pos(intersect(inx1,inx2)) = -1;

Divergence Index:
%divergence index strategy, m is long momentum period, n is for short
longmom = tsmom(price,m);
shortmom = tsmom(price,n);
mm = size(price,1);
pos=zeros(mm,1);
DI = longmom.*shortmom./var(diff(price));
inx1 = find(DI<-8);
inx2 = find(longmom<0);
inx3 = find(longmom>0);
pos(intersect(inx1,inx2))=-1;
pos(intersect(inx1,inx3))=1;

Moving Average Confluence Method:
% p - *price* data
% N - number of points to generate signal
pos=zeros(size(p,1),1);
macs = zeros(size(p,1),20);
for i=1:20
j=i*4;
lag = [nan(j-1,1); lag];
end
macssum = sum(macs,2);
macssum(1:80) = 50; %first 80 observations with zero position
pos(macssum>=N)=1;
pos(macssum<=(100-N))=-1;

There are other strategies left to you to backtest the effectiveness of technical analysis, for example, Kestner’s Moving Average System, Second Order Breakout, MACD Histogram Retracement, Normalized Envelope Indicator, etc. Have fun.

Tags: ,
Really easy to browse through and also it is stuffed with loads of info. It is all totally on point. Will you want to evaluate my blog site?
archery king cheats
Pages: 1/1 1
 Add a comment Emots Enable HTML Enable UBB Enable Emots Hidden Remember Nickname   Password   Optional Site URI   Email   [Register]