Info
This question is closed. Reopen it to edit or answer.
How to code conducting tests to different time periods?
1 view (last 30 days)
Show older comments
Hi!
Im trying to conduct a ttest and ftest on a dataset using a movingsum as an signal on the dataset, and I want the months used in the sum to go from 2-15 and test for each one of these periods. I started to duplicate the code for n=2 to fit n=3, but thought that there might be a more clever way to do this. Does anyone know of one? If you look at the code below, you should get the idea. NOTE; I also want to gather all the results from the tests in 2 matrices, so I can easily access these.
Any help would be greatly greatly appreciated as it would save me alot of time! Thanks in advance!
load austrial.txt % load the data matrix from the file
mkt = austrial(:,2); % market return in the second column
w = log(1 + mkt/100)
numElementsToSum = 2;
mSum = conv(w, ones(numElementsToSum, 1), 'valid');
movsum = mSum(1:end-1);
returns = mkt(numElementsToSum+1:end)
Buytwo=returns(movsum>0);
Selltwo=returns(movsum<0);
ExRetBuytwo = mean(Buytwo)
ExRetSelltwo = mean(Selltwo)
StdBuytwo = std(Buytwo)
StdSelltwo = std(Selltwo)
[h,ptwomean] = ttest2(Buytwo,Selltwo,0.05,'right','unequal');
[h,ptwovar] = vartest2(Buytwo,Selltwo,0.05,'left');
numElementsToSum = 3;
mSum = conv(w, ones(numElementsToSum, 1), 'valid');
movsumthree = mSum(1:end-1);
returns = mkt(numElementsToSum+1:end)
Buythree=returns(movsumthree>0);
Sellthree=returns(movsumthree<0);
ExRetBuythree = mean(Buythree)
ExRetSellthree = mean(Sellthree)
StdBuythree = std(Buythree)
StdSellthree = std(Sellthree)
[h,pthreemean] = ttest2(Buytthree,Sellthree,0.05,'right','unequal');
[h,pthreevar] = vartest2(Buythree,Sellthree,0.05,'left');
pmean= [ptwomean,pthreemean]
pvar= [ptwovar,pthreevar]
0 Comments
Answers (1)
Walter Roberson
on 29 Dec 2012
Guessing here about which values you wish to save:
nvals = 2:15;
for nidx = 1 : length(nvals)
numElementsToSum = nvals(nidx);
mSum = conv(w, ones(numElementsToSum, 1), 'valid');
movsum = mSum(1:end-1);
returns = mkt(numElementsToSum+1:end)
Buytwo=returns(movsum>0);
Selltwo=returns(movsum<0);
ExRetBuytwo = mean(Buytwo)
ExRetSelltwo = mean(Selltwo)
StdBuytwo = std(Buytwo)
StdSelltwo = std(Selltwo)
[h, ptwomean(nidx)] = ttest2(Buytwo,Selltwo,0.05,'right','unequal');
[h, ptwovar(nidx)] = vartest2(Buytwo,Selltwo,0.05,'left');
end
plot(nvals, ptwomean, 'b', nvals, ptwovar, 'g:')
1 Comment
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!