finds.backtesting.backtesting
Utilities for backtesting
Copyright 2022, Terence Lim
MIT License
- finds.backtesting.backtesting.bivariate_sorts(stocks: Stocks, label: str, signals: Signals, rebalbeg: int, rebalend: int, window: int = 0, pct: Tuple[float, float] = (30.0, 70.0), leverage: float = 1.0, months: List[int] = [], minobs: int = 100, minprc: float = 0.0, mincap: float = 0.0, maxdecile: int = 10) Tuple[Dict, Dict, Dict] [source]
Generate monthly time series of holdings by two-way sort procedure
- Parameters:
stocks – Stocks object for accessing stock returns and price data
label – Name of signal to retrieve
signals – Call to extract cross section of values for the signal
rebalbeg – First rebalance date (YYYYMMDD)
rebalend – Last holding date (YYYYMMDD)
pct – Percentile breakpoints to sort high, medium and low buckets
window – No. of months to look back for signal values; 0 is exact month
months – Months (e.g. 6=June) to retrieve univ; empty for all months
maxdecile – Include largest stocks decile from 1 through maxdecile
mincap – Minimum market cap
minobs – Minimum required sample size with non-missing signal values
leverage – Multiplier for leverage or shorting
- Returns
3-tuple of spread holdings, smb holdings, and subportfolio sizes
Notes:
Independent sort by median (NYSE) mkt cap and 30/70 (NYSE) HML percentiles
Subportfolios of the intersections are value-weighted;
Spread portfolios are equal-weighted of subportfolios
Portfolio are resorted every June; and other months’ holdings are adjusted by monthly realized retx (i.e. dividends not reinvested)
- finds.backtesting.backtesting.univariate_sorts(stocks: Stocks, label: str, signals: Signals, rebalbeg: int, rebalend: int, window: int = 0, months: List[int] = [], pct: Tuple[float, float] = (20.0, 80.0), leverage: float = 1.0, minobs: int = 100, minprc: int = 0, mincap: int = 0, maxdecile: int = 10) Dict[int, Series] [source]
Monthly series of cap-weighted holdings of univariate spread portfolios
- Parameters:
stocks – Stocks object for accessing stock returns and price data
label – Name of signal to retrieve
signals – Call to extract cross section of values for the signal
rebalbeg – First rebalance date (YYYYMMDD)
rebalend – Last holding date (YYYYMMDD)
pct – Percentile breakpoints to sort high, medium and low buckets
window – No. of months to look back for signal values; 0 is exact month
months – Months (e.g. 6=June) to retrieve univ; empty for all months
maxdecile – Include largest stocks decile from 1 through maxdecile
mincap – Minimum market cap
minobs – Minimum required sample size with non-missing signal values
leverage – Multiplier for leverage or shorting