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 performance issues on Pandas Data Frame



  • 0_1531641830697_Screen Shot 2018-07-15 at 4.03.15 PM.png

    PyFolio is returning a single value for each day when generating data frame for returns and positions. Meanwhile, transaction data frame shows intra-day execution.

    When the data is ingested from Generic CSV feed, PyFolio is able to iterate through each data observation and return positions and returns value


  • administrators

    You may want to let us know (in code terms) what you have done and what your expectations are. Your message isn't clear at all.

    In any case one can tray to read between the lines that your problems may have to do with intraday data and pyfolio expects daily returns (at least with the versions that worked, because the API kept changing and there could of course have been an update)



  • Apologies for not articulating the problem well enough in the first post. However, you have correctly inferred that I am facing issues with not being able to see intraday positions and returns from PyFolio analyzer.

    My run strat function looks like this:

    def runstrat1():
    
    args = parse_args()
    
    # Create a cerebro entity
    cerebro = bt.Cerebro(stdstats=True)
    
    # Add a strategy
    cerebro.addstrategy(strategy1.TestStrategy)
    
    # Get a pandas dataframe
    datapath = ('./dataset/data2.csv')
    dataframe = pd.read_csv(datapath,parse_dates=True,index_col=0)
    
    # Pass it to the backtrader datafeed and add it to the cerebro
    data = PandasDataExpanded(dataname=dataframe)
    
    cerebro.adddata(data)
    
    # Add PyFolio Analyzer
    cerebro.addanalyzer(bt.analyzers.PyFolio, _name='pyfolio')
    
    # Run over everything
    strats = cerebro.run()
    
    returns, positions, transactions, gross_lev = pyfoliozer.get_pf_items()
    
        for each in strat0.analyzers:
            each.print()
    
        print(positions['cash'])
    
        # Plot the result
        if not args.noplot:
            cerebro.plot(style='bar')
    
        return positions
    

    My class for pandas data feed look like this:

    class PandasDataExpanded(btfeeds.PandasData):
    
    lines = ('barCount',)
    params = (('barCount', -1),)