<jupyter_start><jupyter_text>Evaluates Anomalities in Bitcoin time serieUsing 'Anomaly Detection', in R, Bitcoin price, in US Dollar (US$), was evaluated in three scenarios.1. Period between January 2016 throughout 2018 (present);2. Period between January 2017 throughout 2018 (present);3. Period of 2018.  Install and load required libraries<jupyter_code>if(!require("coindeskr")) install.packages("coindeskr")
if(!require("anomalize")) install.packages("anomalize")
if(!require("tidyverse")) install.packages("tidyverse")

library(anomalize) #tidy anomaly detectiom
library(tidyverse) #tidyverse packages like dplyr, ggplot, tidyr
library(coindeskr) #bitcoin price extraction from coindesk<jupyter_output>Loading required package: coindeskr
Loading required package: anomalize
Loading required package: tidyverse
-- Attaching packages --------------------------------------- tidyverse 1.2.1 --
v ggplot2 2.2.1     v purrr   0.2.4
v tibble  1.4.2     v dplyr   0.7.4
v tidyr   0.8.0     v stringr 1.3.0
v readr   1.1.1     v forcats 0.3.0
-- Conflicts ------------------------------------------ tidyverse_conflicts() --
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()<jupyter_text>Two years length analysis Data import (2016-present)<jupyter_code># Bitcoin present comparing to 2016 |- 2017
btc <- get_historic_price(start = "2016-01-01")

btc_ts <- btc %>% rownames_to_column() %>% as.tibble() %>% 
  mutate(date = as.Date(rowname)) %>% select(-one_of('rowname'))

windows(width = 720, height = 320)

btc_ts %>% 
  time_decompose(Price, method = "stl", frequency = "auto", trend = "auto") %>%
  anomalize(remainder, method = "gesd", alpha = 0.05, max_anoms = 0.2) %>%
  plot_anomaly_decomposition() 

windows(width = 720, height = 320)
  
btc_ts %>% 
  time_decompose(Price) %>%
  anomalize(remainder) %>%
  time_recompose() %>%
  plot_anomalies(time_recomposed = TRUE, ncol = 3, alpha_dots = 0.5)  

btc_ts %>% 
  time_decompose(Price) %>%
  anomalize(remainder) %>%
  time_recompose() %>%
  filter(anomaly == 'Yes')<jupyter_output>Converting from tbl_df to tbl_time.
Auto-index message: index = date
frequency = 7 days
trend = 91 days<jupyter_text>Two years length analysis Data import (2017-present)<jupyter_code># Bitcoin present comparing to 2017
rm(btc, btc_ts)

btc <- get_historic_price(start = "2017-01-01")

btc_ts <- btc %>% rownames_to_column() %>% as.tibble() %>% 
  mutate(date = as.Date(rowname)) %>% select(-one_of('rowname'))

windows(width = 720, height = 320)

btc_ts %>% 
  time_decompose(Price, method = "stl", frequency = "auto", trend = "auto") %>%
  anomalize(remainder, method = "gesd", alpha = 0.05, max_anoms = 0.2) %>%
  plot_anomaly_decomposition() 

windows(width = 720, height = 320)
  
btc_ts %>% 
  time_decompose(Price) %>%
  anomalize(remainder) %>%
  time_recompose() %>%
  plot_anomalies(time_recomposed = TRUE, ncol = 3, alpha_dots = 0.5)  

btc_ts %>% 
  time_decompose(Price) %>%
  anomalize(remainder) %>%
  time_recompose() %>%
  filter(anomaly == 'Yes')<jupyter_output>Converting from tbl_df to tbl_time.
Auto-index message: index = date
frequency = 7 days
trend = 90.5 days<jupyter_text>2018 analysis Data import (2018-present)<jupyter_code># Bitcoin present (2018)
rm(btc, btc_ts)

btc <- get_historic_price(start = "2018-01-01")

btc_ts <- btc %>% rownames_to_column() %>% as.tibble() %>% 
  mutate(date = as.Date(rowname)) %>% select(-one_of('rowname'))

windows(width = 720, height = 320)

btc_ts %>% 
  time_decompose(Price, method = "stl", frequency = "auto", trend = "auto") %>%
  anomalize(remainder, method = "gesd", alpha = 0.05, max_anoms = 0.2) %>%
  plot_anomaly_decomposition() 

windows(width = 720, height = 320)
  
btc_ts %>% 
  time_decompose(Price) %>%
  anomalize(remainder) %>%
  time_recompose() %>%
  plot_anomalies(time_recomposed = TRUE, ncol = 3, alpha_dots = 0.5)  

btc_ts %>% 
  time_decompose(Price) %>%
  anomalize(remainder) %>%
  time_recompose() %>%
  filter(anomaly == 'Yes')<jupyter_output>Converting from tbl_df to tbl_time.
Auto-index message: index = date
frequency = 7 days
trend = 54 days
{'fraction_non_alphanumeric': 0.16471734892787523, 'fraction_numerical': 0.04312865497076023, 'mean_word_length': 4.401315789473684, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '306220', 'license': 'MIT', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1459, 'n_words': 340, 'path': 'Other/Evaluates Anomalities in Bitcoin time serie.ipynb', 'repo_name': 'isix/R', 'size': '4104'}