@adamb032 self.data._rolls[0]
refers to the first contract from the RollOver
feed, and self.data._rolls[1]
to the second.
Therefore it is closing position on the first contract and opening on the second at the same bar.
Latest posts made by BobDenar
-
RE: How do you buy and sell the roll with RollOver Feed
-
RE: How do you buy and sell the roll with RollOver Feed
@adamb032 I have the same issue, here is the workaround I coded:
if not self.position: ... else: if self._check_is_roll_date(self.data.datetime.date(), self._curr_future): self.sell(data=self.data._rolls[0]) self.buy(data=self.data._rolls[1])
The issue here is to get the right contract by its
_rolls
index. A solution would be to name each datafeed composing theRollOver
, then find the wanted contract by its name. -
RE: Issue with RollOver and live data
Hi,
I'm glad you've fixed this issue in the latest release.
Unfortunately, there is a typo in the check for values in the data source:def _load(self): while self._d is not None: if self._d.next() is not False: # no values from current data src if self._ds: self._d = self._ds.pop(0) self._dts.pop(0) else: self._d = None continue ...
It should have been:
def _load(self): while self._d is not None: if self._d.next() is False: # no values from current data src ...
not
was falsely added.Regards
-
RE: Issue with date2num
On timers with
tzdata
parameters to trigger timers on market place's timezone.
Our historicals datas are stored into a MongoDB through Arctic library, since ticks and bars are stored UTC, when building a feed I addtz
parameter to point to the proper timezone.I guess that those uses of timezones pinpointed me to this issue.
-
Issue with date2num
Hi,
I use timezones intensively, and I had an issue with
date2num
on line 209 ofutils/dateintern.py
.
The code refers to an undefined variabledwhen
:def date2num(dt, tz=None): """ Convert :mod:`datetime` to the Gregorian date as UTC float days, preserving hours, minutes, seconds and microseconds. Return value is a :func:`float`. """ if tz is not None: dt = tz.localize(dwhen) if hasattr(dt, 'tzinfo') and dt.tzinfo is not None: delta = dt.tzinfo.utcoffset(dt) if delta is not None: dt -= delta base = float(dt.toordinal()) if hasattr(dt, 'hour'): # base += (dt.hour / HOURS_PER_DAY + # dt.minute / MINUTES_PER_DAY + # dt.second / SECONDS_PER_DAY + # dt.microsecond / MUSECONDS_PER_DAY # ) base = math.fsum( (base, dt.hour / HOURS_PER_DAY, dt.minute / MINUTES_PER_DAY, dt.second / SECONDS_PER_DAY, dt.microsecond / MUSECONDS_PER_DAY)) return base
My guess is that
dwhen
must be substituted withdt
.Thanks
-
Issue with RollOver and live data
Hi,
I had an issue with live data and RollOver data feed, and I think I found where is the problem.
Can you please review it and maybe submit a patch if relevant.The live feed is my own class (Reuters). It returns
None
when no data is available yet andFalse
when this is the end of the feed (I believe this is a convention here). I am trying to trade futures with my live feed and RollOver, but a problem arises on line 155 offeeds/rollover.py
:def _load(self): while self._d is not None: if not self._d.next(): # no values from current data source if self._ds: self._d = self._ds.pop(0) self._dts.pop(0) else: self._d = None continue
The test on
if not self._d.next():
is ambigous as it makes no difference betweenNone
andFalse
.
As a result if in a resampling, on say 5 seconds, no ticks came, then RollOver thinks the contract is over and get to the next one, which is wrong.The solution I propose is to test
False
on this line:def _load(self): while self._d is not None: if self._d.next() is False: # no values from current data source if self._ds: self._d = self._ds.pop(0) self._dts.pop(0) else: self._d = None continue
It works great on both live data feed and backtest data feeds.
Thanks