code: def extract_rets_pos_txn_from_zipline(backtest):
      """
      Extract returns, positions, transactions and leverage from the
      backtest data structure returned by zipline.TradingAlgorithm.run().
  
      The returned data structures are in a format compatible with the
      rest of pyfolio and can be directly passed to
      e.g. tears.create_full_tear_sheet().
  
      Parameters
      ----------
      backtest : pd.DataFrame
          DataFrame returned by zipline.TradingAlgorithm.run()
  
      Returns
      -------
      returns : pd.Series
          Daily returns of strategy.
           - See full explanation in tears.create_full_tear_sheet.
      positions : pd.DataFrame
          Daily net position values.
           - See full explanation in tears.create_full_tear_sheet.
      transactions : pd.DataFrame
          Prices and amounts of executed trades. One row per trade.
           - See full explanation in tears.create_full_tear_sheet.
  
  
      Example (on the Quantopian research platform)
      ---------------------------------------------
      >>> backtest = my_algo.run()
      >>> returns, positions, transactions =
      >>>     pyfolio.utils.extract_rets_pos_txn_from_zipline(backtest)
      >>> pyfolio.tears.create_full_tear_sheet(returns,
      >>>     positions, transactions)
      """
  
      backtest.index = backtest.index.normalize()
      if backtest.index.tzinfo is None:
          backtest.index = backtest.index.tz_localize("UTC")
      returns = backtest.returns
      raw_positions = []
      for dt, pos_row in backtest.positions.iteritems():
          df = pd.DataFrame(pos_row)
          df.index = [dt] * len(df)
          raw_positions.append(df)
      if not raw_positions:
          raise ValueError("The backtest does not have any positions.")
      positions = pd.concat(raw_positions)
      positions = pos.extract_pos(positions, backtest.ending_cash)
      transactions = txn.make_transaction_frame(backtest.transactions)
      if transactions.index.tzinfo is None:
          transactions.index = transactions.index.tz_localize("utc")
  
      return returns, positions, transactions
  
imports: from __future__ import division
  import warnings
  from itertools import cycle
  from matplotlib.pyplot import cm
  import numpy
  import pandas
  from IPython.display import display, HTML
  import empyrical.utils
  from .None import pos
  from .None import txn
label_desc: Use image node_id 6 for calling a global function with example usage: extract_rets_pos_txn_from_zipline(backtest) and returns: returns,  positions,  transactions