Apr 2016Jul 2016Oct 2016Jan 2017Apr 2017Jul 2017Oct 201702k4k6k8k10k
DateBitcoin Price - USD
# Set libPaths.
.libPaths("/Users/kannishida/.exploratory/R/3.4")

# Load required packages.
library(janitor)
library(lubridate)
library(hms)
library(tidyr)
library(stringr)
library(readr)
library(forcats)
library(RcppRoll)
library(dplyr)
library(tibble)
library(exploratory)

# Steps to produce gtrend_bitcoin
`gtrend_bitcoin` <- exploratory::read_delim_file("/Users/kannishida/Dropbox/Data/gtrend-bitcoin.csv" , ",", quote = "\"", skip = 2 , col_names = TRUE , na = c('','NA') , locale=readr::locale(encoding = "UTF-8", decimal_mark = "."), trim_ws = FALSE , progress = FALSE) %>% exploratory::clean_data_frame() %>%
  mutate(Month = str_c(Month, "-01"), Month = ymd(Month)) %>%
  rename(`GTrend - Bitcoin` = `Bitcoin: (Worldwide)`)

# Steps to produce bitcoin_miners_revenue
`bitcoin_miners_revenue` <- load_quandl('BCHAIN/MIREV', 'wide') %>% readr::type_convert() %>% exploratory::clean_data_frame() %>%
  rename(Revenue = Value)

# Steps to produce the output
load_quandl('BCHARTS/BITSTAMPUSD', 'wide') %>% readr::type_convert() %>% exploratory::clean_data_frame() %>%
  rename(`Bitcoin Price - USD` = `Weighted Price`) %>%
  left_join(bitcoin_miners_revenue, by = c("Date" = "Date")) %>%
  mutate(date_month = floor_date(Date, "month")) %>%
  left_join(gtrend_bitcoin, by = c("date_month" = "Month")) %>%
  mutate(gtrend = `GTrend - Bitcoin`) %>%
  filter(Date >= as.Date("2016-01-10") & `Bitcoin Price - USD` > 0)