famafrench.FamaFrench

class famafrench.FamaFrench(pickled_dir, runQuery, freqType, sortCharacsId, factorsId, mainCharacsId=None, runEstimation=False)[source]

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.

pickled_dir

Absolute path directory where pickled datasets will be saved.

Type

str

runQuery

Flag for choosing whether to query datafiles from wrds-cloud or import locally-pickled files.

Type

bool

freqType

Observation frequency of the portfolios. Possible choices are

  • D : daily

  • W : weekly

  • M : monthly

  • Q : quarterly (3-months)

  • A : annual

Type

str

sortCharacsId

Names of the anomaly characteristics used for portfolio sorting. The list will contain one, two, or three elements. The order of the elements matters and should be consistent w/ the orders presented in Ken French’s online library. Possible choices are:

  • ME : Size

  • BE : Book equity

  • BM : Book-to-Market equity

  • OP : Operating Profitability

  • INV : Investment

  • EP : Earnings/Price

  • CFP : Cashflow/Price

  • DP : Dividend Yield (i.e. Dividends/Price)

  • PRIOR_2_12 : Prior (2-12) Returns

  • PRIOR_1_1 : Prior (1-1) Returns

  • PRIOR_60_13 : Prior (13-60) Returns

  • AC : Accruals

  • BETA : Market Beta (estimated using the Scholes-Williams (1977) methodology)

  • VAR : Variance (Daily and calculated using last 60 days (w/ 20 minimum)

  • RESVAR : Fama-French Three-factor model Residual Variance (Daily and calculated using last 60 days (w/ 20 minimum)

  • NI : Net Share Issues

Type

list, str

factorsId

Names of the anomaly/risk-based factors following Fama and French (1992, 1993, 2008, 2015, 2017). Possible choices are:

  • MKT-RF : Market premium

  • SMB : Small Minus Big

  • HML : High Minus Low

  • RMW : Robust Minus Weak

  • RMWc : Cash-based Robust Minus Weak (Todo)

  • CMA : Conservative Minus Aggressive

  • MOM : Momentum - based on Prior (2-12) returns

  • ST_Rev : Short-Term Reversal - based on Prior (1-1) returns

  • LT_Rev : Long-Term Reversal - based on Prior (13-60) returns

Type

None or list, str

mainCharacsId

Names of the anomaly characteristics computed as averages for each portfolio bucket and constructed using the list sortCharacsId. If None, mainCharacsI is set to the list sortCharacsId.

Type

None or list, str, default None

runEstimation

Flag for choosing whether to run any estimation procedures for the first time/re-estimate procedures by querying wrds-cloud datafiles or import locally-pickled files storing existing estimates.

Type

bool, default False

runFactorReg

Flag for initializing the estimation of market beta’s and/or rolling residual variances required for sorting portfolios on BETA and/or RESVAR. This boolean is set internally - no need for user to specify it externally.

Type

bool, default True

(Auxiliary) Methods/Attributes

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.

getFactorRegResults

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

Primary Methods/Attributes

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.

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.

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.

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.