Universal portfolio, part 6

June 10, 2012
By

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

The final table in Universal Portfolios introduces leverage.  It indirectly also shows the dangers of rebalancing on margin, while Kin Ark increases 4.2 times, at 50% margin it goes to nothing.

The code below reproduces Table 8.4, again as plain text only.  For unknown reason, the wealth of the universal portfolio cannot be reproduced, while all other values do match.

# table 8.4 of Cover "Universal Portfolios"
library(logopt)
x <- nyse.cover.1962.1984
xck <- x[,c("comme","kinar")]
nDays <- dim(xck)[1]
Days <- 1:nDays

# calculate the margined sequence
r <- 0.000233 # seems to be r <- ((1+0.06) ^ (1/250)) - 1 rounded
yck <- (2 * xck) - 1 - r
xyck <- cbind(xck[,1], yck[,1], xck[,2], yck[,2])
mck <- cumprod(xyck)[nDays]

cat(sprintf("Commercial metals                       %.4f\n", mck[1,1]))
cat(sprintf("Commercial metals on margin             %.4f\n", mck[1,2]))
cat(sprintf("Kin Ark                                 %.4f\n", mck[1,3]))
cat(sprintf("Kin Ark on margin                       %.4f\n", mck[1,4]))
cat(sprintf("r = %.6f/day = 6%%/year\n",r))

# same "random" b as in Cover
b <-          c(0.8, 0.2, 0.0, 0.0) 
b <- rbind(b, c(0.8, 0.1, 0.0, 0.1))
b <- rbind(b, c(0.6, 0.1, 0.1, 0.2))
b <- rbind(b, c(0.6, 0.0, 0.4, 0.0))
b <- rbind(b, c(0.5, 0.0, 0.2, 0.3))
b <- rbind(b, c(0.4, 0.0, 0.4, 0.2))
b <- rbind(b, c(0.3, 0.5, 0.1, 0.1))
b <- rbind(b, c(0.3, 0.4, 0.1, 0.2))
b <- rbind(b, c(0.3, 0.2, 0.2, 0.3))
b <- rbind(b, c(0.3, 0.1, 0.2, 0.4))
b <- rbind(b, c(0.3, 0.0, 0.1, 0.6))
b <- rbind(b, c(0.2, 0.7, 0.0, 0.1))
b <- rbind(b, c(0.2, 0.2, 0.3, 0.3))
b <- rbind(b, c(0.1, 0.8, 0.1, 0.0))
b <- rbind(b, c(0.1, 0.5, 0.2, 0.2))
b <- rbind(b, c(0.1, 0.4, 0.2, 0.3))
b <- rbind(b, c(0.1, 0.3, 0.1, 0.5))
b <- rbind(b, c(0.1, 0.2, 0.4, 0.3))
b <- rbind(b, c(0.1, 0.1, 0.2, 0.6))
b <- rbind(b, c(0.0, 0.5, 0.4, 0.1))
b <- rbind(b, c(0.0, 0.4, 0.2, 0.4))
b <- rbind(b, c(0.2, 0.5, 0.1, 0.2))


BestValue <- 0
crps <- b[,1] * 0
for (i in 1:length(crps)) {
  crps[i] <- crp(xyck, b[i,])[nDays]
if(crps[i] > BestValue) {
BestValue <- crps[i]
BestB <- b[i,]
}
}

cat(sprintf("Sn* = %.4f                          bn* =(%.1f, %.1f, %.1f, %.1f)\n",
            BestValue, BestB[1], BestB[2], BestB[3], BestB[4]))
cat(sprintf("Best constituent stock                  %.4f\n",max(mck)))
cat(sprintf("Wealth achieved by universal portfolio  Sn^ = %.4f\n", mean(crps)))
cat(sprintf("\n         b                Sn(b)\n\n"))

for (i in 1:length(crps)) {
  cat(sprintf("(%.1f, %.1f, %.1f %.1f)     %8.4f\n",b[i,1], b[i,2], b[i,3], b[i,4], crps[i]))
}

Giving the following output

Commercial metals                       52.0203
Commercial metals on margin             19.7335
Kin Ark                                 4.1276
Kin Ark on margin                       0.0000
r = 0.000233/day = 6%/year
Sn* = 262.4021                          bn* =(0.2, 0.5, 0.1, 0.2)
Best constituent stock                  52.0203
Wealth achieved by universal portfolio  Sn^ = 108.0784

         b                Sn(b)

(0.8, 0.2, 0.0 0.0)      57.0535
(0.8, 0.1, 0.0 0.1)     148.9951
(0.6, 0.1, 0.1 0.2)     207.1143
(0.6, 0.0, 0.4 0.0)     140.7803
(0.5, 0.0, 0.2 0.3)      60.8358
(0.4, 0.0, 0.4 0.2)      47.6074
(0.3, 0.5, 0.1 0.1)     212.8928
(0.3, 0.4, 0.1 0.2)     261.0452
(0.3, 0.2, 0.2 0.3)      89.0330
(0.3, 0.1, 0.2 0.4)      19.4840
(0.3, 0.0, 0.1 0.6)       0.7700
(0.2, 0.7, 0.0 0.1)     121.0142
(0.2, 0.2, 0.3 0.3)      45.2562
(0.1, 0.8, 0.1 0.0)      67.5882
(0.1, 0.5, 0.2 0.2)     233.6328
(0.1, 0.4, 0.2 0.3)     112.6695
(0.1, 0.3, 0.1 0.5)      12.7702
(0.1, 0.2, 0.4 0.3)      19.4840
(0.1, 0.1, 0.2 0.6)       0.2354
(0.0, 0.5, 0.4 0.1)     225.2524
(0.0, 0.4, 0.2 0.4)      31.8076
(0.2, 0.5, 0.1 0.2)     262.4021

To leave a comment for the author, please follow the link and comment on his 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: 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.