require(matrixStats) require(tidyr) require(ggplot2) m02 <- matrix( rnorm(250*100000, 0.0002, 0.0125), ncol = 250 ) dfprod <- matrix(0,nrow=100000,ncol = 5) %>% as.data.frame colnames(dfprod) <- c("etf1x","etf2x","etf3x","etf2x_cost","etf3x_cost") dfprod$etf1x <- (m02 + 1) %>% rowProds dfprod$etf2x <- (m02*2 + 1) %>% rowProds dfprod$etf3x <- (m02*3 + 1) %>% rowProds dfprod$etf2x_cost <- (m02*2 + 1 - 0.00006) %>% rowProds dfprod$etf3x_cost <- (m02*3 + 1 - 0.00008) %>% rowProds long_prod <- gather(dfprod) long_prod$value <- long_prod$value-1 ggplot(long_prod, aes(x=value, fill=key)) + geom_density(alpha=.3)+xlim(-1,2) median(dfprod$etf1x) mean(dfprod$etf1x) sd(dfprod$etf1x) exp(mean(log(dfprod$etf1x)))