def test_per_contract_with_minimum(self):
        # Minimum is met by the first trade.
        self.verify_per_unit_commissions(
            PerContract(cost=0.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=0.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=0.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=0.01, exchange_fee=0.3, min_trade_cost=7),
            commission_totals=[7.0, 7.0, 7.0],
            sid=1000,
        )
    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)
示例#3
0
    def __init__(self, data_frequency, equity_slippage=None,
                 future_slippage=None, equity_commission=None,
                 future_commission=None, cancel_policy=None, stock_exchange='NYSE'):
        # 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 FixedBasisPointsSlippage(),
            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()
示例#4
0
    def __init__(self, data_frequency, broker):
        self.broker = broker
        self._processed_closed_orders = []
        self._processed_transactions = []
        self.data_frequency = data_frequency
        self.new_orders = []
        self.max_shares = int(1e+11)

        self.slippage_models = {
            Equity:
            FixedBasisPointsSlippage(),
            Future:
            VolatilityVolumeShare(
                volume_limit=DEFAULT_FUTURE_VOLUME_SLIPPAGE_BAR_LIMIT, ),
        }
        self.commission_models = {
            Equity:
            PerShare(),
            Future:
            PerContract(
                cost=DEFAULT_PER_CONTRACT_COST,
                exchange_fee=FUTURE_EXCHANGE_FEES_BY_SYMBOL,
            ),
        }
        log.info('Initialized blotter_live')
示例#5
0
    def __init__(
        self,
        equity_slippage=None,
        future_slippage=None,
        option_slippage=None,
        equity_commission=None,
        future_commission=None,
        option_commission=None,
        cancel_policy=None,
    ):
        super(SimulationBlotter, self).__init__(cancel_policy=cancel_policy)

        # 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.max_shares = int(1e11)

        self.slippage_models = {
            Equity:
            equity_slippage or FixedBasisPointsSlippage(),
            Future:
            future_slippage or VolatilityVolumeShare(
                volume_limit=DEFAULT_FUTURE_VOLUME_SLIPPAGE_BAR_LIMIT),
            Option:
            option_slippage or CoverTheSpread(),
        }
        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,
            ),
            Option:
            option_commission
            or PerOptionContract(cost=DEFAULT_PER_OPTION_CONTRACT_COST,
                                 exchange_fee=0.01),
        }