Stock Data Pages | TCA League Tables | About

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

Pub: 04.12.17

| By Anonymous

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))
nvdaret <- monthlyReturn(Ad(NVDA))
amdret <- monthlyReturn(Ad(AMD))
returns <- cbind(btcnret, tslaret, nvdaret, amdret)
colnames(returns) <- c('BitcoinUSD', 'TSLA', 'NVDA', 'AMD')
returns <- head(returns, -1)
returns <- as.timeSeries(returns)
frontier <- portfolioFrontier(returns)
png(filename = "btc_plot_stocks_frontier.png")
plot(frontier, which = "all")
png(filename = "btc_plot_stocks_weights.png")
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')

Bitcoin and Stocks Frontier

Bitcoin and Stocks Weights

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(
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)

Bitcoin and Stocks Covariance Estimate Weights

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

You can also jump to each section directly from here: