library(ggplot2)
library(Data)
library(scrAndFun)
library(dplyr)
outdir = "C:/Users/Soren Schwartz/Dropbox/Egne dokumenter/Skole/master/opgave/Figures"
#### Data manupulation ####
coinList.xts <- list(
BitCoinYahoo.xts = xts::xts(BitCoinYahoo[,2:7], order.by = BitCoinYahoo[,1]),
BitCashYahoo.xts = xts::xts(BitCashYahoo[,2:7], order.by = BitCashYahoo[,1]),
EthereumYahoo.xts = xts::xts(EthereumYahoo[,2:7], order.by = EthereumYahoo[,1]),
RippleYahoo.xts = xts::xts(RippleYahoo[,2:7], order.by = RippleYahoo[,1])
)
MSCI.xts <- list(
days = xts::xts(MSCI_DP[,2], order.by = MSCI_DP[,1]),
weeks = xts::xts(MSCI_WP[,2], order.by = MSCI_WP[,1]),
months = xts::xts(MSCI_MP[,2], order.by = MSCI_MP[,1])
)
dailyExcess <- Log_Period_Vol(listCoins = coinList.xts, listIndex = MSCI.xts,
period = "days",
delta = 60/61, annu = 365.25,
dateRange = list(
BitCoin = "2013/",
BitCash = "2017-08-01/",
Ethereum = "2016-02-01/",
Ripple = "2014-01-01/",
Cum = "2013/"
))
## Random walk of prices
coinList.xts$BitCoinYahoo.xts$`BTC-USD.Adjusted`
Prices <- do.call(cbind, lapply(coinList.xts, quantmod::Ad)) %>%
dplyr::as_tibble() %>%
mutate(Date = zoo::index(coinList.xts$BitCoinYahoo.xts),
RW = cumsum(rnorm(length(XRP.USD.Adjusted)))) %>%
filter(!is.na(BCH.USD.Adjusted)) %>%
transmute(BTC = (BTC.USD.Adjusted - mean(BTC.USD.Adjusted)) / sd(BTC.USD.Adjusted),
BCH = (BCH.USD.Adjusted - mean(BCH.USD.Adjusted)) / sd(BCH.USD.Adjusted),
ETH = (ETH.USD.Adjusted - mean(ETH.USD.Adjusted)) / sd(ETH.USD.Adjusted),
XRP = (XRP.USD.Adjusted - mean(XRP.USD.Adjusted)) / sd(XRP.USD.Adjusted),
RW = (RW - mean(RW)) / sd(RW),
Date = Date)
Prices[,1:5] <- apply(Prices[,1:5], 2, function(x) {x - x[1]})
Prices_tidy <- tidyr::gather(Prices, key = "Process", value = "Standardized value", - Date)
pdf(file = paste0(outdir, "/random_walk_comparison.pdf"),
height = 6, width = 8)
ggplot(Prices_tidy, aes(x = Date, y = `Standardized value`, col = Process)) +
geom_line(size = 0.7) +
theme_classic() +
labs(title = "Prices processes compared to random walk",
caption = "Processes are standardized") +
ggplot2::scale_color_manual(values = c(RColorBrewer::brewer.pal(5,"Set1")))
dev.off()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.