1st Edition

Reproducible Finance with R Code Flows and Shiny Apps for Portfolio Analysis

By Jonathan K. Regenstein, Jr. Copyright 2018
    248 Pages
    by Chapman & Hall

    248 Pages
    by Chapman & Hall

    Reproducible Finance with R: Code Flows and Shiny Apps for Portfolio Analysis is a unique introduction to data science for investment management that explores the three major R/finance coding paradigms, emphasizes data visualization, and explains how to build a cohesive suite of functioning Shiny applications. The full source code, asset price data and live Shiny applications are available at reproduciblefinance.com. The ideal reader works in finance or wants to work in finance and has a desire to learn R code and Shiny through simple, yet practical real-world examples.

    The book begins with the first step in data science: importing and wrangling data, which in the investment context means importing asset prices, converting to returns, and constructing a portfolio. The next section covers risk and tackles descriptive statistics such as standard deviation, skewness, kurtosis, and their rolling histories. The third section focuses on portfolio theory, analyzing the Sharpe Ratio, CAPM, and Fama French models. The book concludes with applications for finding individual asset contribution to risk and for running Monte Carlo simulations. For each of these tasks, the three major coding paradigms are explored and the work is wrapped into interactive Shiny dashboards.

     

     

     

    Chapter 1

    Introduction

    Returns

    Chapter 2

    Asset Prices to Returns

    Converting Daily Prices to Monthly Returns in the xts world

    Converting Daily Prices to Monthly Returns in the tidyverse

    Converting Daily Prices to Monthly Returns in the tidyquant world

    Converting Daily Prices to Monthly Returns with tibbletime

    Visualizing Asset Returns in the xts world

    Visualizing Asset Returns in the tidyverse

    Chapter 3

    Building a Portfolio

    Portfolio Returns in the xts world

    Portfolio Returns in the tidyverse

    Portfolio Returns in the tidyquant world

    Visualizing Portfolio Returns in the xts world

    Visualizing Portfolio Returns in the tidyverse

    Shiny App Portfolio Returns

    Concluding Returns

    Risk

    Chapter 4

    Standard Deviation

    Standard Deviation in the xts world

    Standard Devation in the tidyverse

    Standard Deviation in the tidyquant world

    Visualizing Standard Deviation

    Rolling Standard Deviation

    Rolling Standard Deviation in the xts world

    Rolling Standard Deviation in the tidyverse

    Rolling Standard Devation with the tidyverse and tibbletime

    Rolling Standard Deviation in the tidyquant world

    Visualizing Rolling Standard Deviation in the xts world

    Visualizing Rolling Standard Deviation in the tidyverse

    Shiny App Standard Deviation

    Chapter 5

    Skewness

    Skewness in the xts world

    Skewness in the tidyverse

    Visualizing Skewness

    Rolling Skewness in the xts world

    Rolling Skewness in the tidyverse with tibbletime

    Rolling Skewness in the tidyquant world

    Visualizing Rolling Skewness

    Chapter 6

    Kurtosis

    Kurtosis in the xts world

    Kurtosis in the tidyverse

    Visualizing Kurtosis

    Rolling Kurtosis in the xts world

    Rolling Kurtosis in the tidyverse with tibbletime

    Rolling Kurtosis in the tidyquant world

    Visualizing Rolling Kurtosis

    Shiny App Skewness and Kurtosis

    Concluding Risk

    Portfolio Theory

    Chapter 7

    Sharpe Ratio

    Sharpe Ratio in the xts world

    Sharpe Ratio in the tidyverse

    Shape Ratio in the tidyquant world

    Visualizing Sharpe Ratio

    Rolling Sharpe Ratio in the xts World

    Rolling Sharpe Ratio with the tidyverse and tibbletime

    Rolling Sharpe Ratio with tidyquant

    Visualizing the Rolling Sharpe Ratio

    Shiny App Sharpe Ratio

    Chapter 8

    CAPM

    CAPM and Market Returns

    Calculating CAPM Beta

    Calculating CAPM Beta in the xts world

    Contents v

    Calculating CAPM Beta in the tidyverse

    Calculating CAPM Beta in the tidyquant world

    Visualizing CAPM with ggplot

    Augmenting Our Data

    Visualizing CAPM with highcharter

    Shiny App CAPM

    Chapter 9

    Fama French

    Importing and Wrangling Fama French

    Visualizing Fama French with ggplot

    Rolling Fama French with the tidyverse and tibbletime

    Visualizing Rolling Fama French

    Shiny App Fama French

    Concluding Portfolio Theory

    Practice and Applications

    Chapter 10

    Component Contribution to Standard Deviation

    Component Contribution Step-by-Step

    Component Contribution with a Custom Function

    Visualizing Component Contribution

    Rolling Component Contribution to Volatility

    Visualizing Rolling Component Contribution to Volatility

    Shiny App Component Contribution

    Chapter 11

    Monte Carlo Simulation

    Simulating Growth of a Dollar

    Several Simulation Functions

    Running Multiple Simulations

    Visualizing Simulation Results

    Visualizing with highcharter

    Shiny App Monte Carlo

    Concluding Practice Applications

    Biography

    Jonathan K. Regenstein, Jr. is the Director of Financial Services at RStudio. He studied international relations at Harvard and law at NYU, worked at JP Morgan, and did graduate work in political economy at Emory.

    "There are two major selling points from my perspective. First, Shiny web applications are a new technology that is in high demand. It enables users to communicate data science (including financial analytics) to managers and executives. I believe this alone is a big benefit that separates this book from others. The second is that (he) takes a modern approach to using three different frameworks: xts, tidyverse, and tidyquant/tibbletime. This is refreshing because it shows that there are multiple ways to accomplish the same tasks, and it exposes the user to options that they otherwise might not have considered. Because of these two aspects, I believe that the market is for financial analysts that are seeking to learn these tools. The typical reader will have some knowledge of R (not a complete beginner) and will be hungry to use Shiny in their organization…I enjoyed reading it. I found the prose approachable and not overly technical or formal." ~Matt Dancho, Founder, Business Science, LLC