I downloaded some stock data:
require("quantmod")
s <- c("AAPL", "ADBE", "ADI", "ADP", "ADSK")
e <- new.env()
getSymbols(s, src='yahoo', from='2015-01-10', env = e )
#get closing prices
close <- do.call(merge, eapply(e, function(x) Cl(x)))
I found all the pairs of symbol names:
#find all the pairwise permutations
perm<-combn(s,2)
perm
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] "AAPL" "AAPL" "AAPL" "AAPL" "ADBE" "ADBE" "ADBE" "ADI" "ADI" "ADP"
[2,] "ADBE" "ADI" "ADP" "ADSK" "ADI" "ADP" "ADSK" "ADP" "ADSK" "ADSK"
I'd like to take the "close" data for each name and replace for each pair group of "perm" to be able to analyse the pairs later.
If you wanted to get a list of data frames, one for each pair, you could try:
Now you can get the 2-column data frames for each pair with
dfs[[1]]
,dfs[[2]]
, etc. You can perform statistical analyses on each pair using thelapply
function. Here's a simple example where you get the summary of every paired data frame: