#title 종목간의 상관관계 {{{ #install.packages("magrittr") library(quantmod) library(PerformanceAnalytics) library(magrittr) options("getSymbols.warning4.0"=FALSE) options("getSymbols.yahoo.warning"=FALSE) #tiger 200, KOSEF 국고채10년, KODEX 골드선물(H), TIGER 부동산인프라고배당 symbols = c("102110.KS", "148070.KS","132030.KS", "329200.KS") getSymbols(symbols, from= "2019-01-01", to = "2020-08-25",warnings = FALSE, auto.assign = TRUE, src="yahoo") prices = do.call(cbind, lapply(symbols, function(x) Ad(get(x)))) %>% setNames(symbols) rets = Return.calculate(prices) %>% na.omit() head(rets) library(tidyr) library(dplyr) library(corrplot) cor(rets) %>% corrplot(method = 'color', type = 'upper', addCoef.col = 'black', number.cex = 0.7, tl.cex = 0.6, tl.srt=45, tl.col = 'black', col = colorRampPalette(c('blue', 'white', 'red'))(200), mar = c(0,0,0.5,0)) covmat = cov(rets) }}} attachment:종목간의상관관계/stock_cor.png