Repository: quantopian/zipline
File: zipline/data/minute_bars.py (Python)

Code before:
)

from zipline.gens.sim_engine import NANOS_IN_MINUTE
from zipline.utils.cli import maybe_show_progress
from zipline.utils.memoize import lazyval

US_EQUITIES_MINUTES_PER_DAY = 390

DEFAULT_EXPECTEDLEN = US_EQUITIES_MINUTES_PER_DAY * 252 * 15

OHLC_RATIO = 1000


class BcolzMinuteOverlappingData(Exception):
    pass


class BcolzMinuteWriterColumnMismatch(Exception):
    pass


class MinuteBarReader(with_metaclass(ABCMeta)):

    @abstractproperty
    def last_available_dt(self):
        """
        Returns
        -------
        dt : pd.Timestamp
            The last minute for which the reader can provide data.
        """
        pass

    @abstractproperty
    def first_trading_day(self):
        """
        Returns
        -------
        dt : pd.Timestamp
            The first trading day (session) for which the reader can provide
            data.
        """
        pass

    @abstractmethod
    def get_value(self, sid, dt, field):
        """
        Retrieve the value at the given coordinates.

        Parameters
        ----------

Review comment (suggestion):
I was also surprised that they were different.

After looking at the data portal code which uses `first_trading_day`; `first_trading_day` is used to also get the `first_trading_minute`, as well. Which is then used to determine whether history windows are over valid ranges.

This code will need to be changed soon to support both equities and futures, which may have different start minutes, if not starting sessions.

`last_available_dt` is used in the `us_equity_loader` module to get the range of minutes supported by the reader; which could be its own method supported by the minute bar reader.
`last_available_dt` is also used by own of our internal data loaders to get the last session provided by the reader.

If we picked one of session/date or minute on which to standardize, I would lean towards supporting standardizing on minute, since in the live trading case the last minute available is not derivable from the session label.
We may want to support both date and minute, so that consumers are not responsible for maintaining a calendar associated with the reader to map back and forth between the `last_available_dt` and `last_available_session` values, if only one of the two were provided.


Code after:
)

from zipline.gens.sim_engine import NANOS_IN_MINUTE
from zipline.utils.cli import maybe_show_progress
from zipline.utils.memoize import lazyval

US_EQUITIES_MINUTES_PER_DAY = 390
FUTURES_MINUTES_PER_DAY = 1440

DEFAULT_EXPECTEDLEN = US_EQUITIES_MINUTES_PER_DAY * 252 * 15

OHLC_RATIO = 1000


class BcolzMinuteOverlappingData(Exception):
    pass


class BcolzMinuteWriterColumnMismatch(Exception):
    pass


class MinuteBarReader(with_metaclass(ABCMeta)):

    @abstractproperty
    def last_available_dt(self):
        """
        Returns
        -------
        dt : pd.Timestamp
            The last minute for which the reader can provide data.
        """
        pass

    @abstractproperty
    def first_trading_day(self):
        """
        Returns
        -------
        dt : pd.Timestamp
            The first trading day (session) for which the reader can provide
            data.
        """
        pass

    @abstractmethod
    def get_value(self, sid, dt, field):
        """
        Retrieve the value at the given coordinates.

        Parameters