Merge pull request #1770 from quantopian/zero-transaction-volume

Futures slippage model could have zero transaction volume
This commit is contained in:
David Michalowicz
2017-04-26 13:59:33 -04:00
committed by GitHub
2 changed files with 19 additions and 0 deletions
+14
View File
@@ -839,6 +839,20 @@ class VolatilityVolumeShareTestCase(WithCreateBarData,
self.assertIsNone(price)
self.assertIsNone(amount)
def test_low_transaction_volume(self):
# With a volume limit of 0.001, and a bar volume of 100, we should
# compute a transaction volume of 100 * 0.001 = 0.1, which gets rounded
# down to zero. In this case we expect no amount to be transacted.
model = VolatilityVolumeShare(volume_limit=0.001)
minute = pd.Timestamp('2006-03-01 11:35AM', tz='UTC')
data = self.create_bardata(simulation_dt_func=lambda: minute)
order = Order(dt=data.current_dt, asset=self.ASSET, amount=10)
price, amount = model.process_order(data, order)
self.assertIsNone(price)
self.assertIsNone(amount)
class MarketImpactTestCase(WithCreateBarData, ZiplineTestCase):
+5
View File
@@ -360,6 +360,11 @@ class MarketImpactBase(object):
min(self.get_txn_volume(data, order), abs(order.open_amount))
)
# If the computed transaction volume is zero or a decimal value, 'int'
# will round it down to zero. In that case just bail.
if txn_volume == 0:
return None, None
if mean_volume == 0 or np.isnan(volatility):
# If this is the first day the contract exists or there is no
# volume history, default to a conservative estimate of impact.