Hello everybody,

Recently I got inspired by post about Market Meanness Index from Financial Hacker. More info about it is here:

http://www.financial-hacker.com/the-...eanness-index/ http://www.financial-hacker.com/boos...ade-filtering/
As I have big database from my system (>6 millions of trades for lats year) i decided to filter them using MMI. Here is my implementation

Code:

function [profit_tot, possum, negsum, winner, loser, alltrades] = MMISim(lotsize, spread, freq, tradesize, trades, currency, Smooth, Length)
% for each pair
% 1) calculate raw MMI
% 2) smooth MMI
[startidx, stopidx] = findidxs(trades, currency);
i=1; % index to trade file
alltrades = repmat(trades,1);
inew = 1; % index to new trade file
rawMMI = calc_rawMMI(currency(:,6), Length);
MMI = indicators(rawMMI, 'sma', Smooth);
% pSmoothed = indicators(currency, 'sma', Smooth);
for k=startidx:stopidx
if round(currency(k,1)+currency(k,2),4) >= round(datenum(trades(i,2)),4) % currency in sync with trade list
if i < size(trades,1)
i=i+1;
else
break;
end
if (MMI(k)<MMI(k-1)) % MMI is falling
alltrades(inew,:)= trades(i,:); % copy trade
inew = inew +1;
end
end
end
% delete superfluus of trade file
alltrades(inew+1:end,:) = [];
profit_tot = sum(cell2num(alltrades(:,14)))*tradesize*lotsize/freq;
possum=0;
negsum=0.0001;
winner = 0;
loser = 0;
for ii=1:size(alltrades,1);
if cell2num(alltrades(ii,14))>0
possum = possum + cell2num(alltrades(ii,14));
winner = winner + 1;
end
if cell2num(alltrades(ii,14))<0
negsum = negsum + cell2num(alltrades(ii,14));
loser = loser + 1;
end;
end
% PFs = abs(sum(possum)/sum(negsum));
% PPs = sum(winner)/(sum(winner)+sum(loser))*100;
end
function [rawMMI] = calc_rawMMI(Data, Length)
m = movmedian(Data,Length);
rawMMI = zeros(size(Data,1),1);
for k =size(Data,1):-1:Length+2
nh=0; nl=0;
for i=k:-1:k-Length
if(Data(i) > m(k) && Data(i) > Data(i-1))
nl=nl+1;
else if(Data(i) < m(k) && Data(i) < Data(i-1))
nh=nh+1;
end
end
end
rawMMI(k) = 100.*(nl+nh)/(Length-1);
end
end

and here are the trade files for 8 symbols for 2 different algos. SDAE and Pegassos SVM

Code:

QAtrades_Peg__PF=1.05_Profit=33282336.4_PP=63
QAtrades_SDAE__PF=1.19_Profit=108194086.9_PP=65.4

so initial PF are 1.05 and 1.19.

Here are the results of filtering for different Smooth and Length

Code:

whatifQAtrades_Peg_PF=1.05_Profit=8529502416.6_PP=63.14_freq=1_tradesize=0.01_Smooth=600_Length=50_TP=350392_FP=204589
whatifQAtrades_SDAE_PF=1.2_Profit=23894165020.55_PP=65.63_freq=1_tradesize=0.01_Smooth=600_Length=50_TP=326980_FP=171238
whatifQAtrades_SDAE_PF=1.2_Profit=22116171802.7_PP=65.61_freq=1_tradesize=0.01_Smooth=100_Length=100_TP=330259_FP=173129
whatifQAtrades_SDAE_PF=1.19_Profit=23293250055.9_PP=65.79_freq=1_tradesize=0.01_Smooth=200_Length=100_TP=329397_FP=171282
whatifQAtrades_SDAE_PF=1.18_Profit=22808654859.55_PP=65.71_freq=1_tradesize=0.01_Smooth=300_Length=100_TP=331200_FP=172836
whatifQAtrades_SDAE_PF=1.2_Profit=26104137089.45_PP=65.93_freq=1_tradesize=0.01_Smooth=400_Length=100_TP=333457_FP=172280
whatifQAtrades_SDAE_PF=1.2_Profit=27012799035_PP=65.8_freq=1_tradesize=0.01_Smooth=500_Length=100_TP=332532_FP=172810
whatifQAtrades_SDAE_PF=1.2_Profit=27447013953.5_PP=65.97_freq=1_tradesize=0.01_Smooth=600_Length=100_TP=331464_FP=170994
whatifQAtrades_SDAE_PF=1.2_Profit=22963529441.75_PP=65.72_freq=1_tradesize=0.01_Smooth=100_Length=200_TP=331773_FP=173076
whatifQAtrades_SDAE_PF=1.17_Profit=23790659466.55_PP=65.5_freq=1_tradesize=0.01_Smooth=200_Length=200_TP=336169_FP=177035
whatifQAtrades_SDAE_PF=1.17_Profit=24303021213.8_PP=65.51_freq=1_tradesize=0.01_Smooth=300_Length=200_TP=334265_FP=175962
whatifQAtrades_SDAE_PF=1.18_Profit=25439141483.15_PP=65.54_freq=1_tradesize=0.01_Smooth=400_Length=200_TP=334190_FP=175750
whatifQAtrades_SDAE_PF=1.19_Profit=27360164418.65_PP=65.75_freq=1_tradesize=0.01_Smooth=500_Length=200_TP=337621_FP=175866
whatifQAtrades_SDAE_PF=1.17_Profit=27445995139.35_PP=65.49_freq=1_tradesize=0.01_Smooth=600_Length=200_TP=338051_FP=178145
whatifQAtrades_Peg_PF=1.05_Profit=7349564747_PP=63.13_freq=1_tradesize=0.01_Smooth=600_Length=200_TP=359971_FP=210249

so it seems no big impact on PF, just number of trades cut in half (TP+FP).

as the price data was 1 min but maybe trends are more visible on higher TF i made small modification to simulate 15M TF. I changed

Data(i-1) to Data(i-16) in MMI caclulation function but also not impact....

Code:

whatifQAtrades_Peg_PF=1.06_Profit=6456268137.3_PP=63.63_freq=1_tradesize=0.01_Smooth=600_Length=200_TP=375900_FP=214844
whatifQAtrades_SDAE_PF=1.17_Profit=27481160172.8_PP=65.71_freq=1_tradesize=0.01_Smooth=600_Length=200_TP=349375_FP=182356

So it looks that this method of filtering does not improve or worsen the performance, the timing of filtering seems to be completely random. In next step I will try to make more detailed filtering to see the impact on different symbols, maybe any of them has more 'trendy' characteristics. However this type of selection will introduce higher variance of final result (less trades) and selection bias so it will be risky to say if any improvement in performance is real.

and here is a link to original trades files. If someone has an idea how to filter them to improve their performance let me know. I know already Hidden Markov Models method to switch between regimes but i think this method is not much better than ordinary MA cross.

https://www.mediafire.com/?2bcrqpb3boh23w9
Krzysztof