The volatility of a stock is a measurement of the amount change of variance in the price of a stock over a specific period of time. It is common to compare the volatility to another stock to get a feel for which may have less risk or to a market index to compare the stock's volatility to the overall market. Generally, the higher the volatility, the riskier the investment in that stock.
Volatility is calculated by taking a rolling-window standard deviation on percentage change in a stock (and scaling it relative to the size of the window). The size of the window affects the overall result. The wider a window, the less representative the measurement will become. As the window narrows, the result approaches the standard deviation. So, it is a bit of an art to pick the proper window size based on the data sampling frequency. Fortunately, pandas makes this very easy to modify interactively.
As a demonstration, the following calculates the volatility of the stocks in our sample given a window of 75
periods:
In [33]: # 75 period minimum min_periods = 75 # calculate the volatility vol = pd.stats.moments.rolling_std(daily_pc, min_periods) * np.sqrt(min_periods) # plot it vol.plot(figsize=(10, 8));
The output is seen in the following screenshot:
Lines higher on the chart represent overall higher volatility, and the change of volatility over time is shown.
3.21.104.183