class: center, middle, inverse, title-slide .title[ # Empirical asset pricing with Tidy Finance ] .subtitle[ ## www.tidy-finance.org ] .author[ ### Patrick Weiss ] .date[ ### March 19, 2024 ] --- class: chapter-slide # Talk outline --- ## What is this talk about? 1. Career paths in **Finance** and **academia** 2. Open-source project **Tidy Finance** 3. **Empirical asset pricing** --- class: chapter-slide # Finance and academia --- ## My own journey - Raised and socialized in Vienna, Austria - *My plan:* + Undergraduate business degree with a focus on management + Add an international master's program in management + Become an important manager, get rich, and have a family - **The reality:** + Switch during undergraduate degree to focus on finance and mathematics + Stay in Vienna to complete a **quantitative finance** program + Complete the **CFA charter** to push industry career prospects + Then, continue directly with a **PhD in Finance** --- ## Today's view on Patrick Weiss .pull-left[ <middle><center><img style="border-radius: 50%;" alt="Portrait of Patrick Weiss" src="images/pic_patrick.jpg" width="200px"/></center></middle> .center[**Patrick Weiss**
[patrickw@ru.is](mailto:patrickw@ru.is)] ] .pull-right[ - Assistant professor of finance at RU - External lecturer at WU Vienna - Research focus on empirical asset pricing with equities and bonds - Published in top finance journals - Co-author of Tidy Finance (two textbooks) ] --- ## What do I take away from my journey? - A simplified version: *You never know what life has to offer*? - No. - My main problem with *management* was (is) the **lack of quantifiable relations** for decision making. + Good leaders are absolutely important. + However, we hardly know what makes a good manager nor how to learn the craft. - What drew me to finance is the hope of making informed decisions. + The person with the **right analysis wins** (also against their boss). + Put differently: Truth trumps anything. + At the heart, any decision can be mapped to a **financial decision**. - The core ideas of finance and academia seem optimal to me. --- class: chapter-slide # Tidy Finance --- ### #TidyFinance is ... .pull-left[ - ... an open-source project available at [tidy-finance.org](https://www.tidy-finance.org) and a published textbook. - ... a step towards **reproducible finance** by providing a fully transparent code base. - ... a resource for students, lecturers, and professionals using `R` for applications in finance. - ... a **tidy** approach to finance. - ... continuously maintained and expanded. ] .pull-right[ <middle><center><img src="images/cover-book-r.jpg" alt="Cover image of 'Tidy Finance with R'. The figure reads Tidy Finance with R followed by the author's names; Christoph Scheuch, Stefan Voigt, and Patrick Weiss." width="350"/></center></middle> ] --- class: middle .pull-left[ ### `R` is among the best choices for finance programming. - Free, open-source software with a diverse, active **community**. - Actively-maintained **packages** for all kinds of applications. - Smooth integration with other **programming languages**. - **RStudio**
] .pull-right[ ### `{Tidyverse}` is the way for data analysis. - Messy data cause pain. **Tidy data** cause joy. - Compose simple functions with the **pipe**. - Designed for **humans**. - **Consistent** across packages. ] --- ### #TidyFinance goes Python .pull-left[ - There is a **Python** version of Tidy Finance. - It provides the same treatment of finance in Python as the previous book. - Print release in **June 2024**. - We also have a **blog** for external contributors. ] .pull-right[ <middle><center><img src="images/cover-python.png" alt="Cover image of 'Tidy Finance with Python'." width="400"/></center></middle> Check it out at [tidy-finance.org/python](https://www.tidy-finance.org/python/index.html)! ] --- class: chapter-slide # Empirical Asset Pricing --- ## Is empirical asset pricing important? .pull-left[ - Asset prices are essential for efficient **resource allocation**. - **Theoretical** insights have to be tested empirically. - There are tons of **research articles** produced every year. - Stock, bond, currency **markets** are enormous and affect our daily life. ] .pull-right[ <middle><center><img src="images/fearless_girl.jpg" alt="Image of a bronze statue of a girl in front of a statue of a bull." width="400"/></center></middle> ] --- ## Before we do anything else - If you have not installation of `{tidyverse}`, run `install.packages("tidyverse")` ```r library(tidyverse) ``` - It is the tool we use (and recommend) for data analysis in all contexts --- ## Where to get free data? - There are several free financial data providers: + Yahoo!Finance + Kenneth French's website + FED & ECB data - We will discuss how to access them and manipulate the data - There are more free alternative presented in Chapter *Other data providers* of #TidyFinance --- ## Yahoo!Finance overview - We start by downloading and visualizing stock data from Yahoo!Finance + Provides stock data for several frequencies + Adjusted prices for dividends & splits + Returns have to be computed from the price time series - For this, we also load the convenient `{tidyquant}` package ```r library(tidyquant) ``` --- ## Apple stock data - We retrieve stock market data for Apple (ticker AAPL) with `tq_get()` ```r prices <- tq_get("AAPL", get = "stock.prices", from = "2000-01-01", to = "2021-12-31" ) ``` - `{tidyquant}` comes with additional features, but we will skip them here (consider `tq_index("DOW")` to get a set of tickers) --- ## Apple stock price (I) - It is generally a good idea to look at your data, e.g., by visualizing it in a plot: ```r prices |> ggplot(aes(x = date, y = adjusted)) + geom_line() + labs( x = NULL, y = NULL, title = "Apple stock prices between beginning of 2000 and end of 2021" ) ``` --- ## Apple stock price (II) <img src="HI_Visit_2024_files/figure-html/unnamed-chunk-5-1.png" width="60%" style="display: block; margin: auto;" /> --- ## Computing Apple's stock returns - We can now compute stock returns from our prices + Considering adjusted stock prices (dividends and stock splits) + Returns can be computed as `\(r_t = p_t / p_{t-1} - 1\)` + Where `\(p_t\)` is the adjusted day `\(t\)` price ```r returns <- prices |> arrange(date) |> mutate(ret = adjusted / lag(adjusted) - 1) |> select(symbol, date, ret) |> drop_na(ret) ``` --- ## Apple's stock returns: Historgram (I) ```r quantile_05 <- quantile(returns |> pull(ret) * 100, probs = 0.05) returns |> ggplot(aes(x = ret * 100)) + geom_histogram(bins = 100) + geom_vline(aes(xintercept = quantile_05), linetype = "dashed" ) + labs( x = NULL, y = NULL, title = "Distribution of daily Apple stock returns in percent" ) ``` --- ## Apple's stock returns: Historgram (II) <img src="HI_Visit_2024_files/figure-html/unnamed-chunk-8-1.png" width="60%" style="display: block; margin: auto;" /> --- ## Kenneth French's website - Kenneth French provides data on his webpage including + Risk-free rates + Risk factors returns + Test assets for various tests - Access via the `frenchdata` package - Check out all available data on the webpage or via `get_french_data_list()` --- ## Kenneth French's data access ```r library(frenchdata) factors_ff_monthly_raw <- download_french_data("Fama/French 3 Factors") factors_ff_monthly <- factors_ff_monthly_raw$subsets$data[[1]] |> transmute( month = floor_date(ymd(str_c(date, "01")), "month"), rf = as.numeric(RF) / 100, mkt_excess = as.numeric(`Mkt-RF`) / 100, smb = as.numeric(SMB) / 100, hml = as.numeric(HML) / 100) ``` --- ## Risk-free rate ```r factors_ff_monthly |> ggplot(aes(x = month, y = 100 * rf)) + geom_line() + labs(x = NULL, y = NULL, title = "Risk free rate (in percent)") ``` <img src="HI_Visit_2024_files/figure-html/unnamed-chunk-10-1.png" width="60%" style="display: block; margin: auto;" /> --- ## Macroeconomic data sources - There are tons of data available from the FED and ECB - Check out the packages `{fredr}` and `{ecb}` for easy access - Alternatively, Ivo Welch provides some important predictors for asset pricing research on his website + Use the packages `{readxl}` and `{googledrive}` to retrieve it + Manipulating the data as suggested in Chapter *Accessing and Managing Financial Data* of #TidyFinance --- ## Implementing the CAPM - The **CAPM** of Sharpe (1964), Lintner (1965), and Mossin (1966) originates the literature on asset pricing models - Asset risk is the **covariance** of its return with the **market** portfolio return - The higher the co-movement the less desirable the asset is, hence, the asset **price is lower** and the expected **return is higher** - **Risk premium** is driven by investors' risk aversion and is equal to the expected value of excess market return --- ## Regression specification of stock `\(i\)` `$$r_{i,t} - r_{f,t} = \alpha_i + \underbrace{\frac{Cov(r_i, r_m)}{\text{Var}(r_m)}}_{\beta_i} (r_{m,t} - r_{f,t}) + \varepsilon_{i, t}$$` - Expected returns are determined by the **price of risk** (market risk premium) and the **co-movement** of asset `\(i\)` with the market, `\(\beta_i\)` - To determine whether an asset generates **abnormal returns** relative to the CAPM, we evaluate whether the intercept coefficient `\(\alpha_i\)` is statistically distinguishable from zero --- ## The market factor - The market risk premium is the market excess return `\(z_t = r_{m,t} - r_{f,t}\)` - We proxy for the market with the value-weighted portfolio of all US based common stocks in CRSP (provided by Kenneth French) - **Sharpe ratio** is computed as `\(\frac{\hat{\mu_z}}{\hat{\sigma}_z}\)` ```r factors_ff_monthly |> mutate(mkt_excess = 100 * mkt_excess) |> summarise(across(mkt_excess, list(mean = ~ 12 * mean(.), sd = ~sqrt(12) * sd(.), Sharpe = ~sqrt(12) * mean(.)/sd(.)), .names = "{.fn} (annualized)")) |> kableExtra::kable() ``` | mean (annualized)| sd (annualized)| Sharpe (annualized)| |-----------------:|---------------:|-------------------:| | 8.14| 18.5| 0.44| --- ## CAPM - Introductory example (I) - Implementation of the CAPM is a simple **linear regression** (estimated via OLS) with `lm` - Let us look at an example for Apple Inc. + We compute monthly returns + Then, we run the CAPM linear regression ```r apple_monthly <- returns |> mutate(month = floor_date(date, "month")) |> group_by(month) |> summarize(ret = prod(1+ret) - 1, .groups = "drop") |> left_join(factors_ff_monthly, by = "month") |> mutate(ret_excess = ret - rf) ``` --- ## CAPM - Introductory example (II) - Implementation of the CAPM is a simple **linear regression** (estimated via OLS) with `lm` - Let us look at an example for Apple Inc. + We compute monthly returns + **Then, we run the CAPM linear regression** ```r lm(ret_excess ~ mkt_excess, data = apple_monthly) |> broom::tidy() |> knitr::kable() ``` |term | estimate| std.error| statistic| p.value| |:-----------|--------:|---------:|---------:|-------:| |(Intercept) | 0.018| 0.006| 2.98| 0.003| |mkt_excess | 1.374| 0.132| 10.42| 0.000| --- ## CAPM - Introductory example (III) ```r apple_monthly |> ggplot(aes(x = mkt_excess, y = ret_excess)) + geom_point() + geom_smooth(method = "lm", se = FALSE) + labs(x = "Market Excess Returns", y = "Apple Excess Returns") ``` <img src="HI_Visit_2024_files/figure-html/unnamed-chunk-15-1.png" width="60%" style="display: block; margin: auto;" /> --- ## Bad news for CAPM? <center><img alt="Logo of CRSP" src="images/alpha_beta_sorts.png" width="600px"/></center> - Figure shows decile portfolio sorts based on *lagged* beta (1 lowest, 10 highest) - Each bar corresponds to the CAPM alpha of the value-weighted portfolio performance --- background-image: url("images/wrds_logo.png") background-position: 90% 60% background-size: 400px ## Additional info: Where to get the best data? - Gathering high quality data is the basis for any for research project - Luckily, the Wharton Research Data Service (i.e., WRDS) exists - WRDS combines many data providers in one, easy-to-use platform + CRSP, + Compustat, + TRACE, + Optionmetrics, and so much more.. - The Tidy Finance Chapter on **WRDS, CRSP, and Compustat** covers all details --- ## Additional info: Extensions to portfolio sorts - The CAPM *test* is only one example of how to use portfolio sorts - Portfolio sorts also extend to multiple characteristics at once with **multivariate portfolio sorts** - The famous Fama and French (1992) model's factors come from a 2x3 sort on **size and book-to-market** (+ the market factor) - The **factor zoo** shows how many applications portfolio sorts have in the academic literature --- ## Additional info: Researchs' discretion in portfolio sorts - Researchers have to make **numerous decision** when conducting portfolio sorts: + How many portfolios? + How to weight portfolio returns? + Single or double sorts? + Sample construction rules? - These decision are seemingly innocuous, but have a **large impact** on the estimates of risk premiums - There is a clear potential for **p-hacking** and **data mining** --- ## Additional info: Methodological uncertainty in portfolio sorts <center><img alt="Logo of CRSP" src="images/NSE_plot_figure_1and2.jpg" width="500px"/></center> The degree of variation in risk premium estimates. See [Walter, Weber, and Weiss (2022)](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4164117) for details. --- class: chapter-slide # Final remarks --- ## Conclusion - Finance is great and academia is even better - Check out [Tidy Finance](https://www.tidy-finance.org) - You know some important concepts in **empirical asset pricing** + You have learnt ways to implement them easily + You know where to look for more insights --- class: middle, left background-image: url("images/cover-book-r.jpg") background-position: right background-size: 350px ### Reach out with comments, questions, or <br> suggestions:
[contact@tidy-finance.org](mailto:contact@tidy-finance.org) ##
visit [tidy-finance.org](https://www.tidy-finance.org)