Uncertainty analysis: Gold vs. Bitcoin | R-Bloggers

Uncertainty analysis: Gold vs. Bitcoin | R-Bloggers

[This article was first published on DataGeeek, and kindly contributed to R-bloggers]. (You can report problems here about the content on this page)


Do you want to share your content on R-bloggers? Click here if you have a blog, or here If you don’t.

Deutsche Bank Research Institute stated in its published report that Bitcoin has undergone a process that is comparable to what Gold has experienced in the last 100 years.

According to the report, the increasing acceptance of Bitcoin and reduced volatility can convert into a reserve resistant that central banks could keep by 2030.

The uncertainty graph below confirms the above -mentioned analysis. Especially in the past two years, Gold and Bitcoin have been merged into terms of monthly return distribution.

Graphic Code:

library(tidyverse)
library(tidyquant)
library(ggdist)

#Gold
df_gold <- 
  tq_get("GC=F") %>% 
  tq_transmute(select = close,
            mutate_fun = periodReturn,
            period = "monthly",
            col_rename = "gold_returns") %>% 
  drop_na()

#Bitcoin
df_btc <- 
  tq_get("BTC-USD") %>% 
  tq_transmute(select = close,
               mutate_fun = periodReturn,
               period = "monthly",
               col_rename = "btc_returns") %>% 
  drop_na()

#Merging the datasets
df_merged <- 
  df_gold %>% 
  left_join(df_btc) %>% 
  filter(date >= as.Date("2020-01-01")) %>% 
  drop_na() %>% 
  pivot_longer(-date) %>% 
  mutate(year = year(date) %>% as_factor())


#Uncertainty Distribution Plot
df_merged %>% 
  ggplot(aes(y = value, 
             x = year,
             fill =  name)) +
  stat_slab(aes(thickness = after_stat(pdf*n)), scale = 0.7) +
  stat_dots(side = "bottom", 
            scale = 0.7, 
            slab_linewidth = NA) +
  scale_y_continuous(labels = scales::percent) +
  scale_fill_manual(values = c("darkorange","goldenrod")) +
  labs(x = "",
       y = "", 
       fill = "",
       title = "Comparison of Monthly Returns: Gold vs. Bitcoin") +
  theme_minimal(base_family = "Roboto Slab",
                base_size = 20) +
  theme(axis.text = element_text(face = "bold"),
        plot.title = ggtext::element_markdown(size =  18, 
                                              hjust = 0.5,
                                              face = "bold"),
        axis.text.x = element_text(angle = 45, 
                                   hjust = 1, 
                                   vjust = 1),
        legend.position = "none",
        plot.background = element_rect(fill = "azure", color = "azure"),
        panel.background = element_rect(fill = "snow", color = "snow"))


#Uncertainty #analysis #Gold #Bitcoin #RBloggers

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *