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/

    backtrader data same for 5days vs 50 days

    General Code/Help
    3
    3
    132
    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.
    • R
      Ronan Dunham last edited by

      Hi All,

      cerebro = bt.Cerebro()
      cerebro.addstrategy(SmaCross)
      store = alpaca_backtrader_api.AlpacaStore(key_id=api_key_id,secret_key=api_secret,paper=base_url)
      
      days_to_cross = 5
      date_N_days_ago = datetime.now() - timedelta(days=days_to_cross)
      DataFactory = store.getdata # or use alpaca_backtrader_api.AlpacaData
      
      data0 = DataFactory(
          dataname=stockSymbol,
          timeframe=bt.TimeFrame.TFrame("Minutes"),
          fromdate=pd.Timestamp(date_N_days_ago),compression =1, #compression =1 for 1 Min
      #         todate=pd.Timestamp('2018-11-17'),
          historical=True)
      cerebro.adddata(data0)
      
      cerebro.run()
      mktData = SmaCross.df
      mktData["Dates"]= mktData.index
      return mktData 
      

      On this code 5 days of data or 50 dys of data it returns the same data point.
      I would like to control # of data points with variable days_to_cross. How can this be corrected?
      Also please feedback if I should have asked to questions somewhat relevant on this topic already started or create a new thread.What would be an efficient way to keep this community questionings clean? I am a newbie.

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

        @Ronan-Dunham said in backtrader data same for 5days vs 50 days:

        On this code 5 days of data or 50 dys of data it returns the same data point.

        The statement may make sense to you because you are deep in your problem, but it makes no sense to me. It seems to indicate, but this is only a guess, that the amount of downloaded data, even if you change your days_to_cross variable, doesn't change.

        It may all be related to the alpaca API, which I personally don't know how to use or how it works.

        1 Reply Last reply Reply Quote 0
        • SPECULARI FUND
          SPECULARI FUND last edited by

          @Ronan-Dunham do you have experience with Alpaca API?

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