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




