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



  • 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.


  • administrators

    @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.


Log in to reply
 

});