mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-10 12:00:15 +08:00
MAINT: Removed unnecessary floating point checks in slippage
Cleaned up some other expressions in slippage as well Fixes #277
This commit is contained in:
@@ -24,7 +24,6 @@ from functools import partial
|
||||
from six import with_metaclass
|
||||
|
||||
from zipline.protocol import DATASOURCE_TYPE
|
||||
import zipline.utils.math_utils as zp_math
|
||||
|
||||
SELL = 1 << 0
|
||||
BUY = 1 << 1
|
||||
@@ -98,14 +97,10 @@ def transact_stub(slippage, commission, event, open_orders):
|
||||
slippage and commission models can be enclosed.
|
||||
"""
|
||||
for order, transaction in slippage(event, open_orders):
|
||||
if (
|
||||
transaction
|
||||
and not
|
||||
zp_math.tolerant_equals(transaction.amount, 0)
|
||||
):
|
||||
if transaction and transaction.amount != 0:
|
||||
direction = math.copysign(1, transaction.amount)
|
||||
per_share, total_commission = commission.calculate(transaction)
|
||||
transaction.price = transaction.price + (per_share * direction)
|
||||
transaction.price += per_share * direction
|
||||
transaction.commission = total_commission
|
||||
yield order, transaction
|
||||
|
||||
@@ -171,7 +166,7 @@ class SlippageModel(with_metaclass(abc.ABCMeta)):
|
||||
|
||||
for order in current_orders:
|
||||
|
||||
if zp_math.tolerant_equals(order.open_amount, 0):
|
||||
if order.open_amount == 0:
|
||||
continue
|
||||
|
||||
order.check_triggers(event)
|
||||
@@ -231,7 +226,7 @@ class VolumeShareSlippage(SlippageModel):
|
||||
volume_share = min(total_volume / event.volume,
|
||||
self.volume_limit)
|
||||
|
||||
simulated_impact = (volume_share) ** 2 \
|
||||
simulated_impact = volume_share ** 2 \
|
||||
* math.copysign(self.price_impact, order.direction) \
|
||||
* event.price
|
||||
|
||||
|
||||
Reference in New Issue
Block a user