Previous topic

fynance.features.metrics.annual_return

Next topic

fynance.features.metrics.calmar

fynance.features.metrics.annual_volatility

fynance.features.metrics.annual_volatility(X, period=252, log=True, axis=0, dtype=None, ddof=0)

Compute the annualized volatility of each X’ series.

In finance, volatility is the degree of variation of a trading price series over time as measured by the standard deviation of logarithmic returns [2].

Parameters:
X : np.ndarray[dtype, ndim=1 or 2]

Time-series of price, performance or index.

period : int, optional

Number of period per year, default is 252 (trading days per year).

log : bool, optional
  • If True then logarithmic returns are computed.
  • Else then returns in percentage are computed.
axis : {0, 1}, optional

Axis along wich the computation is done. Default is 0.

dtype : np.dtype, optional

The type of the output array. If dtype is not given, infer the data type from X input.

ddof : int, optional

Means Delta Degrees of Freedom, the divisor used in calculations is T - ddof, where T represents the number of elements in time axis. Default is 0.

Returns:
dtype or np.ndarray([dtype, ndim=1])

Values of annualized volatility for each series.

Notes

Let \(Var\) the variance function of a random variable:

\[annualVolatility = \sqrt{period \times Var(R_{1:T})}\]

Where, \(R_1 = 0\) and \(R_{2:T} = \begin{cases}ln(\frac{X_{2:T}} {X_{1:T-1}}) \text{, if log=True} \\ \frac{X_{2:T}}{X_{1:T-1}} - 1 \text{, otherwise} \\ \end{cases}\)

References

[2]https://en.wikipedia.org/wiki/Volatility_(finance)

Examples

Assume series of monthly prices:

>>> X = np.array([100, 110, 105, 110, 120, 108]).astype(np.float64)
>>> annual_volatility(X, period=12, log=True, ddof=1)
0.2731896268610321
>>> annual_volatility(X.reshape([6, 1]), period=12, log=False)
array([0.24961719])