Skip to main content

Tidy Finance Helper Functions

Project description

tidyfinance

PyPI PyPI Downloads python-package.yml

License: MIT

Helper functions for empirical research in financial economics, addressing a variety of topics covered in Scheuch, Voigt, Weiss, and Frey (2024). The package is designed to provide shortcuts for issues extensively discussed in the book, facilitating easier application of its concepts. For more information and resources related to the book, visit tidy-finance.org/python.

Installation

You can install the release version from PyPI:

pip install tidyfinance

You can install the development version from GitHub:

pip install "git+https://github.com/tidy-finance/py-tidyfinance"

Download Open Source Data

The main functionality of the tidyfinance package centers around data download. You can download most of the data that we used in Tidy Finance with R using the download_data() function or its children.

import tidyfinance as tf

The function always requires a domain argument and depending on the domain typically also a dataset. For instance, to download monthly Fama-French factors, you have to provide the dataset name according to pdr.famafrench.get_available_datasets():

tf.download_data(
  domain="factors_ff",
  dataset="F-F_Research_Data_5_Factors_2x3_daily",
  start_date="2000-01-01", 
  end_date="2020-12-31"
)

For q factors, you provide the relevant file name:

tf.download_data(
  domain="factors_q",
  dataset="q5_factors_monthly",
  start_date="2000-01-01", 
  end_date="2020-12-31"
)

To download the Welch and Goyal (2008) macroeconomic predictors for monthly, quarterly, or annual frequency:

tf.download_data(
  domain="macro_predictors",
  dataset="monthly",
  start_date="2000-01-01", 
  end_date="2020-12-31"
)

To download data from Open Source Asset Pricing (OSAP):

tf.download_data(
  domain="osap",
  start_date="2020-01-01", 
  end_date="2020-12-31"
)

To download multiple series from the Federal Reserve Economic Data (FRED):

tf.download_data(
  domain="fred",
  series=["GDP", "CPIAUCNS"], 
  start_date="2020-01-01", 
  end_date="2020-12-31"
)

To download stock prices from Yahoo Finance:

tf.download_data(
  domain="stock_prices",
  symbols=["AAPL", "MSFT"], 
  start_date="2020-01-01", 
  end_date="2020-12-31"
)

To download index constituents from selected ETF holdings:

tf.download_data(
  domain="constituents",
  index="S&P 500"
)

Download WRDS Data

To access data from the Wharton Research Data Services (WRDS), you need to set your credentials first:

tf.set_wrds_credentials()

To download monthly CRSP data:

tf.download_data(
  domain="wrds",
  dataset="crsp_monthly", 
  start_date="2020-01-01", 
  end_date="2020-12-31"
)

To download annual (or quaterly) Compustat data:

tf.download_data(
  domain="wrds",
  dataset="compustat_annual", 
  start_date="2020-01-01", 
  end_date="2020-12-31"
)

To download the CRSP-Compustat linking table:

tf.download_data(
  domain="wrds",
  dataset="ccm_links"
)

To download bond characteristics from Mergent FISD:

tf.download_data(
  domain="wrds",
  dataset="fisd"
)

To download Enhanced TRACE data for selected bonds:

tf.download_data(
  domain="wrds",
  dataset="trace_enhanced",
  cusips=["00101JAH9"],
  start_date="2019-01-01", 
  end_date="2021-12-31"
)

Other Helpers

We include functions to check out content from tidy-finance.org:

tf.list_tidy_finance_chapters()
tf.open_tidy_finance_website("capital-asset-pricing-model")

We also include (experimental) functions that can be used for different applications, but note that they might heavily change in future package versions as we try to make them more general:

# Create summary statistics
help(tf.create_summary_statistics)

# Assign portfolios
help(tf.assign_portfolio)

# Estimate betas
help(tf.estimate_betas)

# Estimate Fama-MacBeth 
help(tf.estimate_fama_macbeth)

# Add lag columns
help(tf.add_lag_columns)

# Winsorize or trim 
help(tf.winsorize)
help(tf.trim)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tidyfinance-0.1.2.tar.gz (90.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tidyfinance-0.1.2-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file tidyfinance-0.1.2.tar.gz.

File metadata

  • Download URL: tidyfinance-0.1.2.tar.gz
  • Upload date:
  • Size: 90.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for tidyfinance-0.1.2.tar.gz
Algorithm Hash digest
SHA256 00e565cd64665f95ce26e3d2631e436af2ac6a8492cb1abf14c0ca89942b1218
MD5 e89c0b87fd81b03c8d52136adea5e92b
BLAKE2b-256 738f620d3e3ba0bb4dd0c68612d65c338f5a297013dbdd635bc232eb2fcb6d90

See more details on using hashes here.

File details

Details for the file tidyfinance-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: tidyfinance-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for tidyfinance-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 51b4723612f2a5c80dcc5b381efb3f4b298a589f7fc07e5ad6f9c2318da84bfa
MD5 30a3a9550259482acd3211fac63f76e3
BLAKE2b-256 2f814f54e672da1042fa1fc91ec7bf936338cb5889aa899b8aa602f3f2a78cfc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page