trading rule return how do we calculate it??

2 views (last 30 days)
jean
jean on 27 Dec 2013
Answered: jean on 9 Jan 2014
Hi,
I am running trading rules and wonder how to calculate the return. I have read in the papers but still confusing. They multiply the return by the indicator we get from the rules which are -1,1 or zero. In this case we do not take the holding period into the account.
what I was doing is after getting the buy/sell signals, get the holding period by changing the values of zeros after 1 to 1 till -1 where changes the zeros to -1 till 1 and so on so for. I was looking to the indicator only to indicate the days of buy and sell but I did not multiply them. so I only rely on the return series for the stock to calculate the return.
for example if I have return as follow:
0.2, 3.2, -0.2, -.0785 and signals as follow:
1 0 -1 0 I change them to holding period as follow:
1 1 -1 -1 and the return will be the sum of the return series above: 0.2+3.2-0.2-0.785 but as I understood from the papers is as follow:
multply the return series by the signals as follow:
1* 0.2 + 0*3.2 +(-1-0.2)+ 0*0.785
how do we calculate the return please please please????
thanks
  2 Comments
Image Analyst
Image Analyst on 27 Dec 2013
I don't understand the English for "changing the values of zeros after 1 to 1 till -1 where changes the zeros to -1 till 1 and so on so for." Can you explain that better. Your one example is confusing. So if you have a 0 after a 1, then you change the 0 into a 1. I got that, and that's why [1 0] turned into [1 1] (the first two elements). But I don't know what the rest of the sentence means "till -1 where changes the zeros to -1 till 1 and so on so for." That's where I'm really confused.
jean
jean on 28 Dec 2013
Hi
will give an example:
if I have return series or stock as follow:
0.14 0.64 -0.24 -0.125 0.12 0.3 0.1 0.1458 -0.15 1.24 and signals as follow: 0 1 0 0 0 -1 0 0 1 0 0 0 0 -1 0 0 0 0 1 do we need to change the signals to holding period as I did as follow: 0 1 1 1 1 -1 -1 -1 1 1 1 1 1 -1 -1 -1 -1 -1 1 and after that use these values to indicate the sell/buy signals or do we multiply them by return series? so the return for the rules be: (0 1 1 1 1 -1 -1 -1 1 1 1 1 1 -1 -1 -1 -1 -1 1 )* 0.14 0.64 -0.24 -0.125 0.12 0.3 0.1 0.1458 -0.15 1.24 0.3 0.54 0.6 0.87 0.69 0.1) But the paper was doing as follow: (0 1 0 0 0 -1 0 0 1 0 0 0 0 -1 0 0 0 0 1)* 0.14 0.64 -0.24 -0.125 0.12 0.3 0.1 0.1458 -0.15 1.24 0.3 0.54 0.6 0.87 0.69 0.1.
so dowe confert the value of 0 to 1 or -1 depending to what oming after it or just look to orginal values 0 1 -1?

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 28 Dec 2013
Can you do this:
returnSeries = [0.14 0.64 -0.24 -0.125 0.12 0.3 0.1 0.1458 -0.15 1.24]
signals = [0 1 0 0 0 -1 0 0 1 0 0 0 0 -1 0 0 0 0 1]
index = 1
signalsOut = signals; % Initialize.
while index < length(signals)
if signals(index) == 1 || signals(index) == -1
% It's 1 or -1, so continue that number until we hit the next 1 or -1
valueToPropagate = signals(index); % a 1 or -1
index = index+1;
while signals(index) == 0
signalsOut(index) = valueToPropagate;
index = index+1;
end
else
% No match
index = index + 1;
end
end
signalsOut % Print to command window
product = returnSeries .* signalsOut
The only problem is that the return series example you gave doesn't have the same number of elements as your signal.

jean
jean on 9 Jan 2014
Hi, I have these codes:
result=zeros(1,12) avedata=mean(turkeyreturn); vardata=var(turkeyreturn); N=length(turkeyreturn); for h=1:14;
A=TRBB(:,h);
BB=[A turkeyreturn A.*turkeyreturn ];
% FF=BB(0== sum(isnan(BB), 2), :);
%R(:,h)=BB((100:end),2);
y1=0;y2=0; z1=length(find(A==1)); z2=length(find(A==-1));
for k=1:length(BB) if BB(k,1)==1 y1=BB(k,3)+y1; elseif BB(k,1)==-1 y2=BB(k,2)+y2; end end
for n=length(BB)
% BB=BB(0== sum(isnan(BB), 2), :); BB=BB(isfinite(BB(:, 1)), :) column=(BB(1:end,2)) summ= sum(BB(1:end,2)) av=summ/n annualav=av*256 standard=std(column) sharpe=((annualav-rf)/standard) end
aveofones=y1/z1; aveofmione=y2/z2; buy_sell=(aveofones-aveofmione);
T_one=(aveofones-avedata)/(sqrt((vardata/N)+(vardata/z1))); T_min1=(aveofmione-avedata)/(sqrt((vardata/N)+(vardata/z2))); T_both=(aveofones-aveofmione)/(sqrt((vardata/z1)+(vardata/z1)));
% R(:,h)=FF(:,3); result(h,:)=[z1,z2,aveofones,aveofmione,buy_sell,T_one,T_min1,T_both,av,annualav, standard,sharpe]
end
how do I save the the second col um BB matrix so that I can get all the results in for loap. additionally there are some NaN values in the third column. how can I remove these row with matching cell in the first and second column please from BB matrix and save them after all.The number of NaN is different in each loap.
thanks jean

Categories

Find more on Financial Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!