2

Given a vector of stock ticker symbols:

 sp500 <- c("ABT", "ANF", "ADBE", "AMD", "AES", "AET" .. ) 

How do I find all unique combinations of these for a portfolio of N assets? So for example if N=3 I'd like to return a table/matrix:

  A1   |    A2    |    A3
--------------------------
"ABT"      "ANF"     "ABDE"
"ABT"      "AMD"     "ABDE"
"ABT"      "AMD"     "AES"
  .          .          .
  .          .          .
"YHOO"    "YUM"      "ZMH"

The order does not matter, so it's a "combination" rather than a "permutation", I believe.. I'm attempting to use R for this.

Advice on which function/method I might use for this would be much appreciated.

4

1 に答える 1

3

help.search("combination")あなたに答えを与えたでしょう:

combn(sp500,3)
于 2012-10-29T13:35:46.137 に答える