shortening code & variance ratio

2 views (last 30 days)
Martin
Martin on 5 Feb 2013
I am very new to Matlab. I have five matrices, each containing five column vectors of data, which are returns of five different stocks over a period of 50 year. The matrices are named monthly, (1962-2011), monthlya1, (1962,1974), monthlya2, (1974,1986), monthlya3,(1986-1999) and monthlya4, (1999-2011).
I need to calculate the variance ratio for each stock and for different periods given above. Here is the formula we are given: VR(3) is the variance of returns that are 3 periods apart divided buy 3 times variance of return. In other words; VR(3) = var[r(t)+r(t-2)] / [3*var(r(t))];
Here is the long formula I wrote, but I am thinking that there might be a smart and short way of doing this. Any idea is welcomed..
VR2=[
var(monthly(2:end,1)+monthly(1:end-1,1))/(3*var(monthly(2:end,1)));
var(monthlya1(2:end,1)+monthlya1(1:end-1,1))/(3*var(monthlya1(2:end,1)));
var(monthlya2(2:end,1)+monthlya2(1:end-1,1))/(3*var(monthlya2(2:end,1)));
var(monthlya3(2:end,1)+monthlya3(1:end-1,1))/(3*var(monthlya3(2:end,1)));
var(monthlya4(2:end,1)+monthlya4(1:end-1,1))/(3*var(monthlya4(2:end,1)));
var(monthly(2:end,2)+monthly(1:end-1,2))/(3*var(monthly(2:end,2)));
var(monthlya1(2:end,2)+monthlya1(1:end-1,2))/(3*var(monthlya1(2:end,2)));
var(monthlya2(2:end,2)+monthlya2(1:end-1,2))/(3*var(monthlya2(2:end,2)));
var(monthlya3(2:end,2)+monthlya3(1:end-1,2))/(3*var(monthlya3(2:end,2)));
var(monthlya4(2:end,2)+monthlya4(1:end-1,2))/(3*var(monthlya4(2:end,2)));
var(monthly(2:end,3)+monthly(1:end-1,3))/(3*var(monthly(2:end,3)));
var(monthlya1(2:end,3)+monthlya1(1:end-1,3))/(3*var(monthlya1(2:end,3)));
var(monthlya2(2:end,3)+monthlya2(1:end-1,3))/(3*var(monthlya2(2:end,3)));
var(monthlya3(2:end,3)+monthlya3(1:end-1,3))/(3*var(monthlya3(2:end,3)));
var(monthlya4(2:end,3)+monthlya4(1:end-1,3))/(3*var(monthlya4(2:end,3)));
var(monthly(2:end,4)+monthly(1:end-1,4))/(3*var(monthly(2:end,4)));
var(monthlya1(2:end,4)+monthlya1(1:end-1,4))/(3*var(monthlya1(2:end,4)));
var(monthlya2(2:end,4)+monthlya2(1:end-1,4))/(3*var(monthlya2(2:end,4)));
var(monthlya3(2:end,4)+monthlya3(1:end-1,4))/(3*var(monthlya3(2:end,4)));
var(monthlya4(2:end,4)+monthlya4(1:end-1,4))/(3*var(monthlya4(2:end,4)));
var(monthly(2:end,5)+monthly(1:end-1,5))/(3*var(monthly(2:end,5)));
var(monthlya1(2:end,5)+monthlya1(1:end-1,5))/(3*var(monthlya1(2:end,5)));
var(monthlya2(2:end,5)+monthlya2(1:end-1,5))/(3*var(monthlya2(2:end,5)));
var(monthlya3(2:end,5)+monthlya3(1:end-1,5))/(3*var(monthlya3(2:end,5)));
var(monthlya4(2:end,5)+monthlya4(1:end-1,5))/(3*var(monthlya4(2:end,5)))];

Answers (0)

Community Treasure Hunt

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

Start Hunting!