def cvar_historic(r, level=5):
    '\n    Computes the Conditional VaR of Series or DataFrame\n    '
    r = r[((r != 0) & r.notnull())]
    if isinstance(r, pd.Series):
        is_beyond = (r <= (- var_historic(r, level=level)))
        return (- r[is_beyond].mean())
    elif isinstance(r, pd.DataFrame):
        return r.aggregate(cvar_historic, level=level)
    else:
        raise TypeError('Expected r to be a Series or DataFrame')
Computes the Conditional VaR of Series or DataFrame
def cvar_historic(r, level=5):
    '\n    \n    '
    r = r[((r != 0) & r.notnull())]
    if isinstance(r, pd.Series):
        is_beyond = (r <= (- var_historic(r, level=level)))
        return (- r[is_beyond].mean())
    elif isinstance(r, pd.DataFrame):
        return r.aggregate(cvar_historic, level=level)
    else:
        raise TypeError('Expected r to be a Series or DataFrame')