Visualizing the Daily Variability of Bitcoin with Quandl and Highcharts
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Lay your dreams, little darling, in a flower bed; let that sunshine in your hair (Where the skies are blue, The Lumineers)
I discovered this nice visualization some days ago. The author is also the creator of Highcharter, an incredible R wrapper for Highcharts javascript libray and its modules. I am a big fan of him.
Inspired by his radial plot, I did a visualization of the daily evolution of Daily Bitcoin exchange rate (BTC vs. EUR) on Localbtc. Data is sourced from here and I used Quandl to obtain the data frame. Quandl is a marketplace for financial and economic data delivered in modern formats for today’s analysts. There is a package called Quandl to interact directly with the Quandl API to download data in a number of formats usable in R. You only need to locate the data you want in the Quandl site. In my case data are here.
After loading data, I do the folowing steps:
- Filtering data to obtain last 12 complete months
- Create a new variable with the difference between closing and opening price of Bitcoin (in Euros)
- Create a color variable to distinguish between positive and negative differences
- Create the graph using Fivethirtyeight theme for highcharts
This is the result:
Apart of its appealing, I think is a good way to to have a quick overview of the evolution of a stock price. This is the code to do the experiment:
library(Quandl)
library(dplyr)
library(highcharter)
library(lubridate)
bitcoin=Quandl("BCHARTS/LOCALBTCEUR")
bitcoin %>%
arrange(Date) %>%
mutate(tmstmp = datetime_to_timestamp(Date)) -> bitcoin
last_date=max(bitcoin$Date)
if (day(last_date+1)==1) date_to=last_date else
date_to=ymd(paste(year(last_date), month(last_date),1, sep="-"))-1
date_from=ymd(paste(year(date_to)-1, month(date_to)+1,1, sep="-"))
bitcoin %>% filter(Date>=date_from, Date<=date_to) -> bitcoin
var_bitcoin <- bitcoin %>%
mutate(Variation = Close - Open,
color = ifelse(Variation>=0, "green", "red"),
y = Variation) %>%
select(x = tmstmp,
y,
variation = Variation,
name = Date,
color,
open = Open,
close = Close) %>%
list.parse3()
x <- c("Open", "Close", "Variation")
y <- sprintf("{point.%s}", tolower(x))
tltip <- tooltip_table(x, y)
hc <- highchart() %>%
hc_title(text = "Bitcoin Exchange Rate (BTC vs. EUR)") %>%
hc_subtitle(text = "Daily Variation on Localbtc. Last 12 months")%>%
hc_chart(
type = "column",
polar = TRUE) %>%
hc_plotOptions(
series = list(
stacking = "normal",
showInLegend = FALSE)) %>%
hc_xAxis(
gridLineWidth = 0.5,
type = "datetime",
tickInterval = 30 * 24 * 3600 * 1000,
labels = list(format = "{value: %b}")) %>%
hc_yAxis(showFirstLabel = FALSE) %>%
hc_add_series(data = var_bitcoin) %>%
hc_add_theme(hc_theme_538()) %>%
hc_tooltip(useHTML = TRUE,
headerFormat = as.character(tags$small("{point.x:%d %B, %Y}")),
pointFormat = tltip)
hc
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.