For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

How do I restrict data to market open hours



  • I would like to backtest my csv data and only use the market hours of 10am to 3pm and ignore other times.

    I have tried restricting the import of csv data with sessionstart and sessionend but it doesn't work?

    Any suggestions welcome

    Thanks

    '''

    Add our data

    data = bt.feeds.GenericCSVData(dataname= f'{PATH}SPX500_USD_ALL.csv',
    datetime=0,
    fromdate=datetime.datetime(2018,12,21),
    #todate=datetime.datetime(2018,6,10),
    sessionstart=datetime.time(10),
    sessionend=datetime.time(15),
    open=2,
    high=3,
    low=4,
    close=5,
    openinterest=-1,
    time=-1,
    volume=1,
    # Need code below to display time
    timeframe=bt.TimeFrame.Ticks,
    dtformat="%Y-%m-%d %H:%M:%S")

    '''


  • administrators

    @callan99 said in How do I restrict data to market open hours:

    '''
    

    is not

        ```
    

    @callan99 said in How do I restrict data to market open hours:

    I have tried restricting the import of csv data with sessionstart and sessionend

    Because the parameters sessionstart and sessionend are there to inform the engine and let it know when things like resampling should fold and when timers have to be called. They will not automagically filter your data.

    Apply a filter in any case



  • Many thanks.. The filters work perfectly

    I love this product!!!

    Keep up the good work, apologies for confusing my ''' and ```

    Cheers


 

});