3
$\begingroup$

I have a data set containing equity price information on a tick by tick basis. I would like to calculate the correlation in R, which isn't a hassle. But the vectors are of different length due to one equity being traded more than the other.

I can aggregate on a minute basis, but this also leaves the vectors of inequal length due to trades not occuring each minute for each equity.

I guess it boils down to a statisical question. Can I calculate the correlation with different vector length given they sample the same time period? I thought about inputting the previous price in the empty time minute slots to achieve equal vector length, but perhaps there is a different approach?

I am using R.

Thanks


Thank you for your answers. I have looked into the proposed solutions, and I think an upsampling / downsampling will be best in this case.

Is there a way to code the following in R? My hunch is an if loop that will check the corresponding data frame if the time is present if not then it will grabthe previous price and input a new price for the missing time.

This is what I would like to produce:

Two seperate colums, price and time, for each equity. If the time is present for equity X but not equity Y then the previous price should put into the vector. As per the following example:

X           Y   
price   time        price   time
10  540     20  540
11  541     21  541
12  542     22  543
13  544     23  544
14  545     24  545

price   time        price   time
10  540     20  540
11  541     21  541
12  542     21  542
12  543     22  543
13  544     23  544
14  545     24  545
$\endgroup$

migrated from stackoverflow.com Jan 3 '13 at 16:15

This question came from our site for professional and enthusiast programmers.

2
$\begingroup$

You can upsample the smaller vector or downsample the lager one.

Then use the standard correlation function.

$\endgroup$
  • $\begingroup$ It would be nice to know here which one is preferred method in statistical sense and in practice. $\endgroup$ – Léo Léopold Hertz 준영 Nov 1 '16 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.