class_docstr: This analyzer uses 4 children analyzers to collect data and transforms it
  in to a data set compatible with ``pyfolio``
  
  Children Analyzer
  
    - ``TimeReturn``
  
      Used to calculate the returns of the global portfolio value
  
    - ``PositionsValue``
  
      Used to calculate the value of the positions per data. It sets the
      ``headers`` and ``cash`` parameters to ``True``
  
    - ``Transactions``
  
      Used to record each transaction on a data (size, price, value). Sets
      the ``headers`` parameter to ``True``
  
    - ``GrossLeverage``
  
      Keeps track of the gross leverage (how much the strategy is invested)
  
  Params:
    These are passed transparently to the children
  
    - timeframe (default: ``bt.TimeFrame.Days``)
  
      If ``None`` then the timeframe of the 1st data of the system will be
      used
  
    - compression (default: `1``)
  
      If ``None`` then the compression of the 1st data of the system will be
      used
  
  Both ``timeframe`` and ``compression`` are set following the default
  behavior of ``pyfolio`` which is working with *daily* data and upsample it
  to obtaine values like yearly returns.
  
  Methods:
  
    - get_analysis
  
      Returns a dictionary with returns as values and the datetime points for
      each return as keys
docstr: Returns a tuple of 4 elements which can be used for further processing with
    ``pyfolio``
  
    returns, positions, transactions, gross_leverage
  
  Because the objects are meant to be used as direct input to ``pyfolio``
  this method makes a local import of ``pandas`` to convert the internal
  *backtrader* results to *pandas DataFrames* which is the expected input
  by, for example, ``pyfolio.create_full_tear_sheet``
  
  The method will break if ``pandas`` is not installed
code: def get_pf_items(self):
      """Returns a tuple of 4 elements which can be used for further processing with
        ``pyfolio``
  
        returns, positions, transactions, gross_leverage
  
      Because the objects are meant to be used as direct input to ``pyfolio``
      this method makes a local import of ``pandas`` to convert the internal
      *backtrader* results to *pandas DataFrames* which is the expected input
      by, for example, ``pyfolio.create_full_tear_sheet``
  
      The method will break if ``pandas`` is not installed
      """
      # keep import local to avoid disturbing installations with no pandas
      import pandas
      from pandas import DataFrame as DF
  
      #
      # Returns
      cols = ["index", "return"]
      returns = DF.from_records(
          iteritems(self.rets["returns"]), index=cols[0], columns=cols
      )
      returns.index = pandas.to_datetime(returns.index)
      returns.index = returns.index.tz_localize("UTC")
      rets = returns["return"]
      #
      # Positions
      pss = self.rets["positions"]
      ps = [[k] + v[-2:] for k, v in iteritems(pss)]
      cols = ps.pop(0)  # headers are in the first entry
      positions = DF.from_records(ps, index=cols[0], columns=cols)
      positions.index = pandas.to_datetime(positions.index)
      positions.index = positions.index.tz_localize("UTC")
  
      #
      # Transactions
      txss = self.rets["transactions"]
      txs = list()
      # The transactions have a common key (date) and can potentially happend
      # for several assets. The dictionary has a single key and a list of
      # lists. Each sublist contains the fields of a transaction
      # Hence the double loop to undo the list indirection
      for k, v in iteritems(txss):
          for v2 in v:
              txs.append([k] + v2)
  
      cols = txs.pop(0)  # headers are in the first entry
      transactions = DF.from_records(txs, index=cols[0], columns=cols)
      transactions.index = pandas.to_datetime(transactions.index)
      transactions.index = transactions.index.tz_localize("UTC")
  
      # Gross Leverage
      cols = ["index", "gross_lev"]
      gross_lev = DF.from_records(
          iteritems(self.rets["gross_lev"]), index=cols[0], columns=cols
      )
  
      gross_lev.index = pandas.to_datetime(gross_lev.index)
      gross_lev.index = gross_lev.index.tz_localize("UTC")
      glev = gross_lev["gross_lev"]
  
      # Return all together
      return rets, positions, transactions, glev
  
file_path: backtrader/backtrader/analyzers/pyfolio.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import collections
  import backtrader
  from backtrader.utils.py3 import items, iteritems
  from .None import TimeReturn, PositionsValue, Transactions, GrossLeverage
label_desc: Use image node_id 3 for calling the PyFolio obj's underlying member method code with example usage: obj.get_pf_items() and returns: rets,  positions,  transactions,  glev