roll_var

Defined in fynance.metrics

roll_var(X, alpha=0.05, w=252, method='historical')[source]

Rolling Value-at-Risk of a price/equity curve over a trailing window.

Causal trailing estimate of var: each output point uses only the w returns observed up to and including that point, so the output has a w-point NaN head (there is no well-defined estimate before the window fills).

Parameters:
Xarray_like

Time-series of price, performance or index (a single curve), shape (T,).

alphafloat, optional

Tail probability, in (0, 1). Default is 0.05.

wint, optional

Size of the trailing window, in number of returns. Default is 252.

method{‘historical’, ‘gaussian’, ‘cornish_fisher’}, optional

Estimation method, see var. Default is ‘historical’.

Returns:
np.ndarray[np.float64, ndim=1] of shape (T,)

Rolling Value-at-Risk; the first w values are NaN.

See also

var, roll_cvar, roll_mdd

Examples

>>> import numpy as np
>>> X = np.array([100., 99., 103., 95., 101., 98., 104., 90., 108., 97.,
...                102.])
>>> out = roll_var(X, alpha=0.4, w=5, method='historical')
>>> np.isnan(out[:5]).all()
True
>>> round(out[5], 4)
0.0297