finds.backtesting.riskpremium

Evaluate risk premiums from cross-sectional regressions

Copyright 2022, Terence Lim

MIT License

class finds.backtesting.riskpremium.RiskPremium(sql: SQL, bench: Benchmarks, rf: str, end: int)[source]

Bases: object

Compute and test of factor loading risk premiums

Parameters:
  • sql – Connection to user database to store results

  • bench – Benchmark dataset of market and indexreturns

  • rf – Name of riskfree rate from bench database

  • end – Last date of price and returns data

__call__(stocks: Stocks, loadings: Dict[int, DataFrame], weights: str = '', standardize: List[str] = []) Series[source]

Estimate factor risk premiums with cross-sectional FM regressions

Parameters:
  • stocks – Stocks’ returns data

  • loadings – dict keyed by rebalance date of loadings DataFrames

  • standardize – List of columns to demean and rescale (eql-wtd std = 1)

  • weights – List of weights for weighted least squares and demean

Returns:

Series of means and stderrs of FM cross-sectional regression

fit(benchnames: List[str] = []) List[DataFrame][source]

Compute risk premiums and benchmark correlations

plot(factors: List[str] = [], num: int = 1, fontsize: int = 8, figsize: Tuple[float, float] = (10, 5))[source]

Plot computed time series of factor returns