In most finance textbooks, we use the standard deviation of returns as a risk measure. This is based on a critical assumption that log returns follow a normal distribution. Both standard deviation and variance could be used to measure uncertainty; the former is usually called volatility itself. For example, if we say that the volatility of IBM is 20 percent, it means that its annualized standard deviation is 20 percent. Using IBM as an example, the following program is used to estimate its annualized volatility:
import numpy as np from matplotlib.finance import quotes_historical_yahoo_ochl as getData # ticker='IBM' begdate=(2009,1,1) enddate=(2013,12,31) p =getData(ticker, begdate, enddate,asobject=True, adjusted=True) ret = p.aclose[1:]/p.aclose[:-1]-1 std_annual=np.std(ret)*np.sqrt(252) print('volatility (std)=',round(std_annual,4)) ('volatility (std)=', 0.2093)