def optimize(self, date, to_buy, to_sell, parameters):
        # This implementation only process buy signals
        allocations = {}
        for sid in to_sell:
            allocations[sid] = to_sell[sid].amount

        data = to_buy

        #if not self.initialized:
            #self._warm(data)

        x_tilde = np.zeros(self.m)
        b = np.zeros(self.m)

        # find relative moving average price for each security
        for i, stock in enumerate(data):
            price = data[stock].price
            # Relative mean deviation
            if 'mavg' in data[stock]:
                x_tilde[i] = price / data[stock]['mavg']['price']

        ###########################
        # Inside of OLMAR (algo 2)
        x_bar = x_tilde.mean()

        # market relative deviation
        mark_rel_dev = x_tilde - x_bar

        # Expected return with current portfolio
        exp_return = np.dot(self.b_t, x_tilde)
        weight = self.eps - exp_return
        variability = (np.linalg.norm(mark_rel_dev)) ** 2

        # test for divide-by-zero case
        if variability == 0.0:
            step_size = 0
        else:
            step_size = max(0, weight / variability)

        b = self.b_t + step_size * mark_rel_dev
        b_norm = utils.simplex_projection(b)
        np.testing.assert_almost_equal(b_norm.sum(), 1)

        allocations.update(self._rebalance_portfolio(data, b_norm))

        # update portfolio
        self.b_t = b_norm

        #e_ret = 0
        #e_risk = 1
        e_ret = exp_return
        e_risk = variability
        return allocations, e_ret, e_risk
dataset/ETHPy150Open intuition-io/insights/insights/managers/_review/olmar.py/OLMAR.optimize/swapped operands of `/`