mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-13 12:00:16 +08:00
MAINT: Provide a callable base class for slippage models.
Work towards a set_slippage method accepts a function that takes event and orders as the argument, instead of being tightly bound to using classes like FixedSlippage etc., in that scenario the instances of SlippageModel will be used via `__call__`, so that backwards compatiblity is maintained.
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import abc
|
||||
|
||||
import pytz
|
||||
import math
|
||||
|
||||
@@ -59,7 +61,7 @@ def transact_stub(slippage, commission, event, open_orders):
|
||||
This is intended to be wrapped in a partial, so that the
|
||||
slippage and commission models can be enclosed.
|
||||
"""
|
||||
transactions = slippage.simulate(event, open_orders)
|
||||
transactions = slippage(event, open_orders)
|
||||
|
||||
for transaction in transactions:
|
||||
if (
|
||||
@@ -112,7 +114,19 @@ def create_transaction(sid, amount, price, dt, order_id):
|
||||
return transaction
|
||||
|
||||
|
||||
class VolumeShareSlippage(object):
|
||||
class SlippageModel(object):
|
||||
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
@abc.abstractmethod
|
||||
def simulate(self, event, current_orders, **kwargs):
|
||||
pass
|
||||
|
||||
def __call__(self, event, current_orders, **kwargs):
|
||||
return self.simulate(event, current_orders, **kwargs)
|
||||
|
||||
|
||||
class VolumeShareSlippage(SlippageModel):
|
||||
|
||||
def __init__(self,
|
||||
volume_limit=.25,
|
||||
@@ -190,7 +204,7 @@ class VolumeShareSlippage(object):
|
||||
return txns
|
||||
|
||||
|
||||
class FixedSlippage(object):
|
||||
class FixedSlippage(SlippageModel):
|
||||
|
||||
def __init__(self, spread=0.0):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user