docstr: Clear out any assets that have expired before starting a new sim day.
  
  Performs two functions:
  
  1. Finds all assets for which we have open orders and clears any
     orders whose assets are on or after their auto_close_date.
  
  2. Finds all assets for which we have positions and generates
     close_position events for any assets that have reached their
     auto_close_date.
docstr_tok: ["Clear","out","any","assets","that","have","expired","before","starting","a","new","sim","day",".","Performs","two","functions",":","1",".","Finds","all","assets","for","which","we","have","open","orders","and","clears","any","orders","whose","assets","are","on","or","after","their","auto_close_date",".","2",".","Finds","all","assets","for","which","we","have","positions","and","generates","close_position","events","for","any","assets","that","have","reached","their","auto_close_date","."]
code: def _cleanup_expired_assets(self, dt, position_assets):
      """
      Clear out any assets that have expired before starting a new sim day.
  
      Performs two functions:
  
      1. Finds all assets for which we have open orders and clears any
         orders whose assets are on or after their auto_close_date.
  
      2. Finds all assets for which we have positions and generates
         close_position events for any assets that have reached their
         auto_close_date.
      """
      algo = self.algo
  
      def past_auto_close_date(asset):
          acd = asset.auto_close_date
          return acd is not None and acd <= dt
  
      # Remove positions in any sids that have reached their auto_close date.
      assets_to_clear = [
          asset
          for asset in position_assets
          if past_auto_close_date(asset)
      ]
      perf_tracker = algo.perf_tracker
      data_portal = self.data_portal
      for asset in assets_to_clear:
          perf_tracker.process_close_position(asset, dt, data_portal)
  
      # Remove open orders for any sids that have reached their
      # auto_close_date.
      blotter = algo.blotter
      assets_to_cancel = set(
          [
              asset
              for asset in blotter.open_orders
              if past_auto_close_date(asset)
          ]
      )
      for asset in assets_to_cancel:
          blotter.cancel_all_orders_for_asset(asset)
  
file_path: catalyst/catalyst/gens/tradesimulation.py
imports: from contextlib2 import ExitStack
  from logbook import Logger, Processor
  from pandas.tslib import normalize_date
  from catalyst.protocol import BarData
  from catalyst.utils.api_support import ZiplineAPI
  from six import viewkeys
  from catalyst.gens.sim_engine import BAR, SESSION_START, SESSION_END, MINUTE_END, BEFORE_TRADING_START_BAR
  from catalyst.constants import LOG_LEVEL
label_desc: Use image node_id 5 for calling the AlgorithmSimulator obj's underlying member method code with example usage: obj._cleanup_expired_assets(dt, position_assets) and returns: unknown