Source code example, what is source code and what is the output?
I'm trying to understand, specifically what is source code and what is output produced in the Asset correlation section.
The current coding (expanded for ease of reading here) is:
Asset correlation in R
Source code
library(quantmod)# make sure you have library installed
#download data from yahoo
getSymbols(c("XIU.TO","XBB.TO","XRE.TO","GLD"),src='yahoo', from="2000-01-01")
#merge adjusted columns into one data frame
returns<-merge(monthlyReturn(XIU.TO$XIU.TO.Adjusted),
monthlyReturn(XBB.TO$XBB.TO.Adjusted),
monthlyReturn(XRE.TO$XRE.TO.Adjusted),
monthlyReturn(GLD$GLD.Adjusted))
#put normal names
names(returns)<-c("xiu","xbb","xre","gld")
#show correlation matrix using only rows with all (complete) data
cor(returns, use="complete.obs")
library(psych) #has a good stats function
describe(returns)[,c(4,8,9,11,12)]# choose the columns
#scatterplots to visualize correlation
pairs(~xiu+xbb+xre+gld, data = returns, upper.panel = NULL)