library(quantmod)
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(PerformanceAnalytics)
## 
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
## 
##     legend
library(TTR)
library(dygraphs)

Bring in weekly return data from yahoo finance about the following tickers

ticker5 <- c("SPY","VOO","VFH","VYM","VDC")
#Generate data
getSymbols(ticker5[1], auto.assign = FALSE, from = '2018-01-01') -> pos1
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be checked for
## alternate defaults.
## 
## This message is shown once per session and may be disabled by setting 
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
getSymbols(ticker5[2], auto.assign = FALSE, from = '2018-01-01') -> pos2
getSymbols(ticker5[3], auto.assign = FALSE, from = '2018-01-01') -> pos3
getSymbols(ticker5[4], auto.assign = FALSE, from = '2018-01-01') -> pos4
getSymbols(ticker5[5], auto.assign = FALSE, from = '2018-01-01') -> pos5
#Omit extra data, only focus on closing price
#VOO$VOO.Close -> VOO1
#VNQI$VNQI.Close -> VNQI2
#$VFH.Close -> VFH3
#VYM$VYM.Close -> VYM4
#VDC$VDC.Close -> VDC5
#Generate weekly return from closing prices
weeklyReturn(pos1[,4]) ->c1
weeklyReturn(pos2[,4]) ->c2
weeklyReturn(pos3[,4]) ->c3
weeklyReturn(pos4[,4]) ->c4
weeklyReturn(pos5[,4]) ->c5
#Bring everything together in one object
cbind(c1,c2,c3,c4,c5)->ticker5returns
#Rename it all again
names(ticker5returns) <- ticker5
#Inspect + visualize
cor(ticker5returns)
##           SPY       VOO       VFH       VYM       VDC
## SPY 1.0000000 0.9984358 0.8945384 0.9581968 0.8540007
## VOO 0.9984358 1.0000000 0.8934951 0.9589321 0.8536856
## VFH 0.8945384 0.8934951 1.0000000 0.9326218 0.7217453
## VYM 0.9581968 0.9589321 0.9326218 1.0000000 0.8684211
## VDC 0.8540007 0.8536856 0.7217453 0.8684211 1.0000000
dygraph(ticker5returns)