R is a programming language that owes it’s lineage to S, a language designed in it’s own developers words, “to turn ideas into software, quickly and faithfully.”(1) Shiny is an “interactive web technology” that makes it easy to take R models and publish them to the web.
Jonathan L. Regenstein, Jr., the director of financial services at RStudio (an integrated development environment for R), walks us through both technologies in a portfolio analysis setting.
When I first joined Alpha Architect many of our financial models were exclusively in Excel and augmented with VBA code. Coming from Amazon, I was overwhelmed with VBA code and my eyes (and heart) started to bleed. Excel makes it very easy to write one-off simple programs and very difficult to write reproducible, maintainable programs.
R and Shiny fill this niche effectively. The book starts off with a crash course in a few common R packages. From there it dives into using those packages in a financial context. There are examples using the common data table libraries including xts, tidyverse, tidyquant, and tibbletime.
The book moves quickly from pulling down, cleaning, and producing returns data from the web to computing common statistical measures (standard deviation, skewness, kurtosis). The remainder of the book focuses on Portfolio theory including calculating Sharpe ratios, the CAPM, the Fama-French 3-factor model (including code that works verbatim for downloading data from the Fama French website), component contributions to standard deviation, and culminates in a full-blown web app running monte-carlo simulations.
We found the book compelling enough that we are planning on migrating many of our internal and external tools to R and the Shiny framework.
This is a book for practitioners; if you have not programmed in another language before this book will be very difficult. The book also moves through the Financial material very quickly.
In the author’s own words:
The book seeks to be a resource for R coders interested in finance, or financiers who are interested in R or quantitative work generally.
The book also “prioritizes code that is understandable over code that is theoretically brilliant”. The code does have quite a bit of copy-paste and there are areas where adding a function or module would have cleaned up the code. Those who have an obsession for elegance, you have been warned.
This book achieves it’s mission to teach finance professionals and programmers how to use R in a financial setting. While I’m still a far-cry from mastering R, the book did give me enough knowledge that we will be using it for modelling purposes going forward.
Jack Vogel, Ph.D., conducts research in empirical asset pricing and behavioral finance, and is a co-author of DIY FINANCIAL ADVISOR: A Simple Solution to Build and Protect Your Wealth. His dissertation investigates how behavioral biases affect the value anomaly. His academic background includes experience as an instructor and research assistant at Drexel University in both the Finance and Mathematics departments, as well as a Finance instructor at Villanova University. Dr. Vogel is currently a Managing Member of Alpha Architect, LLC, an SEC-Registered Investment Advisor, where he heads the research department and serves as the Chief Financial Officer. He has a PhD in Finance and a MS in Mathematics from Drexel University, and graduated summa cum laude with a BS in Mathematics and Education from The University of Scranton.
Performance figures contained herein are hypothetical, unaudited and prepared by Alpha Architect, LLC; hypothetical results are intended for illustrative purposes only. Past performance is not indicative of future results, which may vary. There is a risk of substantial loss associated with trading stocks, commodities, futures, options and other financial instruments. Full disclosures here.