コード例 #1
0
    def test_doc_differentiates(self):
        a = sentinel('sentinel-name', 'original-doc')
        with self.assertRaises(ValueError) as e:
            sentinel(a.__name__, 'new-doc')

        msg = str(e.exception)
        self.assertIn(a.__name__, msg)
        self.assertIn(a.__doc__, msg)
コード例 #2
0
class TestingSlippage(SlippageModel):
    """
    Slippage model that fills a constant number of shares per tick, for
    testing purposes.

    Parameters
    ----------
    filled_per_tick : int or TestingSlippage.ALL
        The number of shares to fill on each call to process_order. If
        TestingSlippage.ALL is passed, the entire order is filled.

    See also
    --------
    catalyst.finance.slippage.SlippageModel
    """
    ALL = sentinel('ALL')

    allowed_asset_types = (Equity, )

    def __init__(self, filled_per_tick):
        super(TestingSlippage, self).__init__()
        self.filled_per_tick = filled_per_tick

    def process_order(self, data, order):
        price = data.current(order.asset, "close")
        if self.filled_per_tick is self.ALL:
            volume = order.amount
        else:
            volume = self.filled_per_tick

        return (price, volume)
コード例 #3
0
ファイル: core.py プロジェクト: Aeroglyphic/catalyst-crypto
class tmp_assets_db(object):
    """Create a temporary assets sqlite database.
    This is meant to be used as a context manager.

    Parameters
    ----------
    url : string
        The URL for the database connection.
    **frames
        The frames to pass to the AssetDBWriter.
        By default this maps equities:
        ('A', 'B', 'C') -> map(ord, 'ABC')

    See Also
    --------
    empty_assets_db
    tmp_asset_finder
    """
    _default_equities = sentinel('_default_equities')

    def __init__(self,
                 url='sqlite:///:memory:',
                 equities=_default_equities,
                 **frames):
        self._url = url
        self._eng = None
        if equities is self._default_equities:
            equities = make_simple_equity_info(
                list(map(ord, 'ABC')),
                pd.Timestamp(0),
                pd.Timestamp('2015'),
            )

        frames['equities'] = equities
        self._frames = frames
        self._eng = None  # set in enter and exit

    def __enter__(self):
        self._eng = eng = create_engine(self._url)
        AssetDBWriter(eng).write(**self._frames)
        return eng

    def __exit__(self, *excinfo):
        assert self._eng is not None, '_eng was not set in __enter__'
        self._eng.dispose()
        self._eng = None
コード例 #4
0
ファイル: labelarray.py プロジェクト: zhoukalex/catalyst
    def __init__(self, left, right):
        (mismatches,) = np.where(left != right)
        assert len(mismatches), "Not actually a mismatch!"
        super(CategoryMismatch, self).__init__(
            "LabelArray categories don't match:\n"
            "Mismatched Indices: {mismatches}\n"
            "Left: {left}\n"
            "Right: {right}".format(
                mismatches=mismatches,
                left=left[mismatches],
                right=right[mismatches],
            )
        )


_NotPassed = sentinel('_NotPassed')


class LabelArray(ndarray):
    """
    An ndarray subclass for working with arrays of strings.

    Factorizes the input array into integers, but overloads equality on strings
    to check against the factor label.

    Parameters
    ----------
    values : array-like
        Array of values that can be passed to np.asarray with dtype=object.
    missing_value : str
        Scalar value to treat as 'missing' for operations on ``self``.
コード例 #5
0
 def test_weakreferencable(self):
     ref(sentinel('a'))
コード例 #6
0
 def test_pickle_roundtrip(self):
     a = sentinel('a')
     self.assertIs(loads(dumps(a)), a)
コード例 #7
0
 def test_new(self):
     with self.assertRaises(TypeError):
         type(sentinel('a'))()
コード例 #8
0
 def test_repr(self):
     self.assertEqual(
         repr(sentinel('a')),
         "sentinel('a')",
     )
コード例 #9
0
from catalyst.utils.sentinel import sentinel

NotSpecified = sentinel(
    'NotSpecified',
    'Singleton sentinel value used for Term defaults.',
)

NotSpecifiedType = type(NotSpecified)
コード例 #10
0
 def test_copy(self):
     a = sentinel('a')
     self.assertIs(copy(a), a)
コード例 #11
0
 def test_memo(self):
     self.assertIs(sentinel('a'), sentinel('a'))
コード例 #12
0
 def test_doc(self):
     self.assertEqual(sentinel('a', 'b').__doc__, 'b')
コード例 #13
0
 def test_name(self):
     self.assertEqual(sentinel('a').__name__, 'a')
コード例 #14
0
class calendars(object):
    CRYPTO_ASSETS = sentinel('CRYPTO_ASSETS')
    US_EQUITIES = sentinel('US_EQUITIES')
    US_FUTURES = sentinel('US_FUTURES')
コード例 #15
0
 def test_deepcopy(self):
     a = sentinel('a')
     self.assertIs(deepcopy(a), a)
コード例 #16
0
    """
    def __init__(self, left, right):
        (mismatches, ) = np.where(left != right)
        assert len(mismatches), "Not actually a mismatch!"
        super(CategoryMismatch,
              self).__init__("LabelArray categories don't match:\n"
                             "Mismatched Indices: {mismatches}\n"
                             "Left: {left}\n"
                             "Right: {right}".format(
                                 mismatches=mismatches,
                                 left=left[mismatches],
                                 right=right[mismatches],
                             ))


_NotPassed = sentinel('_NotPassed')


class LabelArray(ndarray):
    """
    An ndarray subclass for working with arrays of strings.

    Factorizes the input array into integers, but overloads equality on strings
    to check against the factor label.

    Parameters
    ----------
    values : array-like
        Array of values that can be passed to np.asarray with dtype=object.
    missing_value : str
        Scalar value to treat as 'missing' for operations on ``self``.
コード例 #17
0
ファイル: sentinels.py プロジェクト: zhoukalex/catalyst
from catalyst.utils.sentinel import sentinel


NotSpecified = sentinel(
    'NotSpecified',
    'Singleton sentinel value used for Term defaults.',
)

NotSpecifiedType = type(NotSpecified)