Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
library(scales)
Attaching package: 'scales'
The following object is masked from 'package:purrr':
discard
The following object is masked from 'package:readr':
col_factor
VIX
#load the data library(readxl)VIXCLS <-read_excel("00_data_raw/VIXCLS.xls", range ="A11:B60")View(VIXCLS)
Fed Funds Effective Rates
#load the data library(readxl)FEDFUNDS <-read_excel("00_data_raw/FEDFUNDS.xls", range ="A11:B60")View(FEDFUNDS)
#loading the data#1. loading country coverage so I cant later create context about which countries are covered in the dataset Sustainable_debt_monitor <-read_excel("00_data_raw/Sustainable_debt_monitor.xlsx", sheet ="Country coverage", range ="A42:D183", col_types =c("skip", "text", "text", "text"))View(Sustainable_debt_monitor)
Loading the IIF Debt Monitor dataset
here ("00_data_raw", "Sustainable_debt_monitor.xlsx") %>%excel_sheets()
[1] "Table of contents" "Country coverage"
[3] "1a_global markets - issuance" "1b_global markets - outstanding"
[5] "2a_MM by country" "2b_MM by sector"
[7] "3a_EM&FM by country" "3b_EM&FM by sector"
[9] "4a_offshore centers by country" "4b_offshore centers by sector"
[11] "5_supranationals by country" "6_outstanding amt by country "
[13] "7_Share of ESG debt issuance"
We’re going to make the data on “1a_global markets - issuance” into a cohesive dataset that we can play around with.
here("00_data_raw", "Sustainable_debt_monitor.xlsx") %>%#specify the sheet + the range of cells in excelread_excel(sheet ="1a_global markets - issuance",range ="B4:E48") %>%# rename the first column to "date"rename(date =`$ billion`) %>%# Tidy the dataset by making the column names into long formatpivot_longer(cols =-date, names_to ="geography", values_to ="issuance_bn_usd") %>%# coerce the date column into a date object using lubridate::ymd() (year-month_date)mutate(date =ymd(date)) %>%# Add a column that includes the name of this specific dataadd_column(issuance_type ="Sustainable debt (bonds and loans)")
# A tibble: 132 × 4
date geography issuance_bn_usd issuance_type
<date> <chr> <dbl> <chr>
1 2013-03-31 Mature markets 6.71 Sustainable debt (bonds and loan…
2 2013-03-31 Emerging markets 1.45 Sustainable debt (bonds and loan…
3 2013-03-31 Offshore centers 0 Sustainable debt (bonds and loan…
4 2013-06-30 Mature markets 5.46 Sustainable debt (bonds and loan…
5 2013-06-30 Emerging markets 0.670 Sustainable debt (bonds and loan…
6 2013-06-30 Offshore centers 0 Sustainable debt (bonds and loan…
7 2013-09-30 Mature markets 13.9 Sustainable debt (bonds and loan…
8 2013-09-30 Emerging markets 1.97 Sustainable debt (bonds and loan…
9 2013-09-30 Offshore centers 0 Sustainable debt (bonds and loan…
10 2013-12-31 Mature markets 17.7 Sustainable debt (bonds and loan…
# ℹ 122 more rows
There are 11 different sub-datasets on this worksheet, so let’s save ourselves some time and make a function.
# A tibble: 220 × 4
date geography issuance_bn_usd issuance_type
<date> <chr> <dbl> <chr>
1 2013-03-31 Mature markets 0 Social bonds
2 2013-03-31 Emerging markets 0 Social bonds
3 2013-03-31 Offshore centers 0 Social bonds
4 2013-03-31 Supranationals 0.136 Social bonds
5 2013-03-31 Global 0.136 Social bonds
6 2013-06-30 Mature markets 0 Social bonds
7 2013-06-30 Emerging markets 0 Social bonds
8 2013-06-30 Offshore centers 0 Social bonds
9 2013-06-30 Supranationals 0 Social bonds
10 2013-06-30 Global 0 Social bonds
# ℹ 210 more rows
Green municipal bonds
green_municipal_bonds <-process_iif_gb_issuance(range ="AY4:BD48", issuance_type ="Green municipal bonds")green_municipal_bonds
# A tibble: 220 × 4
date geography issuance_bn_usd issuance_type
<date> <chr> <dbl> <chr>
1 2013-03-31 Mature markets 0.396 Green municipal bonds
2 2013-03-31 Emerging markets 0 Green municipal bonds
3 2013-03-31 Offshore centers 0 Green municipal bonds
4 2013-03-31 Supranationals 0 Green municipal bonds
5 2013-03-31 Global 0.396 Green municipal bonds
6 2013-06-30 Mature markets 0.517 Green municipal bonds
7 2013-06-30 Emerging markets 0 Green municipal bonds
8 2013-06-30 Offshore centers 0 Green municipal bonds
9 2013-06-30 Supranationals 0 Green municipal bonds
10 2013-06-30 Global 0.517 Green municipal bonds
# ℹ 210 more rows
# A tibble: 176 × 4
date sector issuance_bn_usd issuance_type
<date> <chr> <dbl> <chr>
1 2013-03-31 Non-financial corps. 0 Green bonds
2 2013-03-31 Financial corps. 0 Green bonds
3 2013-03-31 Sovereign 0 Green bonds
4 2013-03-31 General government (ex-sov.) 0 Green bonds
5 2013-06-30 Non-financial corps. 0 Green bonds
6 2013-06-30 Financial corps. 0 Green bonds
7 2013-06-30 Sovereign 0 Green bonds
8 2013-06-30 General government (ex-sov.) 0 Green bonds
9 2013-09-30 Non-financial corps. 0 Green bonds
10 2013-09-30 Financial corps. 0 Green bonds
# ℹ 166 more rows
# A tibble: 176 × 4
date sector issuance_bn_usd issuance_type
<date> <chr> <dbl> <chr>
1 2013-03-31 Non-financial corps. 0 Social bonds
2 2013-03-31 Financial corps. 0 Social bonds
3 2013-03-31 Sovereign 0 Social bonds
4 2013-03-31 General government (ex-sov.) 0 Social bonds
5 2013-06-30 Non-financial corps. 0 Social bonds
6 2013-06-30 Financial corps. 0 Social bonds
7 2013-06-30 Sovereign 0 Social bonds
8 2013-06-30 General government (ex-sov.) 0 Social bonds
9 2013-09-30 Non-financial corps. 0 Social bonds
10 2013-09-30 Financial corps. 0 Social bonds
# ℹ 166 more rows
Municipal Bonds
green_municipal_bonds_s <-process_iif_gb_issuance_sectorEM(range ="AD4:AH48", issuance_type ="Green municipal bonds")green_municipal_bonds_s
# A tibble: 176 × 4
date sector issuance_bn_usd issuance_type
<date> <chr> <dbl> <chr>
1 2013-03-31 Non-financial corps. 0 Green municipal bonds
2 2013-03-31 Financial corps. 0 Green municipal bonds
3 2013-03-31 Sovereign 0 Green municipal bonds
4 2013-03-31 General government (ex-sov.) 0 Green municipal bonds
5 2013-06-30 Non-financial corps. 0 Green municipal bonds
6 2013-06-30 Financial corps. 0 Green municipal bonds
7 2013-06-30 Sovereign 0 Green municipal bonds
8 2013-06-30 General government (ex-sov.) 0 Green municipal bonds
9 2013-09-30 Non-financial corps. 0 Green municipal bonds
10 2013-09-30 Financial corps. 0 Green municipal bonds
# ℹ 166 more rows
# A tibble: 176 × 4
date sector issuance_bn_usd issuance_type
<date> <chr> <dbl> <chr>
1 2013-03-31 Non-financial corps. 0.421 Green loans
2 2013-03-31 Financial corps. 0.0297 Green loans
3 2013-03-31 Sovereign 0 Green loans
4 2013-03-31 General government (ex-sov.) 0 Green loans
5 2013-06-30 Non-financial corps. 0.670 Green loans
6 2013-06-30 Financial corps. 0 Green loans
7 2013-06-30 Sovereign 0 Green loans
8 2013-06-30 General government (ex-sov.) 0 Green loans
9 2013-09-30 Non-financial corps. 1.97 Green loans
10 2013-09-30 Financial corps. 0 Green loans
# ℹ 166 more rows
# A tibble: 176 × 4
date sector issuance_bn_usd issuance_type
<date> <chr> <dbl> <chr>
1 2013-03-31 Non-financial corps. 0.124 Green bonds
2 2013-03-31 Financial corps. 0.00355 Green bonds
3 2013-03-31 Sovereign 0 Green bonds
4 2013-03-31 General government (ex-sov.) 0.5 Green bonds
5 2013-06-30 Non-financial corps. 1.04 Green bonds
6 2013-06-30 Financial corps. 0.397 Green bonds
7 2013-06-30 Sovereign 0 Green bonds
8 2013-06-30 General government (ex-sov.) 0 Green bonds
9 2013-09-30 Non-financial corps. 0.268 Green bonds
10 2013-09-30 Financial corps. 0.0563 Green bonds
# ℹ 166 more rows
# A tibble: 176 × 4
date sector issuance_bn_usd issuance_type
<date> <chr> <dbl> <chr>
1 2013-03-31 Non-financial corps. 0.124 Green bonds
2 2013-03-31 Financial corps. 0.00355 Green bonds
3 2013-03-31 Sovereign 0 Green bonds
4 2013-03-31 General government (ex-sov.) 0.5 Green bonds
5 2013-06-30 Non-financial corps. 1.04 Green bonds
6 2013-06-30 Financial corps. 0.397 Green bonds
7 2013-06-30 Sovereign 0 Green bonds
8 2013-06-30 General government (ex-sov.) 0 Green bonds
9 2013-09-30 Non-financial corps. 0.268 Green bonds
10 2013-09-30 Financial corps. 0.0563 Green bonds
# ℹ 166 more rows
# A tibble: 176 × 4
date sector issuance_bn_usd issuance_type
<date> <chr> <dbl> <chr>
1 2013-03-31 Non-financial corps. 0 Social bonds
2 2013-03-31 Financial corps. 0 Social bonds
3 2013-03-31 Sovereign 0 Social bonds
4 2013-03-31 General government (ex-sov.) 0 Social bonds
5 2013-06-30 Non-financial corps. 0 Social bonds
6 2013-06-30 Financial corps. 0 Social bonds
7 2013-06-30 Sovereign 0 Social bonds
8 2013-06-30 General government (ex-sov.) 0 Social bonds
9 2013-09-30 Non-financial corps. 0 Social bonds
10 2013-09-30 Financial corps. 0 Social bonds
# ℹ 166 more rows
Green municipal Bonds
green_municipal_bonds_sm <-process_iif_gb_issuance_sectorMM(range ="AD4:AH48", issuance_type ="Green municipal bonds")green_municipal_bonds_sm
# A tibble: 176 × 4
date sector issuance_bn_usd issuance_type
<date> <chr> <dbl> <chr>
1 2013-03-31 Non-financial corps. 0 Green municipal bonds
2 2013-03-31 Financial corps. 0 Green municipal bonds
3 2013-03-31 Sovereign 0 Green municipal bonds
4 2013-03-31 General government (ex-sov.) 0.396 Green municipal bonds
5 2013-06-30 Non-financial corps. 0 Green municipal bonds
6 2013-06-30 Financial corps. 0 Green municipal bonds
7 2013-06-30 Sovereign 0 Green municipal bonds
8 2013-06-30 General government (ex-sov.) 0.517 Green municipal bonds
9 2013-09-30 Non-financial corps. 0 Green municipal bonds
10 2013-09-30 Financial corps. 0 Green municipal bonds
# ℹ 166 more rows
# A tibble: 176 × 4
date sector issuance_bn_usd issuance_type
<date> <chr> <dbl> <chr>
1 2013-03-31 Non-financial corps. 3.87 Green loans
2 2013-03-31 Financial corps. 0 Green loans
3 2013-03-31 Sovereign 0 Green loans
4 2013-03-31 General government (ex-sov.) 0 Green loans
5 2013-06-30 Non-financial corps. 1.16 Green loans
6 2013-06-30 Financial corps. 0.0785 Green loans
7 2013-06-30 Sovereign 0 Green loans
8 2013-06-30 General government (ex-sov.) 0 Green loans
9 2013-09-30 Non-financial corps. 0.972 Green loans
10 2013-09-30 Financial corps. 0 Green loans
# ℹ 166 more rows
New names:
Rows: 49 Columns: 4
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," dbl
(3): ...1, VIXCLS, FEDFUNDS date (1): observation_date
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...1`
New names:
Rows: 660 Columns: 5
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(2): geography, issuance_type dbl (2): ...1, issuance_bn_usd date (1): date
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...1`
New names:
Rows: 141 Columns: 4
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(3): Emerging and frontier markets (141), Mature markets (35), Offshore ... dbl
(1): ...1
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...1`
New names:
Rows: 1980 Columns: 5
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(2): geography, issuance_type dbl (2): ...1, issuance_bn_usd date (1): date
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...1`
New names:
Rows: 1496 Columns: 5
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(2): sector, issuance_type dbl (2): ...1, issuance_bn_usd date (1): date
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...1`
New names:
Rows: 1496 Columns: 5
── Column specification
──────────────────────────────────────────────────────── Delimiter: "," chr
(2): sector, issuance_type dbl (2): ...1, issuance_bn_usd date (1): date
ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
Specify the column types or set `show_col_types = FALSE` to quiet this message.
• `` -> `...1`
#plotting issuance_bn_usd over time for different geographies using the correct dataframeggplot(headline_issuance, aes(x = date, y = issuance_bn_usd, color = geography)) +geom_line() +theme_minimal() +labs(title ="Sustainable Debt Issuance over Time",x ="Date",y ="Issuance (Billion USD)",color ="Geography") +scale_x_date(date_breaks ="1 year", date_labels ="%Y")
Fixing the table so I can calculate issuances as a share of global issuance
# First, obtain the total global issuance for each date.global_totals <- headline_issuance %>%filter(geography =="Global") %>%rename(global_issuance = issuance_bn_usd) %>%select(date, global_issuance)# Make sure that 'data' is indeed a dataframe or a tibble.# Now, join this with the original data to have the global issuance amounts alongside each entry.data_with_global <- headline_issuance %>%left_join(global_totals, by ="date")# Finally, calculate the share for each geography as a percentage of the global total.data_with_shares <- data_with_global %>%mutate(share_of_global = (issuance_bn_usd / global_issuance) *100)# View the resultprint(data_with_shares)
# Filter out the 'Global' geographydata_without_global <- data_with_shares %>%filter(geography !="Global")# Now plot the data without 'Global'ggplot(data_without_global, aes(x = date, y = share_of_global, color = geography, group = geography)) +geom_smooth() +labs(title ="Share of Global Issuance by Geography Over Time",x ="Date",y ="Share of Global (%)",color ="Geography") +theme_minimal() +scale_x_date(date_breaks ="1 year", date_labels ="%Y") # Adjust date_breaks and date_labels as needed
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'
Alternative plot
ggplot(data_without_global, aes(x = date, y = share_of_global, group = geography)) +geom_line() +facet_wrap(~ geography, scales ='free_y') +# This will create separate panels for each geographylabs(title ="Share of Global Issuance by Geography Over Time",x ="Date",y ="Share of Global (%)") +theme_minimal() +theme(strip.text.x =element_text(size =8)) # This will ensure the facet labels are not too large
Alternative graph
library(plotly)
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
fig <- data_without_global %>%plot_ly(x =~date, y =~share_of_global, color =~geography, type ='scatter', mode ='lines')fig <- fig %>%layout(title ="Share of Global Issuance by Geography Over Time",xaxis =list(title ="Date"),yaxis =list(title ="Share of Global (%)"))fig