**logopt: a journey in R, finance and open source**, and kindly contributed to R-bloggers)

Part 8 was discussing the distribution of the absolute wealth of the Universal Portfolio across all possible tuples of length 2, 3 and 4.

However, comparing the absolute wealth against some reference, especially against simple portfolio selection algorithm provides a better view of the exact performance of the Universal algorithm. Because we want to compute and compute multiple references, the code uses functions to be more generic. The code remains terse (88 lines, including comments) and could be even terser.

Writing the code in this fashion shows again the strength of R, some specific aspects used here:

- Passing functions as parameters of other functions
- Using frames to access information outside the function scope, including assigning new values.
- Use of … to write variadic functions (I am still learning that, the current code works but is not elegant)
- Use of ::: to access non exported functions from a package

The first graph shows the final wealth of Universal versus the final wealth of the best stock in the tuple. Contrary to the absolute wealth, the relative wealth decreases as the number of stocks in the tuple increases and is also generally significantly less than 1. The red curve shows that for about 70% of the 4-tuples, Universal final wealth is below the wealth of the best stock in the tuple.

Obviously, it is impossible to know in advance which stock will have the best final wealth, so the comparison is slightly unfair. The next two comparisons however are against two of the simplest causal selection algorithms:

- Equally weighted buy and hold, UBH for short, U for uniform
- Equally weighted Constant Rebalanced Portfolio, usually UCRP for Uniform CRP. This one is interesting as Universal itself is based on a weighted combination of all CRP.

- Universal generally loses to UCRP (around 90% of the time) and sometimes pretty badly
- Increasing the tuple size increases the relative performance when UCRP is better than Universal and decreases the performance when the opposite is true.

**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...