Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Pyfolio Integration Error : Grouper and axis must be same length

    General Code/Help
    2
    2
    972
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Aadhunik Sharma
      Aadhunik Sharma last edited by

      Hi there,
      I am trying to generate tear sheet for intraday strategy. I have followed every single part of the documentation but failed to resolve this issue.

      1
      
      pf.create_full_tear_sheet(returns=retur, positions=positions, transactions=transactions, estimate_intraday=True)
      
      ---------------------------------------------------------------------------
      ValueError                                Traceback (most recent call last)
      <ipython-input-116-ea97606746b1> in <module>
      ----> 1 pf.create_full_tear_sheet(returns=retur, positions=positions, transactions=transactions, estimate_intraday=True)
      
      ~/anaconda3/lib/python3.7/site-packages/pyfolio/tears.py in create_full_tear_sheet(returns, positions, transactions, market_data, benchmark_rets, slippage, live_start_date, sector_mappings, bayesian, round_trips, estimate_intraday, hide_positions, cone_std, bootstrap, unadjusted_returns, style_factor_panel, sectors, caps, shares_held, volumes, percentile, turnover_denom, set_context, factor_returns, factor_loadings, pos_in_dollars, header_rows, factor_partitions)
          197 
          198     positions = utils.check_intraday(estimate_intraday, returns,
      --> 199                                      positions, transactions)
          200 
          201     create_returns_tear_sheet(
      
      ~/anaconda3/lib/python3.7/site-packages/pyfolio/utils.py in check_intraday(estimate, returns, positions, transactions)
          306     elif estimate:
          307         if positions is not None and transactions is not None:
      --> 308             return estimate_intraday(returns, positions, transactions)
          309         else:
          310             raise ValueError('Positions and txns needed to estimate intraday')
      
      ~/anaconda3/lib/python3.7/site-packages/pyfolio/utils.py in estimate_intraday(returns, positions, transactions, EOD_hour)
          350     # Cumulate transaction amounts each day
          351     txn_val['date'] = txn_val.index.date
      --> 352     txn_val = txn_val.groupby('date').cumsum()
          353 
          354     # Calculate exposure, then take peak of exposure every day
      
      ~/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, observed, **kwargs)
         7892             squeeze=squeeze,
         7893             observed=observed,
      -> 7894             **kwargs
         7895         )
         7896 
      
      ~/anaconda3/lib/python3.7/site-packages/pandas/core/groupby/groupby.py in groupby(obj, by, **kwds)
         2520         raise TypeError("invalid type: {}".format(obj))
         2521 
      -> 2522     return klass(obj, by, **kwds)
      
      ~/anaconda3/lib/python3.7/site-packages/pandas/core/groupby/groupby.py in __init__(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, observed, **kwargs)
          389                 sort=sort,
          390                 observed=observed,
      --> 391                 mutated=self.mutated,
          392             )
          393 
      
      ~/anaconda3/lib/python3.7/site-packages/pandas/core/groupby/grouper.py in _get_grouper(obj, key, axis, level, sort, observed, mutated, validate)
          650                 in_axis=in_axis,
          651             )
      --> 652             if not isinstance(gpr, Grouping)
          653             else gpr
          654         )
      
      ~/anaconda3/lib/python3.7/site-packages/pandas/core/groupby/grouper.py in __init__(self, index, grouper, obj, name, level, sort, observed, in_axis)
          257         self.name = name
          258         self.level = level
      --> 259         self.grouper = _convert_grouper(index, grouper)
          260         self.all_grouper = None
          261         self.index = index
      
      ~/anaconda3/lib/python3.7/site-packages/pandas/core/groupby/grouper.py in _convert_grouper(axis, grouper)
          680     elif isinstance(grouper, (list, Series, Index, np.ndarray)):
          681         if len(grouper) != len(axis):
      --> 682             raise ValueError("Grouper and axis must be same length")
          683         return grouper
          684     else:
      
      ValueError: Grouper and axis must be same length
      
      
      

      Please help

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        1. Pyfolio integration is deprecated due to API changes

        2. Pyfolio was not designed for intraday data.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors