Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Day based bars is not supported yet #59

Closed
ricpruss opened this issue Mar 25, 2017 · 3 comments
Closed

Day based bars is not supported yet #59

ricpruss opened this issue Mar 25, 2017 · 3 comments

Comments

@ricpruss
Copy link

ricpruss commented Mar 25, 2017

Lots of things get a bit weird if you try preload day based bars:

e.g.

    strategy = DayStrategy(
        instruments = [
#         ("ES", "FUT", "GLOBEX", "USD", ACTIVE_MONTH, 0.0, ""),
#          ("SPX", "IND", "CBOE", "USD", "", 0.0, ""),
          ("AAPL", "STK", "SMART", "USD", "", 0.0, "")
         ],
        resolution  = "1D",
        bar_window  = 100,
        preload = "4D"
    )

ES hangs with no history error message on Gateway.
INDes seem to just hang and not return anything.
For stock I got things going with two changes to the blotter.py

     # expand the resolutions
       if resolution[-1] in ("K", "V", "S"):
            self.backfill_resolution = "1 sec"
       elif resolution[-1]== "M":
            self.backfill_resolution = "1 min"
       elif resolution[-1]== "H":
            self.backfill_resolution = "1 hour"
       elif resolution[-1]== "D":
            self.backfill_resolution = "1 day"

```and

  # round to days if asking for days
    if resolution[-1]== "D":
        start_date = datetime(start_date.year, start_date.month, start_date.day)
        end_date   = datetime(end_date.year, end_date.month, end_date.day)
        first_date = datetime(first_date.year, first_date.month, first_date.day)
        last_date  = datetime(last_date.year, last_date.month, last_date.day)
I got the query for the stock back but....something is not parsing the dates well... it works for minute data but not for the day based bars...  (no idea where to debug from here)

1 1970-08-22 10:52:01 1 141.59 142.8 139.35 139.35 352675
2 1970-08-22 10:52:02 1 139.25 141.6 138.67 141.5 238385
3 1970-08-22 10:52:03 1 141.28 141.59 140.61 141 186233
4 1970-08-22 10:52:04 1 141.07 141.74 140.05 140.43 203203
5 2017-03-24 08:36:00 1 141.07 141.14 141.07 141.14 4
6 2017-03-24 08:37:00 1 141.14 141.14 141.14 141.14 0

@ranaroussi
Copy link
Owner

I plan on adding a daily bar db real soon. In the meantime you should resample your daily bars to minute bars before preloading

min_df = daily_df.resample("1T").last().ffill()

@ricpruss
Copy link
Author

ricpruss commented Apr 19, 2017 via email

@webberd1wei
Copy link

webberd1wei commented Oct 18, 2017

Any suggestion to how to manage daily and intraday bars? Is aggregating the intraday bars to get the daily bar a good way to go?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants