code: def single_with_simulator(
      backtest_config: dict,
      orders: pd.DataFrame,
      split: Literal["stock", "day"] = "stock",
      cash_limit: float | None = None,
      generate_report: bool = False,
  ) -> Union[Tuple[pd.DataFrame, dict], pd.DataFrame]:
      """Run backtest in a single thread with SingleAssetOrderExecution simulator. The orders will be executed day by day.
      A new simulator will be created and used for every single-day order.
  
      Parameters
      ----------
      backtest_config:
          Backtest config
      orders:
          Orders to be executed. Example format:
                   datetime instrument  amount  direction
              0  2020-06-01       INST   600.0          0
              1  2020-06-02       INST   700.0          1
              ...
      split
          Method to split orders. If it is "stock", split orders by stock. If it is "day", split orders by date.
      cash_limit
          Limitation of cash.
      generate_report
          Whether to generate reports.
  
      Returns
      -------
          If generate_report is True, return execution records and the generated report. Otherwise, return only records.
      """
      init_qlib(backtest_config["qlib"])
  
      stocks = orders.instrument.unique().tolist()
  
      reports = []
      decisions = []
      for _, row in orders.iterrows():
          date = pd.Timestamp(row["datetime"])
          start_time = pd.Timestamp(
              backtest_config["start_time"]
          ).replace(year=date.year, month=date.month, day=date.day)
          end_time = pd.Timestamp(backtest_config["end_time"]).replace(
              year=date.year, month=date.month, day=date.day
          )
          order = Order(
              stock_id=row["instrument"],
              amount=row["amount"],
              direction=OrderDir(row["direction"]),
              start_time=start_time,
              end_time=end_time,
          )
  
          executor_config = _get_multi_level_executor_config(
              strategy_config=backtest_config["strategies"],
              cash_limit=cash_limit,
              generate_report=generate_report,
              data_granularity=backtest_config["data_granularity"],
          )
  
          exchange_config = copy.deepcopy(backtest_config["exchange"])
          exchange_config.update(
              {
                  "codes": stocks,
                  "freq": backtest_config["data_granularity"],
              }
          )
  
          simulator = SingleAssetOrderExecution(
              order=order,
              executor_config=executor_config,
              exchange_config=exchange_config,
              qlib_config=None,
              cash_limit=None,
          )
  
          reports.append(simulator.report_dict)
          decisions += simulator.decisions
  
      indicator_1day_objs = [
          report["indicator_dict"]["1day"][1] for report in reports
      ]
      indicator_info = {
          k: v
          for obj in indicator_1day_objs
          for k, v in obj.order_indicator_his.items()
      }
      records = _convert_indicator_to_dataframe(indicator_info)
      assert records is None or not np.isnan(records["ffr"]).any()
  
      if generate_report:
          _report = _generate_report(
              decisions, [report["indicator"] for report in reports]
          )
  
          if split == "stock":
              stock_id = orders.iloc[0].instrument
              report = {stock_id: _report}
          else:
              day = orders.iloc[0].datetime
              report = {day: _report}
  
          return records, report
      else:
          return records
  
imports: from __future__ import annotations
  import argparse
  import copy
  import os
  import pickle
  from collections import defaultdict
  from pathlib import Path
  from typing import Dict, List, Optional, Tuple, Union, cast
  import numpy
  import pandas
  import torch
  from joblib import Parallel, delayed
  from qlib.backtest import INDICATOR_METRIC, collect_data_loop, get_strategy_executor
  from qlib.backtest.decision import BaseTradeDecision, Order, OrderDir, TradeRangeByTime
  from qlib.backtest.executor import SimulatorExecutor
  from qlib.backtest.high_performance_ds import BaseOrderIndicator
  from qlib.rl.contrib.naive_config_parser import get_backtest_config_fromfile
  from qlib.rl.contrib.utils import read_order_file
  from qlib.rl.data.integration import init_qlib
  from qlib.rl.order_execution.simulator_qlib import SingleAssetOrderExecution
  from qlib.typehint import Literal
label_desc: Use image node_id 4 for calling a global function with example usage: single_with_simulator(backtest_config, orders, split, cash_limit, generate_report) and returns: records,  report, records