def var_historic(r, level=5):
    '\n    Returns the historic Value at Risk at a specified level\n    i.e. returns the number such that "level" percent of the returns\n    fall below that number, and the (100-level) percent are above\n    '
    r = r[((r != 0) & r.notnull())]
    if isinstance(r, pd.DataFrame):
        return r.aggregate(var_historic, level=level)
    elif isinstance(r, pd.Series):
        return (- np.percentile(r, level))
    else:
        raise TypeError('Expected r to be a Series or DataFrame')
Returns the historic Value at Risk at a specified level
i.e. returns the number such that "level" percent of the returns
fall below that number, and the (100-level) percent are above
def var_historic(r, level=5):
    '\n    Returns the historic Value at Risk at a specified level\n    i.e. returns the number such that "level" percent of the returns\n    fall below that number, and the (100-level) percent are above\n    '
    r = r[((r != 0) & r.notnull())]
    if isinstance(r, pd.DataFrame):
        return r.aggregate(var_historic, level=level)
    elif isinstance(r, pd.Series):
        return (- np.percentile(r, level))
    else:
        raise TypeError('Expected r to be a Series or DataFrame')