Bootstrap Confidence Intervals: Exports in Japan
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Japanese Finance Minister Shunichi Suzuki recently said that the volatility in USD/JPY rates negatively impacts the price competition and even damages the profit of the exporters in Japan. To examine this claim, first, we will look at the movement of the exports of goods and services in Japan, Nikkei 225, and exchange rates together.
library(tidyverse) library(tidymodels) library(tidyquant) library(timetk) library(modeltime) #Quarterly change (%) of USD/JPY exchange rates #https://finance.yahoo.com/quote/JPY%3DX/ df_usdjpy <- tq_get("JPY=x", to = "2024-07-01") %>% tq_transmute(select = "close", mutate_fun = to.quarterly) %>% tq_transmute(mutate_fun = periodReturn, period = "quarterly", col_rename = "usd_jpy") #Quarterly change (%) of exports of goods and services in Japan #https://fred.stlouisfed.org/series/JPNEXPORTQDSNAQ df_exports <- tq_get("JPNEXPORTQDSNAQ", get = "economic.data") %>% select(date, exports = price) %>% mutate(date = as.yearqtr(date), exports = exports / lag(exports) - 1) %>% drop_na() #Quarterly change (%) of Nikkei 225 #https://finance.yahoo.com/quote/%5EN225/ df_nikkei <- tq_get("^N225", to = "2024-07-01") %>% tq_transmute(select = "close", mutate_fun = to.quarterly) %>% tq_transmute(mutate_fun = periodReturn, col_rename = "nikkei225") #Merging series df_merged <- df_exports %>% left_join(df_usdjpy) %>% left_join(df_nikkei) #Change of quarterly % df_merged %>% pivot_longer(-date, names_to = "vars") %>% filter(date >= 2021) %>% mutate(type = case_when( vars == "exports" ~ "Exports in Japan", vars == "usd_jpy" ~ "USD/JPY", vars == "nikkei225" ~ "Nikkei 225", TRUE ~ vars )) %>% ggplot(aes(date, value, color = vars)) + geom_line(linewidth = 1.25) + geom_text( data = . %>% slice_tail(n = 1, by = type), aes(label = type), hjust = 0, vjust = 0, family = "Bricolage Grotesque", nudge_x = 0.05, size = 5 ) + scale_y_continuous(labels = scales::percent) + scale_x_yearqtr(format = "%Y Q%q", expand = expansion(mult = c(0, .3))) + labs(x = "", y = "", subtitle = "Change of quarterly %") + theme_minimal(base_family = "Bricolage Grotesque", base_size = 16) + theme(legend.position = "none", panel.grid.minor = element_blank())
When we look at the chart above, we can say that exchange rates and exports diverged in the opposite direction in the last quarter, but this still shows no evidence of a relationship between them. To examine whether there is a significant effect of the exchange rate on exports, we will use bootstrap confidence intervals.
#Bootstrap confidence intervals set.seed(12345) jpn_intervals <- reg_intervals(exports ~ usd_jpy, data = df_merged, model_fn = "glm", keep_reps = TRUE) jpn_intervals %>% unnest(.replicates) %>% ggplot(aes(estimate, fill = term)) + geom_vline(xintercept = 0, size = 1.5, lty = 2, color = "gray50") + geom_histogram(alpha = 0.8, show.legend = FALSE) + labs(x = "", y = "", subtitle = "The distribution includes zero which means there is no significant effect", title = "The estimated effect of USD/JPY rates on exports in Japan") + theme_minimal(base_family = "Bricolage Grotesque") + theme(axis.text = element_text(size = 16), plot.title = element_text(size = 16))
According to our simulation results, there seems no significant effect of USD/JPY exchange rates on exports of goods and services in Japan.
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.