code: def rebalance_portfolio(algo, data, desired_port):
      # rebalance portfolio
      desired_amount = np.zeros_like(desired_port)
      current_amount = np.zeros_like(desired_port)
      prices = np.zeros_like(desired_port)
  
      if algo.init:
          positions_value = algo.portfolio.starting_cash
      else:
          positions_value = (
              algo.portfolio.positions_value + algo.portfolio.cash
          )
  
      for i, sid in enumerate(algo.sids):
          current_amount[i] = algo.portfolio.positions[sid].amount
          prices[i] = data.current(sid, "price")
  
      desired_amount = np.round(desired_port * positions_value / prices)
  
      algo.last_desired_port = desired_port
      diff_amount = desired_amount - current_amount
  
      for i, sid in enumerate(algo.sids):
          algo.order(sid, diff_amount[i])
  
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 3 for calling a global function with example usage: rebalance_portfolio(algo, data, desired_port) without return types