liveBook · Manning

Volatility

As explained in Outlier Detection in Python

Volatility is the degree and rate of fluctuation in a quantity across observations over time.

Volatility describes how much and how often values fluctuate over time. In anomaly analysis, unusual volatility can reveal behavior that individual readings do not: a timeline may contain normal values yet vary unusually or become more variable. section 17.2.7 section 12.7

Measure volatility through complementary time-series features:

  • Calculate standard deviation within each month to represent the overall spread of values. section 17.2.7
  • Track the fraction of values larger than their predecessors to capture how often a series rises or falls. section 17.2.7
  • Count local peaks to describe repeated ups and downs, then compare the resulting features across periods or entities. section 17.2.7 section 12.7

Purchasing timelines

Aggregate purchasing data by staff, product, and day, then inspect count, unit cost, and total-cost timelines. Increasing variability in total cost may look suspicious, but should be compared with other segments because chance can produce apparent volatility. section 12.7

Listing 17.11 Engineering features for the volatility each month
import statistics
 
df['Lag -1'] = df['Values'].shift(-1)
df['Bigger'] = df['Values'] > df['Lag 1']
df['Peak'] = (df['Values'] > df['Lag 1']) & (df['Values'] > df['Lag -1'])
 
df['YM'] = df.index.strftime("%Y%m")
df.groupby(['YM'])['Values'].std()
df.groupby(['YM'])['Bigger'].mean()
df.groupby(['YM'])['Peak'].mean()

Shows Python-style feature engineering for monthly standard deviation, increases, and local peaks. section 17.2.7

How Outlier Detection in Python covers it

How deep it goes
Engineers monthly standard deviation, increase fractions, and peak fractions, but stops short of a universal volatility detector.
Examples
Uses monthly standard deviations, rising-value fractions, peak fractions, and purchasing timelines with potentially increasing variability.
What it assumes
Assumes grouped time-series data and basic descriptive statistics, while demonstrating feature construction from raw observations.
What you can do after
Evaluate/understand which periods or entities show unusually high or low variability and require further comparison.
How it connects
Connects time series, outliers, trends, anomaly detection, fraud detection, and aggregation.

Also explained in

Compare how 5 books explain volatility →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Outlier Detection in Python. The section links point to the parts of the book it draws on.