Beta Coefficient

get_beta(eval_history, market_quotes, lookback_periods, beta_type=BetaType.STANDARD)

:warning: Eval and Market quotes have been reversed in v1! Ensure you swap parameter location. (The warning will be shown and it will be removed after v1.0.0')


name type notes
eval_history Iterable[Quote] Historical [evaluation stock] Quotes data should be at any consistent frequency (day, hour, minute, etc).
Need help with pandas.DataFrame?
market_history Iterable[Quote] Historical [market] Quotes data should be at any consistent frequency (day, hour, minute, etc). This market quotes will be used to establish the baseline.
lookback_periods int Number of periods (N) in the lookback period. Must be greater than 0 to calculate; however we suggest a larger period for statistically appropriate sample size and especially when using Beta +/-.
beta_type BetaType, default BetaType.STANDARD Type of Beta to calculate. See BetaType options below.

Historical quotes requirements

You must have at least N periods of quotes to cover the warmup periods. You must have at least the same matching date elements of market_history. Exception will be thrown if not matched. Historical price quotes should have a consistent frequency (day, hour, minute, etc). See the Guide for more information.

BetaType options

from stock_indicators.indicators.common.enums import BetaType
type description
STANDARD Standard Beta only. Uses all historical quotes.
UP Upside Beta only. Uses historical quotes from market up bars only.
DOWN Downside Beta only. Uses historical quotes from market down bars only.
ALL Returns all of the above. Use this option if you want ratio and convexity values returned. Note: 3× slower to calculate.




name type notes
date datetime Date
beta float, Optional Beta coefficient based on N lookback periods
beta_up float, Optional Beta+ (Up Beta)
beta_down float, Optional Beta- (Down Beta)
ratio float, Optional Beta ratio is beta_up/beta_down
convexity float, Optional Beta convexity is (beta_up-beta_down)2
returns_eval float, Optional Returns of evaluated quotes (R)
returns_mrkt float, Optional Returns of market quotes (Rm)


See Utilities and Helpers for more information.


from stock_indicators import indicators
from stock_indicators import BetaType      # Short path, version >= 0.8.1

# This method is NOT a part of the library.
history_SPX = get_history_from_feed("SPX")
history_TSLA = get_history_from_feed("TSLA")

# calculate 20-period Beta coefficient
results = indicators.get_beta(history_SPX, history_TSLA, 20, BetaType.STANDARD)

About Beta Coefficient

Beta shows how strongly one stock responds to systemic volatility of the entire market. Upside Beta (Beta+) and Downside Beta (Beta-), popularized by Harry M. Markowitz, are also included. [Discuss] :speech_balloon: