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.
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