R is fun

[This article was first published on logopt: a journey in R, finance and open source, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

As mentioned in Universal portfolio, part 6, the wealth reported in Table 8.4 of Universal Portfolios could not be reproduced.  An other observation is that the random weight vectors reported in Table 8.4 are shown in descending lexicographic order, except for the last one, suggesting possibly that there is an error in the original table.

R code allows to perform a simple experiment, take subsets of the full set of weights and check if we can reproduce the reported wealth.  Explicitly we’ll try all subsets that exclude from 1 to 7 values in the original set.  This shows the expressive power of R, and how fast modern computers operate.  The whole search only takes a few line of codes and execute very fast even if this entails computing the mean of 280,599 different subsets.

As it turns out, two different subsets with 18 elements match the reported wealth, a surprising result.  No other subsets match.  The code below must be appended after the code used in Universal portfolio, part 6.


# remove selected entries to try to get the published value of 98.4240
# R is fun and modern computers are fast
BestAppr <- 0
nPruned <- 0
nC <- length(crps)
cat(“\n”)
for (m in seq(nC-1, nC-7)) {
CrpPruned <- combn(crps, m, mean)
        nPruned <- nPruned + length(CrpPruned)
Best <- min(abs(CrpPruned - 98.4240))
cat(sprintf(“Min delta from Cover with %d samples is %.4f\n”, m, Best))
}
cat(sprintf(“\n%d different subsets tried\n”, nPruned))
cat(“\n Subsets matching the wealth reported in Table 8.4\n”)


# so at least one subset of 18 samples match the published value, show them
Indices <- combn(1:22,18)
for (i in 1:(dim(Indices)[2])) {
PrunedMean <- mean(crps[Indices[,i]])
if (abs(PrunedMean – 98.4240) < 0.0001) {
cat(Indices[,i])
cat(sprintf(”  %.5f\n”,PrunedMean)) 
}
}

This gives the following output

Min delta from Cover with 21 samples is 2.3056
Min delta from Cover with 20 samples is 0.0398
Min delta from Cover with 19 samples is 0.0116
Min delta from Cover with 18 samples is 0.0000
Min delta from Cover with 17 samples is 0.0003
Min delta from Cover with 16 samples is 0.0008
Min delta from Cover with 15 samples is 0.0002

280599 different subsets tried

Subsets matching the wealth reported in Table 8.4

1 2 3 4 5 6 9 10 11 12 13 14 15 17 19 20 21 22  98.42403
1 2 3 4 5 6 9 11 12 13 14 15 17 18 19 20 21 22  98.42403

To leave a comment for the author, please follow the link and comment on their blog: logopt: a journey in R, finance and open source.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)