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/

    'Series' object has no attribute 'columns'

    General Code/Help
    2
    2
    555
    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.
    • N
      Nairpic last edited by

      Hi there,

      I am using the bt.Backtest(bt_strategy, price_data)

      For price_data I am trying to use a Data Frame of my own, extracted from a broker (Oanda) in order to test on batches of timeframes and instruments I want.

      The only thing is after edits of the Dataframe in order to make it similar to the bt.get option my price_data which stores the Dataframe doesn't work and gives me the following error: 'Series' object has no attribute 'columns'

      #I changed the index format to make my strategy with BT work
      EURUSD_df.index=pd.to_datetime(EURUSD_df.index, format = '%Y-%m-%d').strftime('%Y-%m-%d')
      EURUSD_df.tail()
      
      close	high	low	open
      2018-12-27	1.14448	1.14728	1.14271	1.14296
      2018-12-30	1.14649	1.14696	1.14216	1.14372
      2019-01-01	1.13447	1.14970	1.13250	1.14649
      2019-01-02	1.13942	1.14112	1.13077	1.13431
      2019-01-03	1.13951	1.14191	1.13457	1.13930
      
      import talib
      
      !pip install bt
      import bt
      
      import matplotlib.pyplot as plt
      
      EMA_short=talib.EMA(EURUSD_df['close'],timeperiod=10).to_frame()
      EMA_long=talib.EMA(EURUSD_df['close'],timeperiod=40).to_frame()
      
      signal=EMA_long.copy()
      signal[EMA_long.isnull()]=0
      signal[EMA_short>EMA_long]=1
      signal[EMA_short<EMA_long]=-1
      combined_df=bt.merge(signal,EURUSD_df["close"],EMA_short,EMA_long)
      combined_df.columns=["Signal","Price","EMA_short","EMA_long"]
      combined_df.plot(secondary_y=["Signal"])
      
      print(EURUSD_df[['close']])
      #EURUSD_df=EURUSD_df['close'].reset_index
      #print(EURUSD_df['close'])
      price_data=EURUSD_df['close']
      price_data=price_data.append(pd.Series(name='NameOfNewRow'))
      print(price_data)
      
      bt_strategy = bt.Strategy('EMA_crossover',
                                [bt.algos.WeighTarget(signal),
                                bt.algos.Rebalance()])
      bt_backtest = bt.Backtest(bt_strategy,price_data)
      bt_result = bt.run(bt_backtest)
      bt_result.plot(title='Backtest result')
      

      Can someone help/guide me, please?

      Much appreciated!

      Ciprian

      run-out 1 Reply Last reply Reply Quote 0
      • run-out
        run-out @Nairpic last edited by

        @nairpic I think you are in the wrong forum.

        pip install bt
        

        is not backtrader, it's bt. https://github.com/pmorissette/bt

        RunBacktest.com

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