Setting Up Your Environment
Empirical finance work is only as trustworthy as the environment it runs in. This chapter installs the language and packages used throughout, and sets up the credentials the data chapters rely on, so every later script runs end to end and reproducibly. Use the R | Python toggle to switch.
Installing packages
Install the core data-and-plotting stack once, then load it at the start of each session. R uses the tidyverse; Python uses pandas/numpy. Both add the companion tidyfinance package for one-line data downloads.
install.packages("tidyverse")
install.packages("tidyfinance")
# In your terminal:
# pip install pandas numpy tidyfinance
library(tidyverse)
library(tidyfinance)
import pandas as pd
import numpy as np
import tidyfinance as tf
Development versions
The latest features sometimes live on GitHub before a release. You can install the development version directly.
remotes::install_github("tidy-finance/r-tidyfinance")
# In your terminal:
# pip install "git+https://github.com/tidy-finance/py-tidyfinance"
Reproducibility and credentials
Beyond packages, a reproducible setup means: fixing a random seed wherever you draw random numbers, keeping a clean project layout (scripts separate from data and outputs, relative paths from the project root), and storing credentials — such as a WRDS login — outside the codebase in environment variables, never hard-coded. The goal is that a reader could clone the project and regenerate every result.
Study notes following the Tidy Finance curriculum by Scheuch, Voigt, Weiss, and Frey. Prose is my own; the R/Python code is reproduced from the book's open-source source, licensed CC BY-NC-SA 4.0.