小编J.W*_*W.D的帖子

滤波器相关矩阵 R

我在尝试从相关矩阵中提取数据时遇到了一些困难,我希望提取高于 0.8 且低于 0.99 的值,因为我想排除恰好为 1 的两只股票的相关性。

这是我的代码:

  #Test 

#load the packages
library(corrr)
library(ggplot2)
library(ggcorrplot)
library(dplyr)
library(quantmod)

#get the data needed
startdate <- "2001-01-03"

tickers <- c("MMM", "AA", "AXP", "T", "BAC")
portfolioprices <- NULL

for(ticker in tickers)
  portfolioprices <- cbind(portfolioprices, getSymbols(ticker, from=startdate, auto.assign=F)[,4])
colnames(portfolioprices) <- tickers

#check if there is nothing wrong with the data
print(portfolioprices)

#create a correlation matrix and plot it
correlations <- cor(as.matrix(portfolioprices))
correlations <- as.data.frame(correlations)
correlations
ggcorrplot(correlations, hc.order = TRUE, type = "lower",
           lab = TRUE) …
Run Code Online (Sandbox Code Playgroud)

r matrix correlation dataframe

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

correlation ×1

dataframe ×1

matrix ×1

r ×1