def information_ratio(returns, factor_returns): """ Determines the Information ratio of a strategy. Parameters ---------- returns : pd.Series or np.ndarray Daily returns of the strategy, noncumulative. - See full explanation in :func:`~empyrical.stats.cum_returns`. factor_returns: float / series Benchmark return to compare returns against. Returns ------- float The information ratio. Note ----- See https://en.wikipedia.org/wiki/information_ratio for more details. """ if len(returns) < 2: return np.nan active_return = _adjust_returns(returns, factor_returns) tracking_error = nanstd(active_return, ddof=1) if np.isnan(tracking_error): return 0.0 if tracking_error == 0: return np.nan return nanmean(active_return) / tracking_error
def tracking_error(returns, factor_returns): """ Calculate standard deviation of portfolio return - index return and annualize it """ active_return = returns - factor_returns tracking_err = np.nan_to_num(nanstd(active_return, ddof=1, axis=0)) return tracking_err
def annual_volatility(returns, period=DAILY, alpha=2.0, annualization=None): """ Determines the annual volatility of a strategy. Parameters ---------- returns : pd.Series or np.ndarray Periodic returns of the strategy, noncumulative. - See full explanation in :func:`~empyrical.stats.cum_returns`. period : str, optional Defines the periodicity of the 'returns' data for purposes of annualizing. Value ignored if `annualization` parameter is specified. Defaults are: 'monthly':12 'weekly': 52 'daily': 252 alpha : float, optional Scaling relation (Levy stability exponent). annualization : int, optional Used to suppress default values available in `period` to convert returns into annual returns. Value should be the annual frequency of `returns`. Returns ------- float Annual volatility. """ if len(returns) < 2: return np.nan ann_factor = annualization_factor(period, annualization) volatility = nanstd(returns, ddof=1) * (ann_factor ** (1.0 / alpha)) return volatility