def style_analysis(dependent_variable, explanatory_variables):
    '\n    Returns the optimal weights that minimizes the Tracking error between\n    a portfolio of the explanatory variables and the dependent variable\n    '
    n = explanatory_variables.shape[1]
    init_guess = np.repeat((1 / n), n)
    bounds = (((0.0, 1.0),) * n)
    weights_sum_to_1 = {'type': 'eq', 'fun': (lambda weights: (np.sum(weights) - 1))}
    solution = minimize(portfolio_tracking_error, init_guess, args=(dependent_variable, explanatory_variables), method='SLSQP', options={'disp': False}, constraints=(weights_sum_to_1,), bounds=bounds)
    weights = pd.Series(solution.x, index=explanatory_variables.columns)
    return weights
Returns the optimal weights that minimizes the Tracking error between
a portfolio of the explanatory variables and the dependent variable
def style_analysis(dependent_variable, explanatory_variables):
    '\n    Returns the optimal weights that minimizes the Tracking error between\n    a portfolio of the explanatory variables and the dependent variable\n    '
    n = explanatory_variables.shape[1]
    init_guess = np.repeat((1 / n), n)
    bounds = (((0.0, 1.0),) * n)
    weights_sum_to_1 = {'type': 'eq', 'fun': (lambda weights: (np.sum(weights) - 1))}
    solution = minimize(portfolio_tracking_error, init_guess, args=(dependent_variable, explanatory_variables), method='SLSQP', options={'disp': False}, constraints=(weights_sum_to_1,), bounds=bounds)
    weights = pd.Series(solution.x, index=explanatory_variables.columns)
    return weights