HT 在数据框中创建一个新向量,该向量采用现有向量的相关性
我有两个指数的时间序列,每一行代表同一天的收盘价。我想转到第 30 行并回顾过去 30 天并计算皮尔逊相关性。然后将该值存储在一个新向量中。然后,对整个时间序列重复计算。
这在 Excel 中是一项微不足道的任务,所以我相信它可以在 R 中完成。但我不知道要使用的方法。
I have a time series of two indexes, with each row representing the closing price on the same day. I'd like to go to row 30 and lookback over the last 30 'days' and calculate the pearson correlation. And then store that value in a new vector. Then, repeat the calculation for the entire time series.
It is a trivial task in Excel, so I'm convinced it can be done in R. I don't know the method to use though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有很多方法可以做到这一点(与 R 中的所有内容一样)。我始终建议在处理时间序列数据时使用时间序列。
zoo
包可能是最流行的时间序列包(尽管您也可以查看其他包,例如 xts、timeSeries、its、fts):您还可以找到
chart.RollingCorrelationPerformanceAnalytics
包中的 code> 函数很有用。There are many ways to do this (as with everything in R). I always recommend using a time series when working with time series data.
The
zoo
package is probably the most popular time series package (although you can also look at others such as xts, timeSeries, its, fts):You may also find the
chart.RollingCorrelation
function in thePerformanceAnalytics
package useful.