Repository: quantopian/zipline
File: tests/finance/test_slippage.py (Python)

Code before:
                    [order],
                ))
            except StopIteration:
                txn = None

            if expected['transaction'] is None:
                self.assertIsNone(txn)
            else:
                self.assertIsNotNone(txn)

                for key, value in expected['transaction'].items():
                    self.assertEquals(value, txn[key])


class FixedBasisPointsSlippageTestCase(WithCreateBarData,
                                       WithSimParams,
                                       ZiplineTestCase):

    START_DATE = pd.Timestamp('2006-01-05 14:31', tz='utc')
    END_DATE = pd.Timestamp('2006-01-05 14:36', tz='utc')
    SIM_PARAMS_CAPITAL_BASE = 1.0e5
    SIM_PARAMS_DATA_FREQUENCY = 'minute'
    SIM_PARAMS_EMISSION_RATE = 'daily'

    ASSET_FINDER_EQUITY_SIDS = (133,)
    ASSET_FINDER_EQUITY_START_DATE = pd.Timestamp('2006-01-05', tz='utc')
    ASSET_FINDER_EQUITY_END_DATE = pd.Timestamp('2006-01-07', tz='utc')
    minutes = pd.DatetimeIndex(
        start=START_DATE,
        end=END_DATE - pd.Timedelta('1 minute'),
        freq='1min'
    )

    @classproperty
    def CREATE_BARDATA_DATA_FREQUENCY(cls):
        return cls.sim_params.data_frequency

    @classmethod
    def make_equity_minute_bar_data(cls):
        yield 133, pd.DataFrame(
            {
                'open': [3.00],
                'high': [3.15],
                'low': [2.85],
                'close': [3.00],
                'volume': [200],
            },
            index=[cls.minutes[0]],
        )

    @classmethod

Review comment (suggestion):
I would expect not to need these dates set explicitly if we just date bounds for `START_DATE`/`END_DATE`.

Code after:
                    [order],
                ))
            except StopIteration:
                txn = None

            if expected['transaction'] is None:
                self.assertIsNone(txn)
            else:
                self.assertIsNotNone(txn)

                for key, value in expected['transaction'].items():
                    self.assertEquals(value, txn[key])


class FixedBasisPointsSlippageTestCase(WithCreateBarData,
                                       ZiplineTestCase):

    START_DATE = pd.Timestamp('2006-01-05', tz='utc')
    END_DATE = pd.Timestamp('2006-01-05', tz='utc')

    ASSET_FINDER_EQUITY_SIDS = (133,)

    first_minute = (
        pd.Timestamp('2006-01-05 9:31', tz='US/Eastern').tz_convert('UTC')
    )

    @classmethod
    def make_equity_minute_bar_data(cls):
        yield 133, pd.DataFrame(
            {
                'open': [2.9],
                'high': [3.15],
                'low': [2.85],
                'close': [3.00],
                'volume': [200],
            },
            index=[cls.first_minute],
        )

    @classmethod
    def init_class_fixtures(cls):
        super(FixedBasisPointsSlippageTestCase, cls).init_class_fixtures()
        cls.ASSET133 = cls.asset_finder.retrieve_asset(133)

    @parameterized.expand([
        # Volume limit of 10% on an order of 100 shares. Since the bar volume
        # is 200, we should hit the limit and only fill 20 shares.
        ('5bps_over_vol_limit', 5, 0.1, 100, 3.0015, 20),
        # Same as previous, but on the short side.
        ('5bps_negative_over_vol_limit', 5, 0.1, -100, 2.9985, -20),
        # Volume limit of 10% on an order of 10 shares. We should fill the full