Skip to content

Commit

Permalink
Merge 0cc81a5 into 4c334c6
Browse files Browse the repository at this point in the history
  • Loading branch information
jbredeche committed Apr 20, 2017
2 parents 4c334c6 + 0cc81a5 commit 5ed7c8b
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 233 deletions.
8 changes: 4 additions & 4 deletions tests/finance/test_blotter.py
Expand Up @@ -154,7 +154,7 @@ def test_blotter_eod_cancellation(self):
blotter = Blotter('minute', self.asset_finder,
cancel_policy=EODCancel())

# Make two orders for the same sid, so we can test that we are not
# Make two orders for the same asset, so we can test that we are not
# mutating the orders list as we are cancelling orders
blotter.order(self.asset_24, 100, MarketOrder())
blotter.order(self.asset_24, -100, MarketOrder())
Expand Down Expand Up @@ -343,7 +343,7 @@ def test_prune_orders(self):

other_order = Order(
dt=blotter.current_dt,
sid=self.asset_25,
asset=self.asset_25,
amount=1
)

Expand Down Expand Up @@ -406,7 +406,7 @@ def test_slippage_and_commission_dispatching(self):
equity_txn = txns[0]
self.assertEqual(
equity_txn.price,
bar_data.current(equity_txn.sid, 'price'),
bar_data.current(equity_txn.asset, 'price'),
)
self.assertEqual(commissions[0]['cost'], 1.0)

Expand All @@ -416,6 +416,6 @@ def test_slippage_and_commission_dispatching(self):
future_txn = txns[1]
self.assertEqual(
future_txn.price,
bar_data.current(future_txn.sid, 'price') + 1.0,
bar_data.current(future_txn.asset, 'price') + 1.0,
)
self.assertEqual(commissions[1]['cost'], 2.0)
8 changes: 4 additions & 4 deletions tests/finance/test_commissions.py
Expand Up @@ -21,16 +21,16 @@ def generate_order_and_txns(self):
asset1 = self.asset_finder.retrieve_asset(1)

# one order
order = Order(dt=None, sid=asset1, amount=500)
order = Order(dt=None, asset=asset1, amount=500)

# three fills
txn1 = Transaction(sid=asset1, amount=230, dt=None,
txn1 = Transaction(asset=asset1, amount=230, dt=None,
price=100, order_id=order.id)

txn2 = Transaction(sid=asset1, amount=170, dt=None,
txn2 = Transaction(asset=asset1, amount=170, dt=None,
price=101, order_id=order.id)

txn3 = Transaction(sid=asset1, amount=100, dt=None,
txn3 = Transaction(asset=asset1, amount=100, dt=None,
price=102, order_id=order.id)

return order, [txn1, txn2, txn3]
Expand Down
54 changes: 24 additions & 30 deletions tests/finance/test_slippage.py
Expand Up @@ -126,7 +126,7 @@ def test_orders_limit(self):
'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': 100,
'filled': 0,
'sid': self.ASSET133,
'asset': self.ASSET133,
'limit': 3.5})
]

Expand All @@ -148,7 +148,7 @@ def test_orders_limit(self):
'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': 100,
'filled': 0,
'sid': self.ASSET133,
'asset': self.ASSET133,
'limit': 3.5})
]

Expand All @@ -170,7 +170,7 @@ def test_orders_limit(self):
'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': 100,
'filled': 0,
'sid': self.ASSET133,
'asset': self.ASSET133,
'limit': 3.6})
]

Expand All @@ -194,7 +194,7 @@ def test_orders_limit(self):
# we ordered 100 shares, but default volume slippage only allows
# for 2.5% of the volume. 2.5% * 2000 = 50 shares
'amount': int(50),
'sid': int(133),
'asset': self.ASSET133,
'order_id': open_orders[0].id
}

Expand All @@ -209,7 +209,7 @@ def test_orders_limit(self):
'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': -100,
'filled': 0,
'sid': self.ASSET133,
'asset': self.ASSET133,
'limit': 3.5})
]

Expand All @@ -231,7 +231,7 @@ def test_orders_limit(self):
'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': -100,
'filled': 0,
'sid': self.ASSET133,
'asset': self.ASSET133,
'limit': 3.5})
]

Expand All @@ -253,7 +253,7 @@ def test_orders_limit(self):
'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': -100,
'filled': 0,
'sid': self.ASSET133,
'asset': self.ASSET133,
'limit': 3.4})
]

Expand All @@ -275,7 +275,7 @@ def test_orders_limit(self):
'dt': datetime.datetime(
2006, 1, 5, 14, 32, tzinfo=pytz.utc),
'amount': int(-50),
'sid': int(133)
'asset': self.ASSET133,
}

self.assertIsNotNone(txn)
Expand All @@ -293,7 +293,7 @@ def test_orders_stop_limit(self):
'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': 100,
'filled': 0,
'sid': self.ASSET133,
'asset': self.ASSET133,
'stop': 4.0,
'limit': 3.0})
]
Expand Down Expand Up @@ -328,7 +328,7 @@ def test_orders_stop_limit(self):
'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': 100,
'filled': 0,
'sid': self.ASSET133,
'asset': self.ASSET133,
'stop': 4.0,
'limit': 3.5})
]
Expand Down Expand Up @@ -363,7 +363,7 @@ def test_orders_stop_limit(self):
'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': 100,
'filled': 0,
'sid': self.ASSET133,
'asset': self.ASSET133,
'stop': 4.0,
'limit': 3.6})
]
Expand Down Expand Up @@ -398,7 +398,7 @@ def test_orders_stop_limit(self):
'dt': datetime.datetime(
2006, 1, 5, 14, 34, tzinfo=pytz.utc),
'amount': int(50),
'sid': int(133)
'asset': self.ASSET133
}

for key, value in expected_txn.items():
Expand All @@ -411,7 +411,7 @@ def test_orders_stop_limit(self):
'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': -100,
'filled': 0,
'sid': self.ASSET133,
'asset': self.ASSET133,
'stop': 3.0,
'limit': 4.0})
]
Expand Down Expand Up @@ -446,7 +446,7 @@ def test_orders_stop_limit(self):
'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': -100,
'filled': 0,
'sid': self.ASSET133,
'asset': self.ASSET133,
'stop': 3.0,
'limit': 3.5})
]
Expand Down Expand Up @@ -481,7 +481,7 @@ def test_orders_stop_limit(self):
'dt': datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
'amount': -100,
'filled': 0,
'sid': self.ASSET133,
'asset': self.ASSET133,
'stop': 3.0,
'limit': 3.4})
]
Expand Down Expand Up @@ -516,7 +516,7 @@ def test_orders_stop_limit(self):
'dt': datetime.datetime(
2006, 1, 5, 14, 32, tzinfo=pytz.utc),
'amount': int(-50),
'sid': int(133)
'asset': self.ASSET133,
}

for key, value in expected_txn.items():
Expand Down Expand Up @@ -574,7 +574,7 @@ def test_volume_share_slippage(self):
dt=datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
amount=100,
filled=0,
sid=self.ASSET133
asset=self.ASSET133
)
]

Expand All @@ -596,7 +596,7 @@ def test_volume_share_slippage(self):
'dt': datetime.datetime(
2006, 1, 5, 14, 31, tzinfo=pytz.utc),
'amount': int(5),
'sid': int(133),
'asset': self.ASSET133,
'commission': None,
'type': DATASOURCE_TYPE.TRANSACTION,
'order_id': open_orders[0].id
Expand All @@ -613,7 +613,7 @@ def test_volume_share_slippage(self):
dt=datetime.datetime(2006, 1, 5, 14, 30, tzinfo=pytz.utc),
amount=100,
filled=0,
sid=self.ASSET133
asset=self.ASSET133
)
]

Expand Down Expand Up @@ -684,7 +684,6 @@ def init_class_fixtures(cls):
'dt': pd.Timestamp('2006-01-05 14:30', tz='UTC'),
'amount': 100,
'filled': 0,
'sid': 133,
'stop': 3.5
},
'event': {
Expand All @@ -693,7 +692,6 @@ def init_class_fixtures(cls):
'price': 4.0,
'high': 3.15,
'low': 2.85,
'sid': 133,
'close': 4.0,
'open': 3.5
},
Expand All @@ -702,7 +700,6 @@ def init_class_fixtures(cls):
'price': 4.00025,
'dt': pd.Timestamp('2006-01-05 14:31', tz='UTC'),
'amount': 50,
'sid': 133,
}
}
},
Expand All @@ -711,7 +708,6 @@ def init_class_fixtures(cls):
'dt': pd.Timestamp('2006-01-05 14:30', tz='UTC'),
'amount': 100,
'filled': 0,
'sid': 133,
'stop': 3.6
},
'event': {
Expand All @@ -720,7 +716,6 @@ def init_class_fixtures(cls):
'price': 3.5,
'high': 3.15,
'low': 2.85,
'sid': 133,
'close': 3.5,
'open': 4.0
},
Expand All @@ -733,7 +728,6 @@ def init_class_fixtures(cls):
'dt': pd.Timestamp('2006-01-05 14:30', tz='UTC'),
'amount': -100,
'filled': 0,
'sid': 133,
'stop': 3.4
},
'event': {
Expand All @@ -742,7 +736,6 @@ def init_class_fixtures(cls):
'price': 3.5,
'high': 3.15,
'low': 2.85,
'sid': 133,
'close': 3.5,
'open': 3.0
},
Expand All @@ -755,7 +748,6 @@ def init_class_fixtures(cls):
'dt': pd.Timestamp('2006-01-05 14:30', tz='UTC'),
'amount': -100,
'filled': 0,
'sid': 133,
'stop': 3.5
},
'event': {
Expand All @@ -764,7 +756,6 @@ def init_class_fixtures(cls):
'price': 3.0,
'high': 3.15,
'low': 2.85,
'sid': 133,
'close': 3.0,
'open': 3.0
},
Expand All @@ -773,7 +764,6 @@ def init_class_fixtures(cls):
'price': 2.9998125,
'dt': pd.Timestamp('2006-01-05 14:31', tz='UTC'),
'amount': -50,
'sid': 133,
}
}
},
Expand All @@ -785,9 +775,13 @@ def init_class_fixtures(cls):
])
def test_orders_stop(self, name, order_data, event_data, expected):
data = order_data
data['sid'] = self.ASSET133
data['asset'] = self.ASSET133
order = Order(**data)

if expected['transaction']:
expected['transaction']['asset'] = self.ASSET133
event_data['asset'] = self.ASSET133

assets = (
(133, pd.DataFrame(
{
Expand Down
Binary file modified tests/resources/example_data.tar.gz
Binary file not shown.

0 comments on commit 5ed7c8b

Please sign in to comment.