Talk:Using open source software for portfolio analysis

From finiki, the Canadian financial wiki

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)
            xiu         xbb       xre       gld
xiu  1.00000000 -0.07174554 0.6165985 0.3090652
xbb -0.07174554  1.00000000 0.2208214 0.1644747
xre  0.61659853  0.22082135 1.0000000 0.0768836
gld  0.30906520  0.16447469 0.0768836 1.0000000
      sd   min  max  skew kurtosis
xiu 0.04 -0.17 0.13 -0.75     1.59
xbb 0.01 -0.03 0.05 -0.14     0.47
xre 0.04 -0.23 0.14 -1.36     6.13
gld 0.06 -0.16 0.13 -0.19     0.06
RplotCorr.png

--Peculiar Investor 08:44, 18 February 2021 (MST)