LATEST DATA

Column

Since the 3rd halving (2020-06-16 01:00:00) - (2020-07-27 19:00:00)

HISTORICAL DATA

Column

BTC - (2011-09-13 - 2020-05-09) Source: bitstampUSD Avg. Buys

SAMPLE-1 OSP ANALYSIS

Column

SAMPLE-1 Between first and second halving (2011-09-13 - 2016-05-08)

SAMPLE-2 OSP ANALYSIS

Column

SAMPLE-2 Between second and third halving (2016-05-09 - 2020-05-10)

About

Bitcoin Dashboard

This dashboard is built with R using the R Markdown framework by Bcogan.

Latest Data

Bitcoin USD value (Binance API. BTCUSDT) with 1 hour intervals since the last halving. The data is updated daily.

Historical Data

Bitcoin USD value (bitstampUSD Avg. Buys) with 1 day intervals for the time period 2011-09-13 - 2020-05-09.

Sample-1 OSP Analysis

Optimal stopping analysis conducted on bitstampUSD data for the time period 2011-09-13 - 2016-05-08 (Between first and second halving).

Sample-2 OSP Analysis

Optimal stopping analysis conducted on bitstampUSD data for the time period 2016-05-09 - 2020-05-10 (Between second and third halving).

---
title: "BTC"
author: "Bcogan"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code: embed
    vertical_layout: fill
    #runtime: shiny
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
#---------Packages-------
library(RJSONIO)
library(flexdashboard)
library(dplyr)
library(xts)
library(dygraphs)
library(readxl)
library(httr)
library(jsonlite)
library(devtools)
library(binancer)
library(googledrive)
library(writexl)
library(usethis)
#---------Current Data----------
#Get data from Binance on the most recent exchanges
fivemin <- binance_klines('BTCUSDT', interval = '5m',limit = 1000, start_time =  as.POSIXct("2020-05-10 21:00:00"), end_time = as.POSIXct(Sys.time()))
hourly <- binance_klines('BTCUSDT', interval = '1h', limit = 1000, end_time = as.POSIXct(Sys.time()))
daily <- binance_klines('BTCUSDT', interval = '1d', limit = 1000, start_time =  as.POSIXct("2020-05-09 21:00:00"))
usdtry <- binance_klines('USDTTRY', interval = '1h', limit = 1000, start_time =  as.POSIXct("2020-05-10 21:00:00"), end_time = as.POSIXct(Sys.time()))
#The data to plot
fivemin_plot <- binance_klines('BTCUSDT', interval = '5m',limit = 1000,start_time =  as.POSIXct("2020-05-10 21:00:00"), end_time = as.POSIXct(Sys.time()))
hourly_plot <- binance_klines('BTCUSDT', interval = '1h',limit = 1000, end_time = as.POSIXct(Sys.time()))
#filter volume columns
usdtry <- usdtry %>%
  select(open_time,	open,	high,	low,	close, close_time)%>%
  mutate(id = row_number())
daily <- daily %>%
  select(open_time,	open,	high,	low,	close, close_time)%>%
  mutate(id = row_number())
fivemin <- fivemin %>%
  select(open_time,	open,	high,	low,	close,close_time)
hourly <- hourly %>%
  select(open_time,	open,	high,	low,	close, close_time)%>%
  mutate(usdtr_high = usdtry$high,
         id = row_number(),
         max_btcusd = ifelse(test= (id ==1), yes= max(high), no =""),
         max_usdtry = ifelse(test= (id ==1), yes= max(usdtr_high), no ="")
         )

#BTC bought
bought_btc <- data.frame ("date_bought"=c(as.POSIXct("2020-05-11 22:04:11")), "unit_price" = c(8763.61))

# #-------------Output files---------------
 #Create a csv output and write the data on it
 #write.csv(hourly,"C:/Users/baris/OneDrive/Documents/R/Binance/hourly.csv", row.names = FALSE)
 write_xlsx(hourly,"C:/Users/baris/OneDrive/Documents/R/Binance/hourly.xlsx")
 write_xlsx(fivemin,"C:/Users/baris/OneDrive/Documents/R/Binance/fivemin.xlsx")
 write_xlsx(daily,"C:/Users/baris/OneDrive/Documents/R/Binance/daily.xlsx")
# 
# #upload to Drive/Binance
   binance_fivemin <- drive_upload(("fivemin.xlsx"), path ="Binance",overwrite = TRUE, "fivemin.xlsx")
   binance_hourly <- drive_upload(("hourly.xlsx"), path ="Binance",overwrite = TRUE, "hourly.xlsx")
   binance_daily <- drive_upload(("daily.xlsx"), path ="Binance",overwrite = TRUE, "daily.xlsx")
# # binance_test <- drive_cp(
# #   fivemin,
# #   name = "fivemin",mime_type = drive_mime_type("spreadsheet"))

#------------Historical data osp analysis-------
 daily <- read.csv(file = 'C:/Users/baris/OneDrive/Documents/R/osp/daily.csv')
 daily_halveone <- read.csv(file = 'C:/Users/baris/OneDrive/Documents/R/osp/daily_halveone.csv')
 daily_halvetwo <- read.csv(file = 'C:/Users/baris/OneDrive/Documents/R/osp/daily_halvetwo.csv')
 daily_halveone_tm <- read.csv(file = 'C:/Users/baris/OneDrive/Documents/R/osp/daily_halveone_tm.csv')
 daily_halvetwo_tm <- read.csv(file = 'C:/Users/baris/OneDrive/Documents/R/osp/daily_halvetwo_tm.csv')
 
#population (total days) for the first and second halving period
 population_two <- nrow(daily_halvetwo)
 population_one <- nrow(daily_halveone)
```

LATEST DATA
=======================================================================


Column {data-height=800}
-------------------------------------


### **Since the 3rd halving (`r  min(hourly_plot$open_time)`) - (`r  max(hourly_plot$open_time)`) **

```{r,echo = FALSE}
#plot open value and time
y_2 <- list( tickfont = list(color = "orange"), overlaying ="y", title="Volume", side ="right")
plotly::plot_ly(data = hourly_plot) %>%
  plotly::add_trace(
    x = ~open_time,
    y = ~open,
    type = "scatter",
    mode = "lines+markers",
    name = "BTCUSDT",
    marker = list(size=2)
  # )%>%
  # plotly::add_trace(x = bought_btc$date_bought, 
  #      y = bought_btc$unit_price, 
  #      type = "scatter",
  #      mode = "markers",
  #      name = "BTC bought",
  #      marker = list(color = "red", size=5)
  ) %>%
  # plotly::add_annotations(
  #  x = as.POSIXct("2020-05-11 22:04:11"),
  #  y = 8763.61,
  #  text = paste("Bought BTC (8763.61$/1BTC)"),
  #  xref = "x",
  #  yref = "y",
  #  #arrowhead = 5,
  #  #arrowhead = 3,
  #  #arrowsize = 1,
  #  showarrow = TRUE,
  #  #ax = -90,
  #  #ay = -90,
  #  font=list(size=10)
  # )%>%
  plotly::add_trace(
    x = ~open_time,
    y = ~volume,
    type = "bar",
    name = "Volume", yaxis = "y2",opacity =0.5,
    marker = list(color = "orange", size=3)
    )%>%
  plotly::layout(
    title = "BTC value and Volume- 1h. intervals (Binance BTCUSDT) ",yaxis2=y_2,
    yaxis = list(title = "USD"),
    xaxis = list(type='date', title = ""),
    #tickformat="%B %d"
    legend = list(), showlegend= FALSE,
    hovermode = "compare"
  )
```

HISTORICAL DATA
=======================================================================


Column {data-height=800}
-------------------------------------


### **BTC - (2011-09-13 - 2020-05-09) Source: bitstampUSD Avg. Buys**
```{r,echo = FALSE}

plotly::plot_ly(data = daily) %>%
  plotly::add_trace(
    x = ~date,
    y = ~m_value,
    type = "scatter",
    mode = "lines+markers",
    name = "BTC USDBuy",
    marker = list(size=2)
  )%>%
plotly::layout(
    title = "",
    yaxis = list(title = "USD"),
    xaxis = list(type='date', title = "",dtick=86400000*90),
    #tickformat="%B %d"
    legend = list(),
    hovermode = "compare"
  )
```

SAMPLE-1 OSP ANALYSIS
=======================================================================


Column {data-height=800}
-------------------------------------


### **SAMPLE-1 Between first and second halving (2011-09-13 - 2016-05-08)**
```{r,echo = FALSE}
plotly::plot_ly(data = daily_halveone) %>%
  plotly::add_trace(
    x = ~date,
    y = ~m_value,
    type = "scatter",
    mode = "lines+markers",
    name = "BTC USDBuy",
    marker = list(size=2)
  )%>%
  plotly::add_annotations(
     x = as.Date("2013-11-30"),
     y = 1140, #= 1133.712
     showarrow=TRUE,
     text = paste(
       "Maximum BTC value 1133.7$ (2013-11-30)"
    ,sep="
" ), xref = "x", yref = "y",font=list(color = "green") ) %>% plotly::add_segments(x = as.Date("2014-03-29"), xend = as.Date("2014-03-29"), y = 0, yend = 1200,opacity =0.5 )%>% plotly::add_segments(x = as.Date("2013-11-29"), xend = as.Date("2013-11-29"), y = 0, yend = 1200,opacity =0.5 )%>% plotly::add_annotations( x = as.Date("2013-11-29"), y = 10, showarrow=TRUE, text = paste( "Optimal stopping (27.8%), 2013-11-29" ,sep="
" ), xref = "x", yref = "y",font=list(color = "green") ) %>% plotly::add_annotations( x = as.Date("2014-03-29"), y = 10, showarrow=TRUE, ax = 20, ay = -60, text = paste( "Stopping at 37%, 2014-03-29" ,sep="
" ), xref = "x", yref = "y",font=list(color = "orange") ) %>% plotly::add_annotations( x = as.Date("2016-07-08"), y = 650, #646.431 showarrow=TRUE, ax = -90, ay = -90, text = paste( "BTC value if stopping at 37%, 2016-07-08" ,sep="
" ), xref = "x", yref = "y",font=list(color = "orange") ) %>% plotly::layout( title = "", yaxis = list(title = "USD"), xaxis = list(type='date',dtick=86400000*60, title = ""), showlegend = FALSE, #tickformat="%B %d" legend = list(), hovermode = "compare" ) ``` SAMPLE-2 OSP ANALYSIS ======================================================================= Column {data-height=800} ------------------------------------- ### **SAMPLE-2 Between second and third halving (2016-05-09 - 2020-05-10)** ```{r,echo = FALSE} plotly::plot_ly(data = daily_halvetwo) %>% plotly::add_trace( x = ~date, y = ~m_value, type = "scatter", mode = "lines+markers", name = "BTC USDBuy", marker = list(size=2) )%>% plotly::add_annotations( x = as.Date("2017-12-17"), y = 19200, #(19197.79) showarrow=TRUE, text = paste( "Maximum BTC value 19197.8$ (2017-12-17)" ,sep="
" ), xref = "x", yref = "y",font=list(color = "green") ) %>% plotly::add_segments(x = as.Date("2017-12-10"), xend = as.Date("2017-12-10"), y = 0, yend = 19500, opacity =0.5 )%>% plotly::add_segments(x = as.Date("2017-12-16"), xend = as.Date("2017-12-16"), y = 0, yend = 19500, opacity =0.5 )%>% plotly::add_annotations( x = as.Date("2017-12-16"), y = 90, showarrow=TRUE, ax = 30, ay = -70, text = paste( "Optimal stopping (37.5%), 2017-12-16" ,sep="
" ), xref = "x", yref = "y",font=list(color = "green") ) %>% plotly::add_annotations( x = as.Date("2017-12-10"), y = 90, ax = -20, ay = -30, showarrow=TRUE, text = paste( "Stopping at 37%, 2017-12-10" ,sep="
" ), xref = "x", yref = "y",font=list(color = "orange") ) %>% plotly::add_annotations( x = as.Date("2017-12-10"), y = 16823, #16822.18, ax = -20, ay = -30, showarrow=TRUE, text = paste( "BTC value if stopping at 37%, 2017-12-12" ,sep="
" ), xref = "x", yref = "y",font=list(color = "orange") ) %>% plotly::layout( title = "", yaxis = list(title = "USD"), xaxis = list(type='date',title = "", dtick=86400000*60),showlegend = FALSE, #tickformat="%B %d" legend = list(), hovermode = "compare" ) ``` About ======================================================================= **Bitcoin Dashboard** This dashboard is built with R using the R Markdown framework by [Bcogan](https://github.com/Bcogan0/){target="_blank"}. **Latest Data** Bitcoin USD value (Binance API. BTCUSDT) with 1 hour intervals since the last halving. The data is updated daily. **Historical Data** Bitcoin USD value (bitstampUSD Avg. Buys) with 1 day intervals for the time period 2011-09-13 - 2020-05-09. **Sample-1 OSP Analysis** Optimal stopping analysis conducted on bitstampUSD data for the time period 2011-09-13 - 2016-05-08 (Between first and second halving). **Sample-2 OSP Analysis** Optimal stopping analysis conducted on bitstampUSD data for the time period 2016-05-09 - 2020-05-10 (Between second and third halving).