IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Exploratory Data Analysis: Will PCE Data Push Bitcoin?

    Selcuk Disci发表于 2024-10-07 09:00:00
    love 0
    [This article was first published on DataGeeek, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
    Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

    Could the latest PCE data catalyze Bitcoin to surge beyond major resistance and reach $70K? The last time that US PCE Price Index values were under the estimates (miss), BTC prices rocketed.

    Source code:

    library(tidyverse)
    library(tidyquant)
    library(timetk)
    
    #U.S. PCE Price Index YoY
    df_pce_yoy <- 
      read.delim("https://raw.githubusercontent.com/mesdi/investingcom/refs/heads/main/us_pce_yoy.txt") %>% 
      as_tibble() %>% 
      janitor::clean_names() %>% 
      rename(date = release_date) %>% 
      #removing parentheses and the text within
      mutate(date = case_when(str_detect(date," \\(.*\\)") ~ str_remove(date," \\(.*\\)"),
                              TRUE ~ date)) %>% 
      mutate(date = parse_date(date, "%b %d, %Y"),
             actual = str_remove(actual, "%") %>% as.numeric(),
             forecast = str_remove(forecast, "%") %>% as.numeric()) %>% 
      mutate(date = floor_date(date, "month") %m+% months(1),
             type = case_when(
               actual > forecast ~ "Beat",
               actual < forecast ~ "Miss",
               actual == forecast ~ "In Line"
             )) %>% 
      select(date, type) %>% 
      drop_na()
    
    
    #Bitcoin USD (BTC-USD)
    df_bitcoin <- 
      tq_get("BTC-USD") %>% 
      tq_transmute(select = "close",
                   mutate_fun = to.monthly,
                   col_rename = "btc") %>% 
      mutate(date = as.Date(date))
    
    #Merging the datasets
    df_merged <- 
      df_pce_yoy %>% 
      left_join(df_bitcoin) %>% 
      drop_na()
    
    
    #Plot
    df_merged %>% 
      ggplot(aes(date, 
                 btc, 
                 color = type)) +
      geom_line(aes(group = 1), size =2) +
      geom_point(size = 5) +
      geom_hline(yintercept = 70000, 
                 size = 1.5, 
                 color = "red", 
                 linetype = "dashed") +
      scale_x_date(expand = expansion(mult = c(.1, .1)),
                   labels = scales::label_date("%Y %b"),
                   breaks = c(make_date(2023,10,1),
                              make_date(2024,1,1),
                              make_date(2024,9,1))) +
      scale_y_continuous(labels = scales::label_dollar()) +
      scale_color_manual(values = c("In Line" = "darkgrey",
                                    "Beat" = "indianred",
                                    "Miss" = "darkgreen")) +
      labs(x= "",
           y ="", 
           color = "Core PCE Estimates",
           title = "Bitcoin USD (Monthly)",
           subtitle = "In the case of the (YoY) PCE values <span style = 'color:indianred;'><br>beat</span>, <span style = 'color:darkgreen;'>miss,</span> or <span style = 'color:darkgrey;'>in line</span> with the estimates") +
      theme_minimal(base_size = 20,
                    base_family = "Bricolage Grotesque") +
      theme(panel.grid = element_blank(),
            legend.position = "none",
            plot.title = element_text(face = "bold"),
            plot.subtitle = ggtext::element_markdown(face = "bold"),
            axis.text = element_text(face = "bold"),
            plot.background = element_rect(fill = "ghostwhite", 
                                           color = "ghostwhite"),
            panel.background = element_rect(fill = "azure", 
                                            color = "azure"))
    
    To leave a comment for the author, please follow the link and comment on their blog: DataGeeek.

    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.
    Continue reading: Exploratory Data Analysis: Will PCE Data Push Bitcoin?


沪ICP备19023445号-2号
友情链接