mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-12 06:35:22 +08:00
Allows for collapsed orders by changing the current order filter.
Changes our filter so that instead of just checking for the current day, we ensure that orders are before or on the current event time. This adds a delay, (defaulting to one minute), to the order so that we avoid filling an order exactly when it is placed.
This commit is contained in:
@@ -197,6 +197,20 @@ class FinanceTestCase(TestCase):
|
||||
}
|
||||
self.transaction_sim(**params2)
|
||||
|
||||
# Runs the collapsed trades over daily trade intervals.
|
||||
# Ensuring that our delay works for daily intervals as well.
|
||||
params3 = {
|
||||
'trade_count': 6,
|
||||
'trade_amount': 100,
|
||||
'trade_interval': timedelta(days=1),
|
||||
'order_count': 24,
|
||||
'order_amount': 1,
|
||||
'order_interval': timedelta(minutes=1),
|
||||
'expected_txn_count': 1,
|
||||
'expected_txn_volume': 24 * 1
|
||||
}
|
||||
self.transaction_sim(**params3)
|
||||
|
||||
@timed(DEFAULT_TIMEOUT)
|
||||
def test_alternating_long_short(self):
|
||||
# create a scenario where we alternate buys and sells
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
# 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.
|
||||
from datetime import timedelta
|
||||
|
||||
import pytz
|
||||
import math
|
||||
@@ -55,10 +56,12 @@ class VolumeShareSlippage(object):
|
||||
|
||||
def __init__(self,
|
||||
volume_limit=.25,
|
||||
price_impact=0.1):
|
||||
price_impact=0.1,
|
||||
delay=timedelta(minutes=1)):
|
||||
|
||||
self.volume_limit = volume_limit
|
||||
self.price_impact = price_impact
|
||||
self.delay = delay
|
||||
|
||||
def simulate(self, event, open_orders):
|
||||
|
||||
@@ -72,7 +75,7 @@ class VolumeShareSlippage(object):
|
||||
orders = sorted(orders, key=lambda o: o.dt)
|
||||
# Only use orders for the current day or before
|
||||
current_orders = filter(
|
||||
lambda o: o.dt.toordinal() <= event.dt.toordinal(),
|
||||
lambda o: o.dt + self.delay <= event.dt,
|
||||
orders)
|
||||
else:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user