mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-30 02:54:16 +08:00
Merge pull request #1657 from quantopian/compare-slippage-models
ENH: Solidify equality comparisons for SlippageModel classes
This commit is contained in:
@@ -88,6 +88,13 @@ class SlippageTestCase(WithCreateBarData,
|
||||
super(SlippageTestCase, cls).init_class_fixtures()
|
||||
cls.ASSET133 = cls.env.asset_finder.retrieve_asset(133)
|
||||
|
||||
def test_equality_and_comparison(self):
|
||||
vol1 = VolumeShareSlippage(volume_limit=0.2)
|
||||
vol2 = VolumeShareSlippage(volume_limit=0.2)
|
||||
|
||||
self.assertEqual(vol1, vol2)
|
||||
self.assertEqual(hash(vol1), hash(vol2))
|
||||
|
||||
def test_fill_price_worse_than_limit_price(self):
|
||||
non_limit_order = TestOrder(limit=None, direction=1)
|
||||
limit_buy = TestOrder(limit=1.5, direction=1)
|
||||
|
||||
@@ -16,7 +16,7 @@ from __future__ import division
|
||||
|
||||
import abc
|
||||
import math
|
||||
from six import with_metaclass
|
||||
from six import with_metaclass, iteritems
|
||||
|
||||
from pandas import isnull
|
||||
|
||||
@@ -152,6 +152,18 @@ class SlippageModel(with_metaclass(abc.ABCMeta)):
|
||||
def __call__(self, bar_data, asset, current_orders):
|
||||
return self.simulate(bar_data, asset, current_orders)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self._attrs_to_check() == other._attrs_to_check()
|
||||
|
||||
def __hash__(self):
|
||||
return hash((
|
||||
type(self),
|
||||
tuple(sorted(iteritems(self._attrs_to_check())))
|
||||
))
|
||||
|
||||
def _attrs_to_check(self):
|
||||
return self.__dict__
|
||||
|
||||
|
||||
class VolumeShareSlippage(SlippageModel):
|
||||
"""Model slippage as a function of the volume of shares traded.
|
||||
|
||||
Reference in New Issue
Block a user