API Reference

This is a comprehensive reference for everything you get when you import famafrench.

FamaFrench Constructor

FamaFrench

Class providing tools for constructing and replicating datasets from Ken French’s online library via queries to CRSP, Compustat Fundamentals Annual, and other sources accessed through wrds-cloud.

wrdsConnection Constructor

wrdsConnection

Class for setting up the remote connection to wrds-cloud; largely builds on the Connection class in the WRDS-Py library.

Connecting to wrds-cloud

connect

Make a connection to the wrds-cloud database.

close

Close the connection to the database.

get_wrds_table

Create a pandas.DataFrame from an entire table in the database.

raw_sql

Query the wrds-cloud database using a raw SQL string.

wrds-cloud Query Tools

queryComp

Query Compustat Fundamentals Annual files from wrds-cloud.

queryCrsp

Query CRSP Stock/Security files from wrds-cloud.

queryCrspdlret

Query CRSP’s Stock Event - Delisting files on wrds-cloud.

queryrf1m

Query the risk-free interest rate (ie 1-month Treasury Bill rate) from wrds-cloud.

getCrspDailyRollVar

Calculate rolling daily variance of stock returns for all CRSP stocks queried from wrds-cloud.

aggregateME

Aggregate market value of equity me for cases in which the same firm (ie single permco identifer) has two or more securities (ie multiple permno identifiers) for a given date.

getMEDec

Construct market value of equity me for Decemeber of every year.

getMEJune

Construct market value of equity me for June of every year.

mergeCCM

Query the CRSP/Compustat (CCM) Merged Linking Table needed to merge CRSP securities to Compustat companies on (permno, gvkey) identifier pairs.

Estimating Market Betas and Rolling Residual Variances

getFactorRegResults

Estimate factor-based quantities of risk (specifically, market betas) as well as residuals using rolling regressions.

Constructing Portfolios and Return-Based Factors

getNyseThresholdsAndRet

Select NYSE stocks used in the construction of breakpoints (ie thresholds) for portfolio sorting.

getPortfolios

Generalized routine used to construct datasets containing portfolio returns (which may include factor returns), number of firms in each portfolio, or average anomaly portfolio characteristics at a given frequency and for a given sample period.

getPortfolioReturns

Construct dataset w/ portfolio returns (which may include factor returns) at a given frequency and for a given sample period.

getNumFirms

Construct dataset w/ number of firms in each portfolio at a given frequency and for a given sample period.

getCharacs

Construct average anomaly portfolio characteristics at a given frequency and for a given sample period.

getFFfactors

Construct dataset w/ Fama-French-style factors at a given frequency and for a given sample period.

Comparing to Ken French’s Online Library

kfLibrary

Generalized routine used to query datasets from Ken French’s online library at a given frequency and for a given sample period.

getkfPortfolioReturns

Query portfolio returns from Ken French’s online library at a given frequency and for a given sample period.

getkfNumFirms

Query number of firms in each portfolio from Ken French’s online data library at a given frequency and for a given sample period.

getkfCharacs

Query average anomaly portfolio characteristics from Ken French’s online library at a given frequency and for a given sample period.

getkfFFfactors

Query Fama-French-style factors from Ken French’s online library at a given frequency and for a given sample period.

Summary Statistics and Diagnostics

getFamaFrenchStats

Detailed summary statistics tables of portfolio returns (which may include factor returns), number of firms in each portfolio, or average anomaly portfolio characteristics at a given frequency and for a given sample period.

comparePortfolios

Generalized routine used to compare datasets constructed from wrds-cloud queries to their equivalents made publicly available on Ken French’s online library at a given frequency and for a given sample period.

Auxiliary Functions and Utilities

lru_cached_method

Wrapper for methodtools.lru_cache() enabling recognition of decorated class instance methods by Sphinx.

get_kfpriorfactors_directly

Directly download (from Ken French’s online library) zipped monthly or annual datafiles for the Short-Term Reversal or Long-Term Reversal Fama-French-style factors.

timing

Wrapper for class instance methods enabling the timing of execution.

any_in

Boolean variable that is True if elements in a given set a_set intersect with elements in another set b_set.

priormonthToDay

Consistent w/ Fama and French (2008, 2016), map the prior (j-k) monthly return strategy into a daily strategy (see Ken French’s online documentation).

grouped_vwAvg

Calculate (net) weighted portfolio return for portfolio with weights col_weights within a group or groups.

portRetAvg

Compute a simple average across different columns.

get_statsTable

Construct detailed tables with summary statistics.