Installing package into 'C:/Users/Shiya (Grace) Huang/AppData/Local/R/win-library/4.3'
(as 'lib' is unspecified)
package 'tidyverse' successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\Shiya (Grace) Huang\AppData\Local\Temp\RtmpQRlu3X\downloaded_packages
── 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
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 |>group_by(sustainable_classification) |>summarize(# how many funds?n_funds =n(),# how much money?assets_usd =sum(net_assets_usd, na.rm =TRUE) ) |># arrange in descending orderarrange(assets_usd |>desc())
#blackrock_etf_screener_w_new_features <- blackrock_etf_screener |>mutate(# if the sustainable_classification column is NA, then the fund is not an ESG fund.standard_or_esg =if_else(condition =is.na(sustainable_classification),true ="Standard",false ="ESG" ),# lubridate::year() extracts the year from a dateinception_year = lubridate::year(incept_date),# Change to a meaningful magnitude for the data. In asset management, billions is a good default. net_assets_bn_usd = net_assets_usd/10^9,# let's put our new variables at the front so we can see them easily..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 |>ggplot(aes(x = assets_bn, y = standard_or_esg)) +geom_bar(stat ="identity", fill ="grey40", alpha = .7) +# make it prettier# scales::label_* funcitons provide useful options. Check them out!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",# you can use \n to create a line breakcaption ="I made this.\nData as of xyz") +theme_minimal()
# contains the largest fund from each sustainable classification.largest_funds_by_classification <- blackrock_etf_screener_w_new_features |>group_by(sustainable_classification) |>summarise(Largest_Fund = name[which.max(net_assets_usd)],Max_Assets =max(net_assets_usd),Total_Assets =sum(net_assets_usd, na.rm =TRUE),.groups ='drop' ) |>mutate(Percent_Of_Category_Assets = (Max_Assets / Total_Assets) *100 )# shows the percent of assets that the top fund comprises for its category# Ranks each sustainable classification by the % of assets in its largest fund, and arranges them in descending order.ranked_classifications <- largest_funds_by_classification |>mutate(Rank =rank(-Percent_Of_Category_Assets) ) |>arrange(desc(Percent_Of_Category_Assets))###### 2.5.0.2 Homework Problem 2# Filter for the 10 smallest ETFs by net assetssmallest_etfs <- blackrock_etf_screener_w_new_features |>arrange(net_assets_usd) |>slice_head(n =10)# Create a sorted bar chartsmallest_etfs_chart <- smallest_etfs %>%ggplot(aes(x =fct_reorder(ticker, net_assets_usd), y = net_assets_usd)) +geom_bar(stat ="identity") +coord_flip() +# Flip the chart for better readability of the tickerslabs(title ="10 Smallest ETFs by Net Assets",x ="Ticker",y ="Net Assets (USD)",caption ="Data sourced from BlackRock ETF Screener") +scale_y_continuous(labels = scales::label_dollar()) # Use dollar format for y-axissmallest_etfs_chart
# A tibble: 9 × 4
asset_class sub_asset_class Number_of_Funds Total_Assets
<chr> <chr> <int> <dbl>
1 Equity All Cap 23 95486052602.
2 Equity Large Cap 1 1852506812.
3 Equity Large/Mid Cap 10 42421984678.
4 Equity Small Cap 17 187292555389.
5 Fixed Income Corporates 1 41339182.
6 Fixed Income Credit 1 408038372.
7 Fixed Income Government 3 17560711395.
8 Fixed Income High Yield 16 38239624578.
9 Real Estate Real Estate Securities 4 7145439523.
###### 2.5.0.4 Homework Problem 4library(ggplot2)# Distribution of MSCI ESG Quality Scoresggplot(blackrock_etf_screener_w_new_features, aes(x = msci_esg_quality_score_0_10)) +geom_histogram(binwidth =0.1, fill ="skyblue", color ="black") +labs(title ="Distribution of MSCI ESG Quality Scores",x ="ESG Quality Score",y ="Number of Funds") +theme_minimal()
# Pie Chart of Total Assets by Asset Class for Bottom Quintilelibrary(ggplot2)bottom_quintile_summary |>ggplot(aes(x ="", y = Total_Assets, fill = asset_class)) +geom_bar(width =1, stat ="identity") +coord_polar("y") +labs(title ="Total Assets by Asset Class for Bottom Quintile Funds")
# Bar Chart of Funds by Asset Class in Bottom Quintilelibrary(ggplot2)ggplot(bottom_quintile_summary, aes(x = asset_class, y = Number_of_Funds, fill = asset_class)) +geom_bar(stat ="identity") +labs(title ="Funds in Bottom Quintile by Asset Class", x ="Asset Class", y ="Number of Funds") +theme_minimal()
# Line Graph Showing Cumulative Number of New ESG Funds Over Timeggplot(etf_formation_esg_vs_standard_cumulative, aes(x = inception_year, y = cumulative_n, color = standard_or_esg)) +geom_line() +labs(title ="Cumulative Number of New ESG Funds Over Time", x ="Year", y ="Cumulative Number of Funds")