def test_per_contract_no_minimum(self): # Note that the exchange fee is a one-time cost that is only applied to # the first fill of an order. # # The commission on the first fill is (230 * 0.01) + 0.3 = 2.6 # The commission on the second fill is 170 * 0.01 = 1.7 # The total after the second fill is 2.6 + 1.7 = 4.3 # The commission on the third fill is 100 * 0.01 = 1.0 # The total after the third fill is 5.3 model = PerContract(cost=0.01, exchange_fee=0.3, min_trade_cost=None) self.verify_per_unit_commissions( model=model, commission_totals=[2.6, 4.3, 5.3], sid=1000, order_amount=500, fill_amounts=[230, 170, 100], ) # Test using custom costs and fees. model = PerContract( cost={ 'CL': 0.01, 'FV': 0.0075 }, exchange_fee={ 'CL': 0.3, 'FV': 0.5 }, min_trade_cost=None, ) self.verify_per_unit_commissions(model, [2.6, 4.3, 5.3], sid=1000) self.verify_per_unit_commissions(model, [2.225, 3.5, 4.25], sid=1001)
def test_per_contract_with_minimum(self): # Minimum is met by the first trade. self.verify_per_unit_commissions( PerContract(cost=.01, exchange_fee=0.3, min_trade_cost=1), commission_totals=[2.6, 4.3, 5.3], sid=1000, ) # Minimum is met by the second trade. self.verify_per_unit_commissions( PerContract(cost=.01, exchange_fee=0.3, min_trade_cost=3), commission_totals=[3.0, 4.3, 5.3], sid=1000, ) # Minimum is met by the third trade. self.verify_per_unit_commissions( PerContract(cost=.01, exchange_fee=0.3, min_trade_cost=5), commission_totals=[5.0, 5.0, 5.3], sid=1000, ) # Minimum is not met by any of the trades. self.verify_per_unit_commissions( PerContract(cost=.01, exchange_fee=0.3, min_trade_cost=7), commission_totals=[7.0, 7.0, 7.0], sid=1000, )
def __init__(self, data_frequency, equity_slippage=None, future_slippage=None, equity_commission=None, future_commission=None, cancel_policy=None): # these orders are aggregated by asset self.open_orders = defaultdict(list) # keep a dict of orders by their own id self.orders = {} # holding orders that have come in since the last event. self.new_orders = [] self.current_dt = None self.max_shares = int(1e+11) self.slippage_models = { Equity: equity_slippage or VolumeShareSlippage(), Future: future_slippage or VolatilityVolumeShare( volume_limit=DEFAULT_FUTURE_VOLUME_SLIPPAGE_BAR_LIMIT, ), } self.commission_models = { Equity: equity_commission or PerShare(), Future: future_commission or PerContract( cost=DEFAULT_PER_CONTRACT_COST, exchange_fee=FUTURE_EXCHANGE_FEES_BY_SYMBOL, ), } self.data_frequency = data_frequency self.cancel_policy = cancel_policy if cancel_policy else NeverCancel()