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")'''
-
@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
andsessionend
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
- Docs - Filters
- Docs - Filters Reference and use the
SessionFilter
-
Many thanks.. The filters work perfectly
I love this product!!!
Keep up the good work, apologies for confusing my ''' and ```
Cheers
-
@Callan99, I am stuck in the same situation as you from a few years back and would like to see an example of how you used the SessionFilter to process the csv for specified session if possible. Thanks!
-
-
@vladisld awesome, i got my codes to work, thank you for sharing the link :)