COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Rolling correlation

• Email
• Follow

I'm trying to create a rolling correlation figure for two assets using a defined window period.

I'm trying to make the function:

function RC = Rcor(asset1, asset2, window)
cmat = [asset1 asset2]; % Create correlation matrix
RC = size(window:length(cmat)); % Pre-allocate matrix to hold the rolling correlation

for i = window:length(cmat)
matx = cmat(i-window:i,1:2); % Trying to make moving 5x2 matrix from cmat
matxc = corrcoef(matx); % 2x2 Correlation matrix
RC(i) = matxc(1,2); % Pull out xy correlation value
end

I fall down when trying to index through cmat to create the matx 'moving matrix'. Currently I have the error "Subscript indices must either be real positive integers or
logicals." I appreciate the whole method i'm using for the function is probably wrong too but I haven;t got to the stage of fixing that yet as I can't work around this problem, any help/guidance/pointers much appreciated.

Kind Regards

 0
Reply Ralph 10/18/2010 10:35:04 PM

See related articles to this posting

Look at matx = cmat(i-window:i,1:2);  for the first i value, which is
window.

i-window = 0, and that's not allowed as a matrix row value.  You
probably want i-window+1.


 0
Reply ImageAnalyst 10/18/2010 11:32:02 PM

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <af464093-c43f-4035-9534-ef2f7d84b840@l35g2000vbr.googlegroups.com>...
> Look at matx = cmat(i-window:i,1:2);  for the first i value, which is
> window.
>
> i-window = 0, and that's not allowed as a matrix row value.  You
> probably want i-window+1.

Perfect, Thanks!!

 0
Reply Ralph 10/19/2010 8:33:07 AM

2 Replies
802 Views

Similar Articles

12/8/2013 3:05:26 PM
[PageSpeed]

 Reply:

Similar Artilces:

Correlation
Can someone help me around with a small problem: I have a vector z with N elements all picked from a complex Gaussian distribution with 0 mean and a given variance. In addition, Q is a NxN unitray matrix and L is NxN with all 0 elements except one arbitrary L(i,i)=1 (say L(1,1)=1 and everything else is 0). I think it is easy to show that a=z'QLQ'z follows a chi-square distribution but what if the elements of z are correlated, eg \hat z = R*z where R is the square-root of the correlation matrix. What I'm interested in is how a will change as the correlation between elements...'QLQ'z follows a > chi-square distribution but what if the elements of > z are correlated, eg \hat z = R*z where R is the square-root > of the correlation matrix. > > What I'm interested in is how a will change as the correlation > between elements of z increases. > Is it for example possible to find the disribution/simple expression > for b/a where b=(\hat z)'QLQ'(\hat z) ? > > Any help will be greatly appreciated. Thank you. If b = (\hat z)'QLQ'(\hat z) and z = R*z, then b = (\hat z)'R'QLQ'R(\hat z). Let Q_b = R'Q

correlation 404249
hi all, whether the correlation function is the cross correlation? how to find the displacement using the correlation function ?

Correlation help
Hello everyone, I am not a stats guy, however I have a project I need to finish. The null hypothesis is increase in sales of cooking gas cylinders means increase consumption/usage of cooking gas . I did a correlation between two variables "cooking gas cylinders" and gas consumption. I have monthly data points from 2006 to 2009 Sep. And I am getting negative correlation. what should be my next approach , because in my mind I know that atleast it should not be negatively correlated. Again 40 odd data points is too less to do this kind of exercise. Any ideas on how go about this, and may be sales of gas cylinders may not be the real cause of increase of usage of gas, but certainly not negatively correlated. Just to add, there are 3 types of gas cylinders, the ones made in 2006 had a different technology, while the ones made in 2009 are of different technology, I did do an overall sales vs overall gas usage , and again new technology gas sales vs gas usage from new technology cylinders, again negative correlation. Now suppose people are buying 2 cylinder, or tri cylinder , that does not mean they are going to use all of them together, So I tried

Help with correlation
I am trying to correlate a loaded audio which contains different tones spaced out at 7 seconds with a kernal created with the users inputs. If I change the length of the kernal, the error in the time delay between the signals changes. How can I eliminate this? Am I finding the delay correctly? % Asks user for wavfile name, then loads wavfile. Prompts % user to enter number of tones desired with corresponding % frequencies from 300 - 3300 Hz range. Generates "kernel" % for each tone and localizes it. Plots data of localized tone clear clc % Prompts user for the si

correlation of images
hi all, I am new to IDL and this site as well, I tried to correlate set of images or two images, but I could not, I tried what Phil Plait had suggested in an old message (y1 = total(image1,1) & x1 = total(image1,2)) but I could not manage to define images.

sliding correlation and cumsum with NaN
Hi, I have some problems here, 1. What the means 'sliding correlation'? 2. If, we have data contain NaN, for example: x = [8; 6; NaN; 3; 9; NaN; 6; 2]; y = cumsum(x); Why value of y starting third line contain 'NaN'? How to removing NaN, without to change size a matrix? and how to calculate sliding correlation from x? 3. From (2), I also have a time : t = (0:1:7)', so have a pair t and x. How to determine correlation (t,x)? Where the result contain a size matrix (8x1), no single value? I hope, in this forum can help me. Thank you. Regards, Kate Kate, NaN... a little bit more "self-explaining" than >> x(find (isnan(x))) =3D 0 J=F6rg Dear Joerg J. Buchholz Thanks for give me comfirming "NaN" di 'cumsum'. So, how about definition of 'SLIDING CORRELATION'? Regards, Kate Sliding correlation is also known as cross correlation and also auto correlation. Look them up on google or any book on fourier transform theory. myphysics2010@yahoo.com wrote: > > > Dear Joerg J. Buchholz > > Thanks for give me comfirming "NaN" di 'cumsum'. So, how about > definition of 'SLIDING

Cross correlation in C
Did someone has experience on implementation of cross correlation in C on CCS? I want to realise the cross correlation in frequency domain by FFT. Until now the Real time FFT is done. The question is that my input signal is two random signals from two infrared sensors, how random signal is calculated by cross correlation? On 10/19/2010 1:26 AM, hyd198471 wrote: > Did someone has experience on implementation of cross correlation in C on > CCS? I want to realise the cross correlation in frequency domain by FFT. > Until now the Real time FFT is done. The question is that my input signal > is two random signals from two infrared sensors, how random signal is > calculated by cross correlation? You'll probably have better luck here by parsing this question: C and CCS are probably not pertinent to the core question so set that aside for now. That the signals are random are probably not pertinent to the core question so that that aside also. That leaves: 1) How do I do cross correlation? 2) How do I do cross correlation in the frequency domain? I don't understand: "Until now the Real time FFT is done." combined with "I

Cross correlation #3
Hi all My case is, I�ve two sequences (Gold sequences of 127 bits) g0 and g1. Sequences are module 127 (circular shift register), and I want to calculate the cross correlation and auto correlation of them. I use the matlab function xcorr, but it�s not the solution because xcorr makes the linear cross correlation, and I needed the circular cross correlation Have you any idea for help me?. Thank you very much for everything and sorry my english. V�ctor Pizarro S�nchez Dear Victor, In order to do a circular correlation you just need to remove the zero padding. Therefore, rather than editing 'xcorr' try something like this, >> ifft(X.*conj(Y)) where, X and Y correspond to X(w) and Y(w), the frequency domain versions of your two input signals, x(n) and y(n). BTW. I think that you write very well! Regards, Sanjeev. ------------------------------------------ Dr. Sanjeev Sarpal CEng, MIET Advanced Solutions Nederland website: <http://www.advancedsolutions.org>

correlation between images
Hi all, I have two images and I want to check (statistically) whether they are "the same" and show it to others so they will believe me :-). The first thing I thought of was using the Pearson correlation coefficient: R=correlate(img1,img2) However, R close to 1 doesn't necessarily means they are "the same" or in other words, img1 vs. img2 is linear. ( Some examples of R=0.8: http://upload.wikimedia.org/wikipedia/commons/b/b6/Anscombe.svg) I can off course show the scatter plot plot,img1,img2 with LADFIT(img1,img2) to draw a line through it and correlate(img1,img2) to add a correlation coefficient. I'm still not satisfied though. Does anyone use another statistical method to compare images? (I tried IDL's c_correlate but I can't figure out what the result means...) Thanks Wox Now the details of actually how to do this escape me for now. But a few ways that come to mind as statistically convincing are: - compute the cross correlation of the images in chunk showing that each chuck is cross correlated - Create a difference image and compare the fluctuation in the difference to the fluctuations of the image itself

auto-correlation.. Please Help
Dear all, I'm trying to perform auto-correlation here. The programe code and the answers are shown below ********************************************************* clc a=[2 4 6 8 10 12 14 16 18 20]; len=length(a); for i=1:len A=a(1:i) end for i1=len:-1:1 B=a(i1:10) end ********************************************************* The answers are shown below A = 1 A = 1 2 A = 1 2 3 A = 1 2 3 4 A = 1 2 3 4 5 A = 1 2 3 4 5 6 A = 1 2 3 4 5 6 7 A = 1 2 3 4 5 6 7 8 A = 1 2 3 4 5 6 7 8 9 A = 1 2 3 4 5 6 7 8 9 10 B = 10 B = 9 10 B = 8 9 10 B = 7 8 9 10 B = 6 7 8 9 10 B = 5 6 7 8 9 10 B = 4 5 6 7 8 9 10 B = 3 4 5 6 7 8 9 10 B = 2 3 4 5 6 7 8 9 10 B = 1 2 3 4 5 6 7 8 9 10 ********************************************************** Can anyone please tell me how to obtain the multiplication of A and B from the following Example? Example: a(1:1) = 1 b(10:10)=10 A.*B = 1*10 =40 a(1:2) = 1 2 b(9:10) = 9 10 A.*B = (1*9)+(2*10) = 29 a(1:3) = 1 2 3 b(8:10