Standard Deviation (volatility)

get_stdev(quotes, lookback_periods, sma_periods=None)

Parameters

name type notes
quotes Iterable[Quote] Iterable of the Quote class or its sub-class.
See here for usage with pandas.DataFrame
lookback_periods int Number of periods (N) in the lookback period. Must be greater than 1 to calculate; however we suggest a larger period for statistically appropriate sample size.
sma_periods int, Optional Number of periods in the moving average of Stdev. Must be greater than 0, if specified.

Historical quotes requirements

You must have at least N periods of quotes to cover the warmup periods.

quotes is an Iterable[Quote] collection of historical price quotes. It should have a consistent frequency (day, hour, minute, etc). See the Guide for more information.

Return

StdevResults[StdevResult]

StdevResult

name type notes
date datetime Date
stdev float, Optional Standard Deviation of Close price over N lookback periods
mean float, Optional Mean value of Close price over N lookback periods
z_score float, Optional Z-Score of current Close price (number of standard deviations from mean)
stdev_sma float, Optional Moving average (SMA) of STDDEV based on sma_periods periods, if specified

Utilities

See Utilities and Helpers for more information.

Example

from stock_indicators import indicators

# This method is NOT a part of the library.
quotes = get_historical_quotes("SPY")

# Calculate 10-period Standard Deviation
results = indicators.get_stdev(quotes, 10)

About Standard Deviation (volatility)

Standard Deviation of Close price over a rolling lookback window. Also known as Historical Volatility (HV). [Discuss] 💬

image

Sources