Info
この質問は閉じられています。 編集または回答するには再度開いてください。
How to code conducting tests to different time periods?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Walter Roberson
2012 年 12 月 29 日
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 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!