Fund Flows via the FT

Fund Flows via the FT

There’s a great piece on the FT today about algos and fund flows. It’s author, Robin Wigglesworth, has become one of my personal favorites, for good writing in general and for good inspiration about interesting data. Today’s article had a nice chart about mutual fund and ETF fund flows and it sent me down a rabbit hole to try to find some publicly available data on that topic and put into a quick chart. Next week I’ll go a little deeper on how to use this data but for today let’s just see if we can approximate the original data vis.

First let’s grab some flows data. The ICI publishes some data on the last three years of fund flows, for both mutual funds and ETF funds. The original article has data going back much further and it’s sourced from EPFR, a higher grade data provider that is not free. Our purpose is to explore some R code so we will stick with the free data source.

We’ll first read in the location of the data and then name the file that will be downloaded.

library(tidyverse)
library(readxl)
url <- "https://www.ici.org/info/combined_flows_data_2018.xls"
destfile <- "combined_flows_data_2018.xls"
curl::curl_download(url, destfile)

Next we pass that information to read_excel() and clean up the raw data and column names.

combined_flows_data_2018 <- read_excel(destfile, 
    col_types = c("text", "numeric", "skip", 
        "numeric", "skip", "numeric", "skip", 
        "numeric", "skip", "numeric", "skip", 
        "numeric", "skip", "numeric", "skip", 
        "numeric", "skip", "numeric"), skip = 5) %>% 
  rename(date = X__1, all = X__2, total_equity = Total, 
         domestic_equity = Domestic, world_equity = World, 
         hybrid = X__3, total_bond = Total__1, commmodity = X__4, 
         muni_bond = Municipal, taxable_bond = Taxable) %>% 
  slice(-1:-2) %>%
  na.omit() %>% 
  mutate(date = ymd(parse_date_time(date, '%m/%d/%Y')))

combined_flows_data_2018 %>% 
  head()

From there, we gather() to tidy format and head to ggplot(), faceting by the type of fund.

combined_flows_data_2018 %>%
  gather(fund_type, flow, -date) %>% 
  mutate(col_pos = 
           if_else(flow > 0, 
                  flow, as.numeric(NA)),
         col_neg = 
           if_else(flow < 0, 
                  flow, as.numeric(NA))) %>%
  ggplot(aes(x = date)) +
  geom_col(aes(y = col_neg),
               alpha = .85, 
               fill = "pink", 
               color = "pink") +
  geom_col(aes(y = col_pos),
               alpha = .85, 
               fill = "cornflowerblue", 
               color = "cornflowerblue") +
  facet_wrap(~fund_type, shrink = FALSE) +
  labs(title = "Weekly fund flows", subtitle = "2016 - 2018", caption = "source: inspired by @RobinWigg", y = "flows (millions)", x = "") +
  scale_y_continuous(label= scales::dollar_format()) +
  scale_x_date(breaks = scales::pretty_breaks(n = 10)) +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 90, hjust = 1),
        plot.title = element_text(hjust = 0.5),
        plot.subtitle = element_text(hjust = 0.5),
        strip.background = element_blank(),
        strip.placement = "inside",
        strip.text = element_text(size=15),
        panel.spacing = unit(0.2, "lines") ,
        panel.background=element_rect(fill="white"))

That’s all! Over the next week we’ll be looking back at 2018 and we’ll add this new data to the exploration.

Shaun Anderson

Tech Lead | Data, Analytics, Automation | Architect and Team Builder

6 年

Great practical example of dplyr data pipelines and the power of ggplot faceted visuals in R. Thanks!

Brian Han, M.Sc., CFA, FRM, CIPM

Investment Systems Consultant | BI & Data Analytics Specialist | Quant Researcher

6 年

Nice work!

Shawn Shobeiri, PhD, PRM

Quant | Data Scientist | Risk Manager at Intersect Power| Renewable Energy | Solar | BESS | Green H2 and NH3 “There are three choices in this life: be good, get good, or give up.”

6 年

Very interesting thanks Jonathan Regenstein

要查看或添加评论,请登录

Jonathan Regenstein的更多文章

  • If you want to understand how to succeed in the hedge fund world, read these two books

    If you want to understand how to succeed in the hedge fund world, read these two books

    Happy holidays to all! I wanted to share brief thoughts on two excellent books that found their way to my book stack…

    9 条评论
  • Momentum investing with R

    Momentum investing with R

    After an extended hiatus, Reproducible Finance is back! We’ll celebrate by changing focus a bit and coding up an…

  • Some Sector Analysis with R

    Some Sector Analysis with R

    Welcome to the second installment of Reproducible Finance 2019! In the previous post, we looked back on the daily…

    2 条评论
  • Looking back on 2018 Reproducible Finance with R part 1

    Looking back on 2018 Reproducible Finance with R part 1

    Welcome to Reproducible Finance 2019! It’s a new year, a new beginning, the Earth has completed one more trip around…

  • Rolling Origin Sampling

    Rolling Origin Sampling

    Today, we continue our work on sampling so that we can run models on subsets of our data and then test the accuracy of…

    2 条评论
  • Rsampling Fama French + Quant Finance Contest

    Rsampling Fama French + Quant Finance Contest

    Today we will continue our work on Fama French factor models, but more as a vehicle to explore some of the awesome…

  • Fama French with R: Managing Multiple Models + Cyber Monday Book Discount

    Fama French with R: Managing Multiple Models + Cyber Monday Book Discount

    Today, we will return to the Fama French (FF) model of asset returns and use it as a proxy for fitting and evaluating…

    1 条评论
  • Reproducible Finance, the book!

    Reproducible Finance, the book!

    I’m thrilled to announce the release of my new book Reproducible Finance with R: Code Flows and Shiny Apps for…

    12 条评论
  • Visualizing GDP with R

    Visualizing GDP with R

    Today we will take a look at the GDP data that is released every quarter or so by the Bureau of Economic Analysis BEA…

  • Highcharting Jobs Friday

    Highcharting Jobs Friday

    Today, in honor of last week’s jobs report from the Bureau of Labor Statistics (BLS), we will visualize jobs data with…

社区洞察

其他会员也浏览了