annual_volatility

Defined in fynance.features.metrics

annual_volatility(X, period=252, log=True, axis=0, dtype=None, ddof=0)[source]

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:
Xnp.ndarray[dtype, ndim=1 or 2]

Time-series of price, performance or index.

periodint, optional

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

logbool, 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.

dtypenp.dtype, optional

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

ddofint, 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.

See also

mdd, drawdown, sharpe, annual_return

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

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])