예제 #1
0
    def get_value(self, sid, dt, field):
        """
        Retrieve the value at the given coordinates.

        Parameters
        ----------
        sid : int
            The asset identifier.
        dt : pd.Timestamp
            The timestamp for the desired data point.
        field : string
            The OHLVC name for the desired data point.

        Returns
        -------
        value : float|int
            The value at the given coordinates, ``float`` for OHLC, ``int``
            for 'volume'.

        Raises
        ------
        NoDataOnDate
            If the given dt is not a valid market minute (in minute mode) or
            session (in daily mode) according to this reader's tradingcalendar.
        NoDataForSid
            If the given sid is not valid.
        """
        try:
            country_code = self._country_code_for_assets([sid])
        except ValueError:
            raise NoDataForSid(
                f'Asset not contained in daily pricing file: {sid}')
        return self._readers[country_code].get_value(sid, dt, field)
예제 #2
0
    def _open_minute_file(self, field, sid):
        sid = int(sid)

        try:
            carray = self._carrays[field][sid]
        except KeyError:
            try:
                carray = self._carrays[field][sid] = bcolz.carray(
                    rootdir=self._get_carray_path(sid, field),
                    mode='r',
                )
            except IOError:
                raise NoDataForSid('No minute data for sid {}.'.format(sid))

        return carray
예제 #3
0
    def load_raw_arrays(self, columns, start_dt, end_dt, assets):
        if start_dt not in self._sessions:
            raise NoDataOnDate(start_dt)
        if end_dt not in self._sessions:
            raise NoDataOnDate(end_dt)

        asset_indexer = self._sids.get_indexer(assets)
        if -1 in asset_indexer:
            bad_assets = assets[asset_indexer == -1]
            raise NoDataForSid(bad_assets)

        date_indexer = self._sessions.slice_indexer(start_dt, end_dt)

        out = []
        for c in columns:
            out.append(self._values[c][date_indexer, asset_indexer])

        return out
예제 #4
0
    def _country_code_for_assets(self, assets):
        try:
            country_codes = self._country_map.loc[assets]
        except KeyError as exc:
            raise_from(
                NoDataForSid(
                    'Assets not contained in daily pricing file: {}'.format(
                        set(assets) - set(self._country_map))), exc)

        unique_country_codes = country_codes.unique()

        if len(unique_country_codes) > 1:
            raise NotImplementedError(
                ('Assets were requested from multiple countries ({}),'
                 ' but multi-country reads are not yet supported.').format(
                     list(unique_country_codes)))

        return np.asscalar(unique_country_codes)
예제 #5
0
    def _open_minute_file(self, field, sid, force_reload=False):
        sid = int(sid)

        try:
            # the force_reload option is to deal with the usstock problem
            # date. See the comments in __init__ and get_value.
            if force_reload:
                raise KeyError()
            carray = self._carrays[field][sid]
        except KeyError:
            try:
                carray = self._carrays[field][sid] = bcolz.carray(
                    rootdir=self._get_carray_path(sid, field),
                    mode='r',
                )
            except IOError:
                raise NoDataForSid('No minute data for sid {}.'.format(sid))

        return carray
예제 #6
0
    def _validate_assets(self, assets):
        """Validate that asset identifiers are contained in the daily bars.

        Parameters
        ----------
        assets : array-like[int]
           The asset identifiers to validate.

        Raises
        ------
        NoDataForSid
            If one or more of the provided asset identifiers are not
            contained in the daily bars.
        """
        missing_sids = np.setdiff1d(assets, self.sids)

        if len(missing_sids):
            raise NoDataForSid(
                'Assets not contained in daily pricing file: {}'.format(
                    missing_sids))