# Analyzing Bitcoin in R - Part 12 - Evaluating a portfolio, stocks and Bitcoin

Pub: 04.12.17

In Finance.

Tags: coding r bitcoin analysis .

Let's do the same thing as in the previous section, but with multiple stocks instead of an index. These are some of the most held stocks by individuals according to online source.

getSymbols("TSLA", src = "yahoo", from = as.Date(firstdate), to = as.Date(lastdate))
getSymbols("NVDA", src = "yahoo", from = as.Date(firstdate), to = as.Date(lastdate))
getSymbols("AMD", src = "yahoo", from = as.Date(firstdate), to = as.Date(lastdate))

tslaret <- monthlyReturn(Ad(TSLA))

returns <- cbind(btcnret, tslaret, nvdaret, amdret)
colnames(returns) <- c('BitcoinUSD', 'TSLA', 'NVDA', 'AMD')
returns <- as.timeSeries(returns)
frontier <- portfolioFrontier(returns)
png(filename = "btc_plot_stocks_frontier.png")
plot(frontier, which = "all")
dev.off()
png(filename = "btc_plot_stocks_weights.png")
weightsPlot(frontier)
dev.off()
out <- minvariancePortfolio(returns, constraints = "LongOnly")
store <- out@portfolio@portfolio$weights out <- maxratioPortfolio(returns, constraints = "LongOnly") store <- rbind(store, out@portfolio@portfolio$weights)
rownames(store) <- c('minvar', 'maxratio')


The resulting allocations would range from 3 to 9 percent into Bitcoin and the rest into TSLA, NVDA, and AMD.

         BitcoinUSD      TSLA      NVDA        AMD
minvar   0.02944844 0.2398669 0.6818332 0.04885147
maxratio 0.09466859 0.3087685 0.5965629 0.00000000


Does the structure of the covariance estimator effect the results of our portfolio optimization

estimatorlist <- c(
'covEstimator',
'kendallEstimator',
'spearmanEstimator',
'mcdEstimator',
'mveEstimator',
'covMcdEstimator',
'covOGKEstimator',
'shrinkEstimator')

png(filename = "btc_plot_stocks_covarestim.png")
par(mfrow = c(4, 2))
par(mar = c(3, 3, 4, 3))
for (i in 1:length(estimatorlist)) {
Spec <- portfolioSpec()
setEstimator(Spec) <- estimatorlist[i]
frontier <- portfolioFrontier(returns, spec = Spec)
weightsPlot(frontier)
}
dev.off()


What if you believe that our return estimates are bogus, especially related to their size and how they are correlated. Or you think more observation might help.

Well, you could decide to use Copulas or extreme value theory to help you: Copulas and extreme values with Bitcoin