Correlation Analysis of Silver, Bitcoin, SOXX, and Blockchain Index with {corrr} package

Silver, Nasdaq Blockchain Economy Index, Bitcoin, and iShares Semiconductor ETF are always thought of as correlated with each other by investors.

We will test this perception with the corrr package.

#iShares Semiconductor ETF (SOXX)
df_soxx <- 
  tq_get(x = "SOXX") %>% 
  select(date, soxx = close)

#Silver Futures
df_silver <- 
  tq_get("SI=F") %>%
  select(date, silver = close)

#Nasdaq Blockchain Economy Index
df_nasdaq_blockchain <- 
  openxlsx::read.xlsx("https://github.com/mesdi/investingcom/raw/refs/heads/main/nasdaq_blockchain.xlsx",
                      sheet = "History",
                      detectDates = TRUE) %>% 
  as_tibble() %>% 
  janitor::clean_names() %>%
  select(date = trade_date, blcn = index_value)

#Bitcoin
df_btc <- 
  tq_get("BTC-USD") %>% 
  select(date, btc = close)


#Merging the datasets
df_merged <- 
  df_silver %>% 
  left_join(df_soxx) %>% 
  left_join(df_nasdaq_blockchain) %>% 
  left_join(df_btc) %>% 
  drop_na() %>% 
  filter(date >= last(date) - months(36))

#Correlation
d <- correlate(df_merged, quiet = TRUE)

d %>% 
  focus(silver:btc, mirror = TRUE) %>%  
  fashion()

#    term silver soxx blcn  btc
#1 silver         .78  .89  .89
#2   soxx    .78       .85  .80
#3   blcn    .89  .85       .97
#4    btc    .89  .80  .97     

#Network plot
df_merged %>% 
  correlate() %>% 
  network_plot(min_cor = .7,
               legend = "full")


The common perception appears to be correct based on the correlation analysis, specifically between the Nasdaq Blockchain Economy index and Bitcoin.

2 responses to “Correlation Analysis of Silver, Bitcoin, SOXX, and Blockchain Index with {corrr} package”

  1. Henrik Avatar
    Henrik

    Hi,

    Isn’t somthing missing df_silver is never populated.

    Best regards

    Like

    1. Selcuk Disci Avatar

      Sorry, the related code chunk has been added.

      Like

Leave a reply to Henrik Cancel reply

I’m Selcuk Disci

Welcome to DataGeeek.com, dedicated to data science and machine learning with R, mostly based on financial data.

Let’s connect