def backtest_ws(r, estimation_window=60, weighting=weight_ew, verbose=False, **kwargs):
    '\n    Backtests a given weighting scheme, given some parameters:\n    r : asset returns to use to build the portfolio\n    estimation_window: the window to use to estimate parameters\n    weighting: the weighting scheme to use, must be a function that takes "r", and a variable number of keyword-value arguments\n    '
    n_periods = r.shape[0]
    windows = [(start, (start + estimation_window)) for start in range((n_periods - estimation_window))]
    weights = [weighting(r.iloc[win[0]:win[1]], **kwargs) for win in windows]
    weights = pd.DataFrame(weights, index=r.iloc[estimation_window:].index, columns=r.columns)
    returns = (weights * r).sum(axis='columns', min_count=1)
    return returns
Backtests a given weighting scheme, given some parameters:
r : asset returns to use to build the portfolio
estimation_window: the window to use to estimate parameters
weighting: the weighting scheme to use, must be a function that takes "r", and a variable number of keyword-value arguments
def backtest_ws(r, estimation_window=60, weighting=weight_ew, verbose=False, **kwargs):
    '\n    Backtests a given weighting scheme, given some parameters:\n    r : asset returns to use to build the portfolio\n    estimation_window: the window to use to estimate parameters\n    weighting: the weighting scheme to use, must be a function that takes "r", and a variable number of keyword-value arguments\n    '
    n_periods = r.shape[0]
    windows = [(start, (start + estimation_window)) for start in range((n_periods - estimation_window))]
    weights = [weighting(r.iloc[win[0]:win[1]], **kwargs) for win in windows]
    weights = pd.DataFrame(weights, index=r.iloc[estimation_window:].index, columns=r.columns)
    returns = (weights * r).sum(axis='columns', min_count=1)
    return returns