code: def handle_data(algo, data):
      algo.days += 1
      if algo.days < algo.window_length:
          return
  
      if algo.init:
          rebalance_portfolio(algo, data, algo.b_t)
          algo.init = False
          return
  
      m = algo.m
  
      x_tilde = np.zeros(m)
  
      # find relative moving average price for each asset
      mavgs = data.history(
          algo.sids, "price", algo.window_length, "1d"
      ).mean()
      for i, sid in enumerate(algo.sids):
          price = data.current(sid, "price")
          # Relative mean deviation
          x_tilde[i] = mavgs[sid] / 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(algo.b_t, x_tilde)
      weight = algo.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 = algo.b_t + step_size * mark_rel_dev
      b_norm = simplex_projection(b)
      np.testing.assert_almost_equal(b_norm.sum(), 1)
  
      rebalance_portfolio(algo, data, b_norm)
  
      # update portfolio
      algo.b_t = b_norm
  
file_path: zipline/zipline/examples/olmar.py
imports: import sys
  import logbook
  import numpy
  from zipline.finance import commission, slippage
label_desc: Use image node_id 2 for calling a global function with example usage: handle_data(algo, data) without return types