R is fun

June 30, 2012

(This article was first published on logopt: a journey in R, finance and open source, and kindly contributed to R-bloggers)

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)
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(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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Mango solutions

plotly webpage

dominolab webpage

Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training





CRC R books series

Six Sigma Online Training

Contact us if you wish to help support R-bloggers, and place your banner here.

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)