-
Notifications
You must be signed in to change notification settings - Fork 36
/
Bitwise analysis and portfolios.R
79 lines (63 loc) · 2.86 KB
/
Bitwise analysis and portfolios.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
library(corrplot)
library(tidyverse)
library(PerformanceAnalytics)
library(tibbletime)
library(tidyquant)
library(quantmod)
#This script is analyzing the performance and risk contribution for adding Bitwise 10 cryptoasset
#index to a stanard portfolio
#set the class Date for importing csv file
setClass('myDate')
setAs("character","myDate", function(from) as.Date(from, format = "%m/%d/%y"))
Bitwise10 <- read.csv(file.choose(),
colClasses = c('myDate',
'numeric'),
header = TRUE)
#convert to an xts class for calculations
Bitwise10 <- na.omit(Bitwise10)
Bitwise10_xts <- as.xts(Bitwise10[,2], order.by = Bitwise10$Date)
head(Bitwise10_xts)
colnames(Bitwise10_xts) <- "Bitwise 10"
#get ETFs as asset class proxies
symbols <- c("VT","LQD","GLD","GSG","IEF","RWO","HYG","EEM")
start <- "2017-10-02"
end <- "2019-08-31"
getSymbols(symbols, from = start, to = end)
#merge the data and then calculate the returns while removing NAs
returns <- merge(VT[,6],
LQD[,6],
GLD[,6],
GSG[,6],
IEF[,6],
RWO[,6],
HYG[,6],
EEM[,6],
Bitwise10_xts) %>% Return.calculate() %>% na.omit()
colnames(returns) <- c("VT", "LQD", "GLD", "GSG", "IEF", "RWO", "HYG", "EEM", "Bitwise 10")
#create correlogram and correlation matrix
Asset_corr <- cor(returns)
corrplot(Asset_corr,
method = "circle", type = "lower", order = "alphabet",
tl.cex = .8, cl.cex = .8, number.cex = .8)
#create weights to put into portfolio rebalance function
weights_8 = rep(1/8, times = 8)
weights_9 = rep(1/9, times = 9)
weights_10 = c(rep(.96/8, times =8),.04)
standard_portfolio_equal <- Return.portfolio(returns[,c(1:8)], weights = weights_8,
rebalance_on = "months")
portfolio_equal_Bitwise <- Return.portfolio(returns[,c(1:9)], weights = weights_9,
rebalance_on = "months")
portfolio_equal_Bitwise_04 <- Return.portfolio(returns, weights = weights_10,
rebalance_on = "months")
portfolios <- merge(standard_portfolio_equal,
portfolio_equal_Bitwise_04,
portfolio_equal_Bitwise)
colnames(portfolios) <- c("Equal Weight ex-Bitwise",
"Equal Weight ETF and 4% Bitwise",
"Equal Weight ETF and Bitwise")
chart.CumReturns(portfolios, legend.loc = "topleft", main = "Crypotassets and Your Portfolio")
table.AnnualizedReturns(portfolios)
table.DrawdownsRatio(portfolios)
chart.CumReturns(returns, legend.loc = "topright", main = "Cumulative performance of Bitwise 10 vs. ETFs")
SortinoRatio(portfolios)
chart.Drawdown(returns, legend.loc = "bottomleft", main = "Cumulative performance of Bitwise 10 vs. ETFs")