The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(tidyr)# Read dataAUM_ESG <-read_excel("/Users/hahazhou/Desktop/Final Project/00_data_raw/AUM_ESG.xlsx")AUM_Thematic <-read_excel("/Users/hahazhou/Desktop/Final Project/00_data_raw/AUM_Thematic ETF.xlsx")# Add "Type" column and fill valuesAUM_ESG <- AUM_ESG %>%mutate(Type ="ESG")AUM_Thematic <- AUM_Thematic %>%mutate(Type ="Thematic")# Combine datasetsCombined_Volume <-bind_rows(AUM_ESG, AUM_Thematic)# Handle duplicatesCombined_Volume <- Combined_Volume %>%group_by(Ticker) %>%mutate(duplicate =n() >1) %>%ungroup() %>%filter(!duplicate | Type =="ESG") %>%mutate(Type =ifelse(duplicate, "ESG and Thematic", Type)) %>%select(-duplicate)# Keep only the first 4 letters in the Ticker columnCombined_Volume$Ticker <-substr(Combined_Volume$Ticker, 1, 4)# Transform to long formatCombined_Volume_long <- Combined_Volume %>%pivot_longer(cols =starts_with("20"), names_to ="Quarter", values_to ="AUM")
library(plotly)
Loading required package: ggplot2
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
ggplot(Combined_Volume_long) +aes(x = Quarter, y = AUM, fill = Ticker) +geom_col() +scale_fill_hue(direction =1) +labs(x ="Quarter",y ="AUM",title ="AUM for ETFs by Type and Ticker",caption ="Data Source: Bloomberg" ) +theme_minimal() +facet_wrap(vars(Type))
# Read dataFF_ESG <-read_excel("/Users/hahazhou/Desktop/Final Project/00_data_raw/Fund Flow_ESG.xlsx")FF_Thematic <-read_excel("/Users/hahazhou/Desktop/Final Project/00_data_raw/Fund Flow_Thematic ETF.xlsx")# Add "Type" column and fill valuesFF_ESG <- FF_ESG %>%mutate(Type ="ESG")FF_Thematic <- FF_Thematic %>%mutate(Type ="Thematic")# Combine datasetsCombined_FF <-bind_rows(FF_ESG, FF_Thematic)# Handle duplicatesCombined_FF <- Combined_FF %>%group_by(Ticker) %>%mutate(duplicate =n() >1) %>%ungroup() %>%filter(!duplicate | Type =="ESG") %>%mutate(Type =ifelse(duplicate, "ESG and Thematic", Type)) %>%select(-duplicate)# Keep only the first 4 letters in the Ticker columnCombined_FF$Ticker <-substr(Combined_FF$Ticker, 1, 4)# Transform to long formatCombined_FF_long <- Combined_FF %>%pivot_longer(cols =starts_with("20"), names_to ="Quarter", values_to ="Fund Flow")# Replace NA with 0Combined_FF_long$`Fund Flow`[is.na(Combined_FF_long$`Fund Flow`)] <-0
ggplot(Combined_FF_long) +aes(x = Quarter, y =`Fund Flow`, fill = Ticker) +geom_col() +scale_fill_hue(direction =1) +labs(x ="Quarter",y ="Fund Flow",title ="Fund Flow by Type and Ticker",caption ="Data source: Bloomberg" ) +theme_minimal() +facet_wrap(vars(Type))
ggplotly()
library(tidyquant)
Loading required package: lubridate
Attaching package: 'lubridate'
The following objects are masked from 'package:base':
date, intersect, setdiff, union
Loading required package: PerformanceAnalytics
Loading required package: xts
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
######################### Warning from 'xts' package ##########################
# #
# The dplyr lag() function breaks how base R's lag() function is supposed to #
# work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or #
# source() into this session won't work correctly. #
# #
# Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
# conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
# dplyr from breaking base R's lag() function. #
# #
# Code in packages is not affected. It's protected by R's namespace mechanism #
# Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
# #
###############################################################################
Attaching package: 'xts'
The following objects are masked from 'package:dplyr':
first, last
Attaching package: 'PerformanceAnalytics'
The following object is masked from 'package:graphics':
legend
Loading required package: quantmod
Loading required package: TTR
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
Warning: There were 26 warnings in `dplyr::mutate()`.
The first warning was:
ℹ In argument: `data.. = purrr::map(...)`.
Caused by warning:
! x = 'PBW ', get = 'stock.prices': Error in getSymbols.yahoo(Symbols = "PBW ", env = <environment>, verbose = FALSE, : Unable to import "PBW ".
URL using bad/illegal format or missing URL
Removing PBW .
ℹ Run `dplyr::last_dplyr_warnings()` to see the 25 remaining warnings.
Warning: There were 40 warnings in `dplyr::mutate()`.
The first warning was:
ℹ In argument: `nested.col = purrr::map(...)`.
ℹ In group 5: `Ticker = "AVDG"` and `Type = "ESG"`.
Caused by warning in `to_period()`:
! missing values removed from data
ℹ Run `dplyr::last_dplyr_warnings()` to see the 39 remaining warnings.
library(ggplot2)library(plotly)library(dplyr)ggplot(combined_returns) +aes(x = date, y = monthly.returns, colour = Ticker) +geom_line() +scale_color_viridis_d(option ="viridis", direction =1) +labs(x ="Year",y ="Monthly Returns",title ="Monthly Returns by Type and Ticker",caption ="Data Source: Bloomberg" ) +theme_gray() +facet_wrap(vars(Type))