knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(syslosseval) library(tidyverse) library(xtable)
total_assets_2016 <- eba_exposures_2016 %>% filter(Exposure == "Total assets") %>% select(LEI_code, Bank_name, Total_Amount) total_assets_eba_2016 <- eba_exposures_2016 %>% filter(!(Exposure %in% c("Common tier1 equity capital", "Total assets")), Country == "Total") %>% group_by(LEI_code, Bank_name) %>% summarize(Total_Amount_EBA = sum(Total_Amount, na.rm = F)) asset_sum_compare_2016 <- left_join(total_assets_2016, total_assets_eba_2016, by = c("LEI_code", "Bank_name")) %>% arrange(desc(Bank_name)) %>% mutate(abs_diff = Total_Amount_EBA - Total_Amount) %>% mutate(rel_diff = abs_diff/Total_Amount) %>% mutate(hi_lo = if_else(rel_diff > 0, "Above", "Below"))
p_2016 <- ggplot(data = asset_sum_compare_2016, mapping = aes(x = Bank_name, y = rel_diff, fill = hi_lo)) gaps_2016 <- p_2016 + geom_col() + guides(fill = FALSE) + labs(x = NULL, y = "Difference in percent", title = "Value gaps", subtitle = "Residual Position") + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) + coord_flip() ggsave(filename = "../paper/Figures/gaps_2016.png", plot = gaps_2016)
hist_residual_2016 <- ggplot(data = asset_sum_compare_2016, mapping= aes(rel_diff)) + geom_histogram(bins=15, color = "black", fill = "white", boundary = 0) + labs(x = "Percentage value gap", y = "Number of Banks") + geom_vline(xintercept = -0.084115 , color = "red", linetype = "dashed") ggsave(filename = "../paper/Figures/hist_residual_2016.png", plot = hist_residual_2016)
total_assets_2020 <- eba_exposures_2020 %>% filter(Exposure == "Total assets") %>% select(LEI_code, Bank_name, Total_Amount) total_assets_eba_2020 <- eba_exposures_2020 %>% filter(!(Exposure %in% c("Common tier1 equity capital", "Total assets")), Country == "Total") %>% group_by(LEI_code, Bank_name) %>% summarize(Total_Amount_EBA = sum(Total_Amount, na.rm = F)) %>% ungroup() asset_sum_compare_2020 <- left_join(total_assets_2020, total_assets_eba_2020, by = c("LEI_code", "Bank_name")) %>% arrange(Bank_name) %>% mutate(abs_diff = Total_Amount_EBA - Total_Amount) %>% mutate(rel_diff = abs_diff/Total_Amount) %>% mutate(hi_lo = if_else(rel_diff > 0, "Above", "Below"))
p_2020 <- ggplot(data = asset_sum_compare_2020, mapping = aes(x = Bank_name, y = rel_diff, fill = hi_lo)) gaps_2020 <- p_2020 + geom_col() + guides(fill = FALSE) + labs(x = NULL, y = "Difference in percent", title = "Value gaps", subtitle = "Residual Position") + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1, size = 0.001))+ coord_flip() ggsave(filename = "../paper/Figures/gaps_2020.png", plot = gaps_2020)
hist_residual_2020 <- ggplot(data = asset_sum_compare_2020, mapping= aes(rel_diff)) + geom_histogram(bins=15, color = "black", fill = "white", boundary = 0) + labs(x = "Percentage value gap", y = "Number of Banks") + geom_vline(xintercept = 0.11 , color = "red", linetype = "dashed") ggsave(filename = "../paper/Figures/hist_residual_2020.png", plot = hist_residual_2020)
panel_2016 <- eba_exposures_2016 %>% filter(!(Exposure %in% c("Total assets", "Common tier1 equity capital")), Country == "Total") panel_2020 <- eba_exposures_2020 %>% filter(!(Exposure %in% c("Total assets", "Common tier1 equity capital")), Country == "Total")
hist_panel_2016 <- ggplot(data = panel_2016, mapping = aes(x = Total_Amount/1000)) + geom_histogram(bins = 20, color = "black", fill = "white", boundary = 0) + facet_wrap(~Exposure) + labs(x = "Exposure in billion Euro", y = "Number of Banks") ggsave(filename = "../paper/Figures/hist_panel_2016.png", plot = hist_panel_2016)
hist_panel_2020 <- ggplot(data = panel_2020, mapping = aes(x = Total_Amount/1000)) + geom_histogram(bins = 20, color = "black", fill = "white", boundary = 0) + facet_wrap(~Exposure) + labs(x = "Exposure in billion Euro", y = "Number of Banks") ggsave(filename = "../paper/Figures/hist_panel_2020.png", plot = hist_panel_2020)
bond_indices <- sovereign_bond_indices
tsp <- ggplot(data = bond_indices, mapping = aes(x=Date, y=Value)) time_series_plot <- tsp + geom_line(aes(color = Country)) ggsave(filename = "../paper/Figures/bond_indices.png", plot = time_series_plot)
table_bonds_2016 <- average_daily_volume_sovereign %>% filter(Year == 2016) table_bonds_2020 <- average_daily_volume_sovereign %>% filter(Year == 2019)
adv_2016 <- xtable(table_bonds_2016) print(adv_2016, file = "../paper/Tables/adv_bonds_2016.txt") adv_2020 <- xtable(table_bonds_2020) print(adv_2020, file = "../paper/Tables/adv_bonds_2020.txt")
aggregate_bonds_2016 <- eba_exposures_2016 %>% filter( !(Exposure %in% c("Total assets", "Common equity tier 1 capital")), Country %in% c("DE", "ES", "GB", "FR", "IT", "JP", "US", "Total")) %>% group_by(Country) %>% summarize(Bond_Exposure = sum(Bond_Amount, na.rm = T)) tab1 <- aggregate_bonds_2016 %>% filter(Country != "Total") tot <- aggregate_bonds_2016 %>% filter(Country == "Total") %>% select(Bond_Exposure) %>% rename(Total_Bond_Exposure=Bond_Exposure) dat_2016 <- bind_cols(tab1, tot) %>% mutate(Share = Bond_Exposure/Total_Bond_Exposure) %>% select(Country, Share) bond_shares_2016 <- xtable(dat_2016) print(bond_shares_2016, file = "../paper/Tables/bond_shares_2016.txt")
aggregate_bonds_2020 <- eba_exposures_2020 %>% filter( !(Exposure %in% c("Total assets", "Common equity tier 1 capital")), Country %in% c("DE", "ES", "GB", "FR", "IT", "JP", "US", "Total")) %>% group_by(Country) %>% summarize(Bond_Exposure = sum(Bond_Amount, na.rm = T)) tab1 <- aggregate_bonds_2020 %>% filter(Country != "Total") tot <- aggregate_bonds_2020 %>% filter(Country == "Total") %>% select(Bond_Exposure) %>% rename(Total_Bond_Exposure=Bond_Exposure) dat_2020 <- bind_cols(tab1, tot) %>% mutate(Share = Bond_Exposure/Total_Bond_Exposure) %>% select(Country, Share) bond_shares_2020 <- xtable(dat_2020) print(bond_shares_2020, file = "../paper/Tables/bond_shares_2020.txt")
bond_exposures_eba_2016 <- eba_exposures_2016 %>% filter(Exposure == "Central banks and central governments", Country %in% c("DE", "ES", "FR", "IT", "JP", "GB", "US", "Total")) %>% select(LEI_code, Bank_name, Country, Bond_Amount) # We bring this into a tabular form with each row a bank and each column a country. Not every bank has an # exposure to every country and so the table will have NA for these banks, which in our context is equivalent # to a bond exposure of 0, so we substitute NA with zero. In the table we can compute a new variable "Rest_of_the_world", # which gives us the differecne of the sum of individual country exposures and the total exposure figure. bond_exposures_eba_2016_all <- bond_exposures_eba_2016 %>% pivot_wider(names_from = Country, values_from = Bond_Amount) %>% mutate_all(~ replace(., is.na(.), 0)) %>% mutate(Rest_of_the_world = Total - (DE + ES + FR + IT + JP + GB + US)) %>% select(Bank_name, DE, ES, FR, GB, IT, JP, US, Rest_of_the_world) %>% pivot_longer(!Bank_name, names_to = "Country" , values_to = "Bond_Exposure") %>% group_by(Bank_name) %>% mutate(Share = Bond_Exposure/sum(Bond_Exposure)) %>% ungroup()
hist_bond_panel_2016 <- ggplot(data = bond_exposures_eba_2016_all, mapping = aes(x = Share)) + geom_histogram(bins = 20, color = "black", fill = "white", boundary = 0) + facet_wrap(~Country) + labs(x = "Share in total bond exposure", y = "Number of Banks") hist_bond_panel_2016 ggsave(filename = "../paper/Figures/hist_bond_panel_2016.png", plot = hist_bond_panel_2016)
bond_exposures_eba_2020 <- eba_exposures_2020 %>% filter(Exposure == "Central banks and central governments", Country %in% c("DE", "ES", "FR", "IT", "JP", "GB", "US", "Total")) %>% select(LEI_code, Bank_name, Country, Bond_Amount) # We bring this into a tabular form with each row a bank and each column a country. Not every bank has an # exposure to every country and so the table will have NA for these banks, which in our context is equivalent # to a bond exposure of 0, so we substitute NA with zero. In the table we can compute a new variable "Rest_of_the_world", # which gives us the differecne of the sum of individual country exposures and the total exposure figure. bond_exposures_eba_2020_all <- bond_exposures_eba_2020 %>% pivot_wider(names_from = Country, values_from = Bond_Amount) %>% mutate_all(~ replace(., is.na(.), 0)) %>% mutate(Rest_of_the_world = Total - (DE + ES + FR + IT + JP + GB + US)) %>% select(Bank_name, DE, ES, FR, GB, IT, JP, US, Rest_of_the_world) %>% pivot_longer(!Bank_name, names_to = "Country" , values_to = "Bond_Exposure") %>% group_by(Bank_name) %>% mutate(Share = Bond_Exposure/sum(Bond_Exposure)) %>% ungroup()
hist_bond_panel_2020 <- ggplot(data = bond_exposures_eba_2020_all, mapping = aes(x = Share)) + geom_histogram(bins = 20, color = "black", fill = "white", boundary = 0) + facet_wrap(~Country) + labs(x = "Share in total bond exposure", y = "Number of Banks") hist_bond_panel_2020 ggsave(filename = "../paper/Figures/hist_bond_panel_2020.png", plot = hist_bond_panel_2020)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.