Homework 2

Author

Adam Savino

library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.3.2
Warning: package 'ggplot2' was built under R version 4.3.2
Warning: package 'dplyr' was built under R version 4.3.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.3     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(dplyr)
library(patchwork)
Warning: package 'patchwork' was built under R version 4.3.2
library(esquisse)
Warning: package 'esquisse' was built under R version 4.3.2
blackrock_etf_screener <-read_csv("https://raw.githubusercontent.com/t-emery/sais-susfin_data/main/datasets/ishares_etf_screener_as_of_2023-12-27.csv")
Rows: 424 Columns: 18
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (10): ticker, name, asset_class, sub_asset_class, region, market, locat...
dbl   (6): gross_expense_ratio_percent, net_expense_ratio_percent, net_asset...
dttm  (2): incept_date, net_assets_as_of

ℹ 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.
blackrock_etf_screener
# A tibble: 424 × 18
   ticker name                        incept_date         gross_expense_ratio_…¹
   <chr>  <chr>                       <dttm>                               <dbl>
 1 IVV    iShares Core S&P 500 ETF    2000-05-15 00:00:00                   0.03
 2 IEFA   iShares Core MSCI EAFE ETF  2012-10-18 00:00:00                   0.07
 3 AGG    iShares Core U.S. Aggregat… 2003-09-22 00:00:00                   0.03
 4 IWF    iShares Russell 1000 Growt… 2000-05-22 00:00:00                   0.19
 5 IJR    iShares Core S&P Small-Cap… 2000-05-22 00:00:00                   0.06
 6 IJH    iShares Core S&P Mid-Cap E… 2000-05-22 00:00:00                   0.05
 7 IEMG   iShares Core MSCI Emerging… 2012-10-18 00:00:00                   0.09
 8 IWM    iShares Russell 2000 ETF    2000-05-22 00:00:00                   0.19
 9 IWD    iShares Russell 1000 Value… 2000-05-22 00:00:00                   0.19
10 TLT    iShares 20+ Year Treasury … 2002-07-22 00:00:00                   0.15
# ℹ 414 more rows
# ℹ abbreviated name: ¹​gross_expense_ratio_percent
# ℹ 14 more variables: net_expense_ratio_percent <dbl>, net_assets_usd <dbl>,
#   net_assets_as_of <dttm>, asset_class <chr>, sub_asset_class <chr>,
#   region <chr>, market <chr>, location <chr>, investment_style <chr>,
#   msci_esg_fund_rating_aaa_ccc <chr>, msci_esg_quality_score_0_10 <dbl>,
#   msci_weighted_average_carbon_intensity_tons_co2e_m_sales <dbl>, …
blackrock_etf_screener %>%
  glimpse()
Rows: 424
Columns: 18
$ ticker                                                   <chr> "IVV", "IEFA"…
$ name                                                     <chr> "iShares Core…
$ incept_date                                              <dttm> 2000-05-15, …
$ gross_expense_ratio_percent                              <dbl> 0.03, 0.07, 0…
$ net_expense_ratio_percent                                <dbl> 0.03, 0.07, 0…
$ net_assets_usd                                           <dbl> 399312542067,…
$ net_assets_as_of                                         <dttm> 2023-12-27, …
$ asset_class                                              <chr> "Equity", "Eq…
$ sub_asset_class                                          <chr> "Large Cap", …
$ region                                                   <chr> "North Americ…
$ market                                                   <chr> "Developed", …
$ location                                                 <chr> "United State…
$ investment_style                                         <chr> "Index", "Ind…
$ msci_esg_fund_rating_aaa_ccc                             <chr> "A", "AA", "A…
$ msci_esg_quality_score_0_10                              <dbl> 6.6845, 7.519…
$ msci_weighted_average_carbon_intensity_tons_co2e_m_sales <dbl> 106.80, 102.8…
$ msci_esg_percent_coverage                                <dbl> 99.05, 99.80,…
$ sustainable_classification                               <chr> NA, NA, NA, N…
blackrock_etf_screener %>%
  distinct(sustainable_classification)
# A tibble: 5 × 1
  sustainable_classification
  <chr>                     
1 <NA>                      
2 Uplift                    
3 Thematic                  
4 Impact                    
5 Screened                  
blackrock_etf_screener %>%
  group_by(sustainable_classification) %>%
  count(sort = TRUE)
# A tibble: 5 × 2
# Groups:   sustainable_classification [5]
  sustainable_classification     n
  <chr>                      <int>
1 <NA>                         384
2 Uplift                        30
3 Thematic                       6
4 Screened                       3
5 Impact                         1
blackrock_etf_screener %>%
  group_by(sustainable_classification) %>%
  summarize(n_funds = n(), assets_usd = sum(net_assets_usd, na.rm = TRUE)) %>%
  arrange(assets_usd %>% 
            desc())
# A tibble: 5 × 3
  sustainable_classification n_funds assets_usd
  <chr>                        <int>      <dbl>
1 <NA>                           384    2.55e12
2 Uplift                          30    5.14e10
3 Thematic                         6    3.43e 9
4 Screened                         3    3.83e 8
5 Impact                           1    3.35e 8
blackrock_etf_screener_w_new_features <- blackrock_etf_screener %>%
  mutate(
    standard_or_esg = if_else(
      condition = is.na(sustainable_classification),
      true = "Standard",
      false = "ESG"
    ),
    inception_year = lubridate::year(incept_date),
    net_assets_bn_usd = net_assets_usd/10^9,
    .before = everything()
  )
blackrock_etf_screener_w_new_features
# A tibble: 424 × 21
   standard_or_esg inception_year net_assets_bn_usd ticker name                 
   <chr>                    <dbl>             <dbl> <chr>  <chr>                
 1 Standard                  2000             399.  IVV    iShares Core S&P 500…
 2 Standard                  2012             107.  IEFA   iShares Core MSCI EA…
 3 Standard                  2003             101.  AGG    iShares Core U.S. Ag…
 4 Standard                  2000              82.1 IWF    iShares Russell 1000…
 5 Standard                  2000              78.2 IJR    iShares Core S&P Sma…
 6 Standard                  2000              77.1 IJH    iShares Core S&P Mid…
 7 Standard                  2012              73.9 IEMG   iShares Core MSCI Em…
 8 Standard                  2000              67.7 IWM    iShares Russell 2000…
 9 Standard                  2000              55.4 IWD    iShares Russell 1000…
10 Standard                  2002              52.2 TLT    iShares 20+ Year Tre…
# ℹ 414 more rows
# ℹ 16 more variables: incept_date <dttm>, gross_expense_ratio_percent <dbl>,
#   net_expense_ratio_percent <dbl>, net_assets_usd <dbl>,
#   net_assets_as_of <dttm>, asset_class <chr>, sub_asset_class <chr>,
#   region <chr>, market <chr>, location <chr>, investment_style <chr>,
#   msci_esg_fund_rating_aaa_ccc <chr>, msci_esg_quality_score_0_10 <dbl>,
#   msci_weighted_average_carbon_intensity_tons_co2e_m_sales <dbl>, …
assets_esg_vs_standard <- blackrock_etf_screener_w_new_features %>%
  group_by(standard_or_esg) %>%
  summarize(
    assets_bn = sum(net_assets_bn_usd, na.rm = TRUE),
    n_funds = n()
  )
assets_esg_vs_standard
# A tibble: 2 × 3
  standard_or_esg assets_bn n_funds
  <chr>               <dbl>   <int>
1 ESG                  55.6      40
2 Standard           2547.      384
assets_esg_vs_standard %>%
  ggplot(aes(x = assets_bn, y = standard_or_esg)) + geom_bar(stat = "identity")

assets_esg_vs_standard %>%
  mutate(assets_pct = assets_bn/sum(assets_bn) * 100, .after = standard_or_esg)
# A tibble: 2 × 4
  standard_or_esg assets_pct assets_bn n_funds
  <chr>                <dbl>     <dbl>   <int>
1 ESG                   2.14      55.6      40
2 Standard             97.9     2547.      384
assets_esg_vs_standard %>%
  ggplot(aes(x = assets_bn, y = standard_or_esg))+ geom_bar(stat = "identity", fill = "grey40", alpha = .7)+
  scale_x_continuous(labels = scales::label_dollar(scale = 1/10^3, suffix = "tn")) +
  labs( title = "Total Assets: iShares ESG vs Standard Funds",
        subtitle = "ESG comprise a small percentage of total assets.",
        x = "Total Assets (USD)",
        y = "Fund Type",
        caption = "I made this \n Data as of xyz")

  theme_minimal()
List of 97
 $ line                      :List of 6
  ..$ colour       : chr "black"
  ..$ linewidth    : num 0.5
  ..$ linetype     : num 1
  ..$ lineend      : chr "butt"
  ..$ arrow        : logi FALSE
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_line" "element"
 $ rect                      :List of 5
  ..$ fill         : chr "white"
  ..$ colour       : chr "black"
  ..$ linewidth    : num 0.5
  ..$ linetype     : num 1
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_rect" "element"
 $ text                      :List of 11
  ..$ family       : chr ""
  ..$ face         : chr "plain"
  ..$ colour       : chr "black"
  ..$ size         : num 11
  ..$ hjust        : num 0.5
  ..$ vjust        : num 0.5
  ..$ angle        : num 0
  ..$ lineheight   : num 0.9
  ..$ margin       : 'margin' num [1:4] 0points 0points 0points 0points
  .. ..- attr(*, "unit")= int 8
  ..$ debug        : logi FALSE
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ title                     : NULL
 $ aspect.ratio              : NULL
 $ axis.title                : NULL
 $ axis.title.x              :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : NULL
  ..$ hjust        : NULL
  ..$ vjust        : num 1
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : 'margin' num [1:4] 2.75points 0points 0points 0points
  .. ..- attr(*, "unit")= int 8
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ axis.title.x.top          :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : NULL
  ..$ hjust        : NULL
  ..$ vjust        : num 0
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : 'margin' num [1:4] 0points 0points 2.75points 0points
  .. ..- attr(*, "unit")= int 8
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ axis.title.x.bottom       : NULL
 $ axis.title.y              :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : NULL
  ..$ hjust        : NULL
  ..$ vjust        : num 1
  ..$ angle        : num 90
  ..$ lineheight   : NULL
  ..$ margin       : 'margin' num [1:4] 0points 2.75points 0points 0points
  .. ..- attr(*, "unit")= int 8
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ axis.title.y.left         : NULL
 $ axis.title.y.right        :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : NULL
  ..$ hjust        : NULL
  ..$ vjust        : num 0
  ..$ angle        : num -90
  ..$ lineheight   : NULL
  ..$ margin       : 'margin' num [1:4] 0points 0points 0points 2.75points
  .. ..- attr(*, "unit")= int 8
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ axis.text                 :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : chr "grey30"
  ..$ size         : 'rel' num 0.8
  ..$ hjust        : NULL
  ..$ vjust        : NULL
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : NULL
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ axis.text.x               :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : NULL
  ..$ hjust        : NULL
  ..$ vjust        : num 1
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : 'margin' num [1:4] 2.2points 0points 0points 0points
  .. ..- attr(*, "unit")= int 8
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ axis.text.x.top           :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : NULL
  ..$ hjust        : NULL
  ..$ vjust        : num 0
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : 'margin' num [1:4] 0points 0points 2.2points 0points
  .. ..- attr(*, "unit")= int 8
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ axis.text.x.bottom        : NULL
 $ axis.text.y               :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : NULL
  ..$ hjust        : num 1
  ..$ vjust        : NULL
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : 'margin' num [1:4] 0points 2.2points 0points 0points
  .. ..- attr(*, "unit")= int 8
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ axis.text.y.left          : NULL
 $ axis.text.y.right         :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : NULL
  ..$ hjust        : num 0
  ..$ vjust        : NULL
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : 'margin' num [1:4] 0points 0points 0points 2.2points
  .. ..- attr(*, "unit")= int 8
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ axis.ticks                : list()
  ..- attr(*, "class")= chr [1:2] "element_blank" "element"
 $ axis.ticks.x              : NULL
 $ axis.ticks.x.top          : NULL
 $ axis.ticks.x.bottom       : NULL
 $ axis.ticks.y              : NULL
 $ axis.ticks.y.left         : NULL
 $ axis.ticks.y.right        : NULL
 $ axis.ticks.length         : 'simpleUnit' num 2.75points
  ..- attr(*, "unit")= int 8
 $ axis.ticks.length.x       : NULL
 $ axis.ticks.length.x.top   : NULL
 $ axis.ticks.length.x.bottom: NULL
 $ axis.ticks.length.y       : NULL
 $ axis.ticks.length.y.left  : NULL
 $ axis.ticks.length.y.right : NULL
 $ axis.line                 : list()
  ..- attr(*, "class")= chr [1:2] "element_blank" "element"
 $ axis.line.x               : NULL
 $ axis.line.x.top           : NULL
 $ axis.line.x.bottom        : NULL
 $ axis.line.y               : NULL
 $ axis.line.y.left          : NULL
 $ axis.line.y.right         : NULL
 $ legend.background         : list()
  ..- attr(*, "class")= chr [1:2] "element_blank" "element"
 $ legend.margin             : 'margin' num [1:4] 5.5points 5.5points 5.5points 5.5points
  ..- attr(*, "unit")= int 8
 $ legend.spacing            : 'simpleUnit' num 11points
  ..- attr(*, "unit")= int 8
 $ legend.spacing.x          : NULL
 $ legend.spacing.y          : NULL
 $ legend.key                : list()
  ..- attr(*, "class")= chr [1:2] "element_blank" "element"
 $ legend.key.size           : 'simpleUnit' num 1.2lines
  ..- attr(*, "unit")= int 3
 $ legend.key.height         : NULL
 $ legend.key.width          : NULL
 $ legend.text               :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : 'rel' num 0.8
  ..$ hjust        : NULL
  ..$ vjust        : NULL
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : NULL
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ legend.text.align         : NULL
 $ legend.title              :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : NULL
  ..$ hjust        : num 0
  ..$ vjust        : NULL
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : NULL
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ legend.title.align        : NULL
 $ legend.position           : chr "right"
 $ legend.direction          : NULL
 $ legend.justification      : chr "center"
 $ legend.box                : NULL
 $ legend.box.just           : NULL
 $ legend.box.margin         : 'margin' num [1:4] 0cm 0cm 0cm 0cm
  ..- attr(*, "unit")= int 1
 $ legend.box.background     : list()
  ..- attr(*, "class")= chr [1:2] "element_blank" "element"
 $ legend.box.spacing        : 'simpleUnit' num 11points
  ..- attr(*, "unit")= int 8
 $ panel.background          : list()
  ..- attr(*, "class")= chr [1:2] "element_blank" "element"
 $ panel.border              : list()
  ..- attr(*, "class")= chr [1:2] "element_blank" "element"
 $ panel.spacing             : 'simpleUnit' num 5.5points
  ..- attr(*, "unit")= int 8
 $ panel.spacing.x           : NULL
 $ panel.spacing.y           : NULL
 $ panel.grid                :List of 6
  ..$ colour       : chr "grey92"
  ..$ linewidth    : NULL
  ..$ linetype     : NULL
  ..$ lineend      : NULL
  ..$ arrow        : logi FALSE
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_line" "element"
 $ panel.grid.major          : NULL
 $ panel.grid.minor          :List of 6
  ..$ colour       : NULL
  ..$ linewidth    : 'rel' num 0.5
  ..$ linetype     : NULL
  ..$ lineend      : NULL
  ..$ arrow        : logi FALSE
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_line" "element"
 $ panel.grid.major.x        : NULL
 $ panel.grid.major.y        : NULL
 $ panel.grid.minor.x        : NULL
 $ panel.grid.minor.y        : NULL
 $ panel.ontop               : logi FALSE
 $ plot.background           : list()
  ..- attr(*, "class")= chr [1:2] "element_blank" "element"
 $ plot.title                :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : 'rel' num 1.2
  ..$ hjust        : num 0
  ..$ vjust        : num 1
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : 'margin' num [1:4] 0points 0points 5.5points 0points
  .. ..- attr(*, "unit")= int 8
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ plot.title.position       : chr "panel"
 $ plot.subtitle             :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : NULL
  ..$ hjust        : num 0
  ..$ vjust        : num 1
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : 'margin' num [1:4] 0points 0points 5.5points 0points
  .. ..- attr(*, "unit")= int 8
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ plot.caption              :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : 'rel' num 0.8
  ..$ hjust        : num 1
  ..$ vjust        : num 1
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : 'margin' num [1:4] 5.5points 0points 0points 0points
  .. ..- attr(*, "unit")= int 8
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ plot.caption.position     : chr "panel"
 $ plot.tag                  :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : 'rel' num 1.2
  ..$ hjust        : num 0.5
  ..$ vjust        : num 0.5
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : NULL
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ plot.tag.position         : chr "topleft"
 $ plot.margin               : 'margin' num [1:4] 5.5points 5.5points 5.5points 5.5points
  ..- attr(*, "unit")= int 8
 $ strip.background          : list()
  ..- attr(*, "class")= chr [1:2] "element_blank" "element"
 $ strip.background.x        : NULL
 $ strip.background.y        : NULL
 $ strip.clip                : chr "inherit"
 $ strip.placement           : chr "inside"
 $ strip.text                :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : chr "grey10"
  ..$ size         : 'rel' num 0.8
  ..$ hjust        : NULL
  ..$ vjust        : NULL
  ..$ angle        : NULL
  ..$ lineheight   : NULL
  ..$ margin       : 'margin' num [1:4] 4.4points 4.4points 4.4points 4.4points
  .. ..- attr(*, "unit")= int 8
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ strip.text.x              : NULL
 $ strip.text.x.bottom       : NULL
 $ strip.text.x.top          : NULL
 $ strip.text.y              :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : NULL
  ..$ hjust        : NULL
  ..$ vjust        : NULL
  ..$ angle        : num -90
  ..$ lineheight   : NULL
  ..$ margin       : NULL
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ strip.text.y.left         :List of 11
  ..$ family       : NULL
  ..$ face         : NULL
  ..$ colour       : NULL
  ..$ size         : NULL
  ..$ hjust        : NULL
  ..$ vjust        : NULL
  ..$ angle        : num 90
  ..$ lineheight   : NULL
  ..$ margin       : NULL
  ..$ debug        : NULL
  ..$ inherit.blank: logi TRUE
  ..- attr(*, "class")= chr [1:2] "element_text" "element"
 $ strip.text.y.right        : NULL
 $ strip.switch.pad.grid     : 'simpleUnit' num 2.75points
  ..- attr(*, "unit")= int 8
 $ strip.switch.pad.wrap     : 'simpleUnit' num 2.75points
  ..- attr(*, "unit")= int 8
 - attr(*, "class")= chr [1:2] "theme" "gg"
 - attr(*, "complete")= logi TRUE
 - attr(*, "validate")= logi TRUE
etf_formation_esg_vs_standard <- blackrock_etf_screener_w_new_features %>%
  group_by(standard_or_esg, inception_year) %>%
  count() %>%
  ungroup()
etf_formation_esg_vs_standard
# A tibble: 37 × 3
   standard_or_esg inception_year     n
   <chr>                    <dbl> <int>
 1 ESG                       2005     1
 2 ESG                       2006     1
 3 ESG                       2008     1
 4 ESG                       2014     1
 5 ESG                       2016     5
 6 ESG                       2017     2
 7 ESG                       2018     3
 8 ESG                       2019     1
 9 ESG                       2020    12
10 ESG                       2021     5
# ℹ 27 more rows
etf_formation_esg_vs_standard %>%
  ggplot(aes(x = inception_year, y = n, fill = standard_or_esg)) + geom_line()

etf_formation_esg_vs_standard_cumulative <- etf_formation_esg_vs_standard %>%
  arrange(standard_or_esg, inception_year) %>%
  group_by(standard_or_esg) %>%
  mutate(cumulative_n = cumsum(n)) %>%
  ungroup
etf_formation_esg_vs_standard_cumulative
# A tibble: 37 × 4
   standard_or_esg inception_year     n cumulative_n
   <chr>                    <dbl> <int>        <int>
 1 ESG                       2005     1            1
 2 ESG                       2006     1            2
 3 ESG                       2008     1            3
 4 ESG                       2014     1            4
 5 ESG                       2016     5            9
 6 ESG                       2017     2           11
 7 ESG                       2018     3           14
 8 ESG                       2019     1           15
 9 ESG                       2020    12           27
10 ESG                       2021     5           32
# ℹ 27 more rows
etf_formation_esg_vs_standard_cumulative %>%
  ggplot(aes(x = inception_year, y = cumulative_n, color = standard_or_esg)) + geom_line()

blackrock_etf_screener_w_new_features |> 
  group_by(standard_or_esg, asset_class) %>%
  summarize(
    max_size = max(net_assets_bn_usd, na.rm = TRUE),
    min_size = min(net_assets_bn_usd, na.rm = TRUE),
    avg_size = mean(net_assets_bn_usd, na.rm = TRUE),
    sd_size = sd(net_assets_bn_usd, na.rm = TRUE),
    median_size = median(net_assets_bn_usd, na.rm = TRUE),
    percentile_50 = quantile(net_assets_bn_usd, .5, na.rm = TRUE),
    percentile_75 = quantile(net_assets_bn_usd, .75, na.rm = TRUE),
  )
`summarise()` has grouped output by 'standard_or_esg'. You can override using
the `.groups` argument.
# A tibble: 9 × 9
# Groups:   standard_or_esg [2]
  standard_or_esg asset_class   max_size min_size avg_size  sd_size median_size
  <chr>           <chr>            <dbl>    <dbl>    <dbl>    <dbl>       <dbl>
1 ESG             Equity        13.4     0.00371   1.74     2.97        0.501  
2 ESG             Fixed Income   3.56    0.0125    0.954    1.22        0.586  
3 ESG             Multi Asset    0.0257  0.00527   0.0144   0.00966     0.0132 
4 ESG             Real Estate    0.00939 0.00939   0.00939 NA           0.00939
5 Standard        Commodity     26.5     0.0130    4.48     8.92        0.659  
6 Standard        Equity       399.      0.000457  8.02    29.9         0.817  
7 Standard        Fixed Income 101.      0.00247   5.22    12.6         0.423  
8 Standard        Multi Asset    2.25    0.00271   0.435    0.782       0.00383
9 Standard        Real Estate    4.60    0.0403    1.76     1.67        1.41   
# ℹ 2 more variables: percentile_50 <dbl>, percentile_75 <dbl>
blackrock_etf_screener_w_new_features %>%
  filter(standard_or_esg == "ESG") %>%
  select(ticker, name, net_assets_bn_usd) %>%
  mutate(
    fund_rank = rank(net_assets_bn_usd),
    fund_percentile = percent_rank(net_assets_bn_usd),
    fund_decile = ntile(net_assets_bn_usd, n = 10),
    
    pct_of_total = net_assets_bn_usd/sum(net_assets_bn_usd, na.rm = TRUE) *100,
    pct_of_total_cumulative = cumsum(pct_of_total)
  )
# A tibble: 40 × 8
   ticker name           net_assets_bn_usd fund_rank fund_percentile fund_decile
   <chr>  <chr>                      <dbl>     <dbl>           <dbl>       <int>
 1 ESGU   iShares ESG A…             13.4         40           1              10
 2 ESGD   iShares ESG A…              7.64        39           0.974          10
 3 SUSA   iShares MSCI …              5.37        38           0.949          10
 4 DSI    iShares MSCI …              4.08        37           0.923          10
 5 ESGE   iShares ESG A…              4.02        36           0.897           9
 6 EAGG   iShares ESG A…              3.56        35           0.872           9
 7 ICLN   iShares Globa…              3.06        34           0.846           9
 8 USCL   iShares Clima…              2.09        33           0.821           9
 9 PABU   iShares Paris…              1.54        32           0.795           8
10 LCTU   BlackRock U.S…              1.51        31           0.769           8
# ℹ 30 more rows
# ℹ 2 more variables: pct_of_total <dbl>, pct_of_total_cumulative <dbl>
# Homework Problem 1

blackrock_only_etf <- blackrock_etf_screener_w_new_features %>%
  filter(standard_or_esg == "ESG")%>%
  group_by(sustainable_classification)%>%
  summarize(number_class_funds = n(), big_sust = max(net_assets_bn_usd, na.rm = TRUE), total_netass_bn = sum(net_assets_bn_usd, na.rm = TRUE), percent_netass_bn = (big_sust/total_netass_bn)*100)%>%
  arrange(desc(percent_netass_bn))
View(blackrock_only_etf)

# Homework Problem 2
blackrock_mini <- blackrock_etf_screener_w_new_features %>%
  filter(standard_or_esg == "ESG")%>%
  reframe(mini = head(sort(net_assets_bn_usd), 10, na.rm = TRUE))
blackrock_mini
# A tibble: 10 × 1
      mini
     <dbl>
 1 0.00371
 2 0.00412
 3 0.00424
 4 0.00469
 5 0.00527
 6 0.00541
 7 0.00577
 8 0.00749
 9 0.00873
10 0.00939
blackrock_mini %>%
ggplot(aes(x = rank(mini), y = mini, color = "gray20")) + geom_bar(stat = "identity") + labs(title = "10 Smallest ESG Funds", subtitle = "In terms of assets expressed in USD billions", x = "ranking of the values from smallest to greatest", y = "USD bn values")

# Homework Problem 3
bingus_1 <- blackrock_etf_screener_w_new_features%>%
  filter(standard_or_esg == "ESG") %>%
  group_by(asset_class, sub_asset_class)%>%
  summarize(
    bottom_quint = quantile(msci_esg_quality_score_0_10, .2, na.rm = TRUE), Assets_p_subc_bn_usd = sum(net_assets_bn_usd), number_o_funds = n()
    )%>%
  arrange(desc(bottom_quint))
`summarise()` has grouped output by 'asset_class'. You can override using the
`.groups` argument.
bingus_1
# A tibble: 10 × 5
# Groups:   asset_class [4]
   asset_class  sub_asset_class bottom_quint Assets_p_subc_bn_usd number_o_funds
   <chr>        <chr>                  <dbl>                <dbl>          <int>
 1 Equity       All Cap                 7.10              3.08                 5
 2 Multi Asset  Multi Strategy          7.08              0.0574               4
 3 Equity       Large Cap               7.08              1.56                 3
 4 Fixed Income Credit                  6.84              2.41                 4
 5 Equity       Large/Mid Cap           6.81             42.5                 17
 6 Fixed Income Multi Sectors           6.46              4.15                 2
 7 Real Estate  Real Estate Se…         6.02              0.00939              1
 8 Equity       Mid Cap                 5.98              0.137                1
 9 Fixed Income High Yield              5.97              0.121                1
10 Equity       Small Cap               5.66              1.53                 2
# Homework Problem 4

b <- blackrock_etf_screener_w_new_features %>%
  filter(!is.na(msci_esg_fund_rating_aaa_ccc)) %>%
  filter(!is.na(sustainable_classification)) %>%
  ggplot(aes(x = sustainable_classification, y = msci_esg_fund_rating_aaa_ccc, fill = sustainable_classification)) +
  geom_tile() +
  scale_fill_hue(direction = 1) +
  labs(
    x = "MSCI ESG Bond Rating", 
    y = "Sustainability Classification",
    title = "Ratings of ESG Bonds",
    subtitle = "Categorized by Classification", 
    fill = "Sustainability Classification"
  ) +
  theme_minimal()
b

a <- blackrock_etf_screener_w_new_features %>%
 filter(!is.na(msci_esg_fund_rating_aaa_ccc)) %>%
 ggplot() +
 aes(x = region, y = msci_esg_fund_rating_aaa_ccc, fill = msci_esg_fund_rating_aaa_ccc) +
 geom_tile() + labs(title = "Available ESG Asset Ratings Per Region", x = "Rating", y = "Region") +
 scale_fill_hue(direction = 1) +
 theme_minimal()
a

e <- blackrock_etf_screener_w_new_features %>%
 filter(!is.na(sustainable_classification)) %>%
 ggplot() +
 aes(x = sustainable_classification, y = asset_class, 
 fill = sustainable_classification) +
 geom_tile() +
 scale_fill_hue(direction = 1) +
 labs(x = "Sustainability Classification", 
 y = "Asset Classes", title = "Sustainability Classification Divided into Asset Classes", fill = "Sustainability Classification") +
 theme_minimal()
e

c <- blackrock_etf_screener_w_new_features %>%
  filter(!is.na(msci_esg_fund_rating_aaa_ccc)) %>%
  group_by(msci_esg_fund_rating_aaa_ccc, region) %>%
  count() %>%
  pivot_wider(names_from = region, values_from = n, values_fill = 0)
View(c)

d <- blackrock_etf_screener_w_new_features %>%
  filter(!is.na(msci_esg_fund_rating_aaa_ccc)) %>%
  filter(!is.na(sustainable_classification)) %>%
  group_by(msci_esg_fund_rating_aaa_ccc, sustainable_classification) %>%
  count() %>%
  pivot_wider(names_from = sustainable_classification, values_from = n, values_fill = 0)
View(d)

print("My focus in this question was linking the MSCI ratings values to regions and sustainability classifications. In graphs A and B, you see the relationships depicted graphically, and in charts c and d, you see the numerical relationships between these variables. Part e shows the relationship between the sustainability classifications and the asset classes")
[1] "My focus in this question was linking the MSCI ratings values to regions and sustainability classifications. In graphs A and B, you see the relationships depicted graphically, and in charts c and d, you see the numerical relationships between these variables. Part e shows the relationship between the sustainability classifications and the asset classes"

The echo: false option disables the printing of code (only output is displayed).