How to use the qstrader.broker.zero_broker_commission.ZeroBrokerCommission function in qstrader

To help you get started, we’ve selected a few qstrader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mhallsmoore / qstrader / qstrader / simulation / backtest_trading_simulation.py View on Github external
def _create_broker_commission(self):
        """
        TODO: Fill in doc string!
        """
        if self.settings.BROKER['COMMISSION']['MODEL'] == "Zero Commission":
            broker_commission = ZeroBrokerCommission()
        else:
            print(
                "No supported Broker Commission "
                "model specified. Exiting."
            )
            sys.exit()
        return broker_commission
github mhallsmoore / qstrader / tests / algo / test_equal_weight_pcm.py View on Github external
assets = [
            Equity("%s Inc." % ticker, ticker, "NYSE")
            for ticker in [
                "%s" % (letter * 3)
                for letter in string.ascii_uppercase[:9]
            ]
        ]
        forecasts = []

        # Create Exchange and SimulatedBroker
        prices = [
            45.34, 26.58, 62.432, 88.123, 12.876,
            103.56, 229.54, 650.98, 998.123
        ]
        exchange = ExchangeMock(assets, prices)
        zcm = ZeroBrokerCommission()
        broker = SimulatedBroker(
            start_dt, exchange,
            account_id=1234,
            initial_funds=cash,
            broker_commission=zcm
        )
        bpid = "2222"
        broker.create_portfolio(bpid)
        broker.subscribe_funds_to_portfolio(bpid, cash)

        # Create portfolio construction model
        ewpcm = EqualWeightPCM(
            start_dt, broker, bpid,
            transaction_cost_model=zcm
        )
github mhallsmoore / qstrader / tests / algo / test_equal_weight_pcm.py View on Github external
Forecast(assets[i], val, start_dt, forecast_dt)
            for i, val in enumerate(
                [
                    0.5, 0.25, 0.3, 0.8, 0.87,
                    0.99, 0.35, 0.28, 0.47
                ]
            )
        ]

        # Create Exchange and SimulatedBroker
        prices = [
            45.34, 26.58, 62.432, 88.123, 12.876,
            103.56, 229.54, 650.98, 998.123
        ]
        exchange = ExchangeMock(assets, prices)
        zcm = ZeroBrokerCommission()
        broker = SimulatedBroker(
            start_dt, exchange,
            account_id=1234,
            initial_funds=cash,
            broker_commission=zcm
        )
        bpid = "2222"
        broker.create_portfolio(bpid)
        broker.subscribe_funds_to_portfolio(bpid, cash)

        # Create portfolio construction model
        ewpcm = EqualWeightPCM(
            start_dt, broker, bpid,
            transaction_cost_model=zcm
        )
github mhallsmoore / qstrader / tests / broker / test_simulated_broker.py View on Github external
)
        tcb1 = dict(
            zip(
                settings.CURRENCIES,
                [0.0] * len(settings.CURRENCIES)
            )
        )
        self.assertEqual(sb1.cash_balances, tcb1)
        self.assertEqual(sb1.portfolios, {})
        self.assertEqual(sb1.open_orders, {})

        # Test a SimulatedBroker with some parameters set
        sb2 = SimulatedBroker(
            start_dt, exchange, account_id="ACCT1234",
            base_currency="GBP", initial_funds=1e6,
            broker_commission=ZeroBrokerCommission()
        )
        self.assertEqual(sb2.start_dt, start_dt)
        self.assertEqual(sb2.cur_dt, start_dt)
        self.assertEqual(sb2.exchange, exchange)
        self.assertEqual(sb2.account_id, "ACCT1234")
        self.assertEqual(sb2.base_currency, "GBP")
        self.assertEqual(sb2.initial_funds, 1e6)
        self.assertEqual(
            type(sb2.broker_commission),
            ZeroBrokerCommission
        )
        tcb2 = dict(
            zip(
                settings.CURRENCIES,
                [0.0] * len(settings.CURRENCIES)
            )
github mhallsmoore / qstrader / tests / broker / test_simulated_broker.py View on Github external
appropriate broker commission model depending upon
        user choice.
        """
        start_dt = pd.Timestamp('2017-10-05 08:00:00', tz=pytz.UTC)
        exchange = ExchangeMock()

        # Broker commission is None
        sb1 = SimulatedBroker(start_dt, exchange)
        self.assertEqual(
            sb1.broker_commission.__class__.__name__,
            "ZeroBrokerCommission"
        )

        # Broker commission is specified as a subclass
        # of BrokerCommission abstract base class
        bc2 = ZeroBrokerCommission()
        sb2 = SimulatedBroker(
            start_dt, exchange, broker_commission=bc2
        )
        self.assertEqual(
            sb2.broker_commission.__class__.__name__,
            "ZeroBrokerCommission"
        )

        # Broker commission is mis-specified and thus
        # raises a BrokerException
        with self.assertRaises(BrokerException):
            SimulatedBroker(
                start_dt, exchange, broker_commission="brokercom"
            )
github mhallsmoore / qstrader / tests / broker / test_simulated_broker.py View on Github external
correctly for default settings.
        """
        start_dt = pd.Timestamp('2017-10-05 08:00:00', tz=pytz.UTC)
        exchange = ExchangeMock()

        # Test a default SimulatedBroker
        sb1 = SimulatedBroker(start_dt, exchange)
        self.assertEqual(sb1.start_dt, start_dt)
        self.assertEqual(sb1.cur_dt, start_dt)
        self.assertEqual(sb1.exchange, exchange)
        self.assertEqual(sb1.account_id, None)
        self.assertEqual(sb1.base_currency, "USD")
        self.assertEqual(sb1.initial_funds, 0.0)
        self.assertEqual(
            type(sb1.broker_commission),
            ZeroBrokerCommission
        )
        tcb1 = dict(
            zip(
                settings.CURRENCIES,
                [0.0] * len(settings.CURRENCIES)
            )
        )
        self.assertEqual(sb1.cash_balances, tcb1)
        self.assertEqual(sb1.portfolios, {})
        self.assertEqual(sb1.open_orders, {})

        # Test a SimulatedBroker with some parameters set
        sb2 = SimulatedBroker(
            start_dt, exchange, account_id="ACCT1234",
            base_currency="GBP", initial_funds=1e6,
            broker_commission=ZeroBrokerCommission()
github mhallsmoore / qstrader / tests / algo / test_equal_weight_pcm.py View on Github external
assets = [
            Equity("%s Inc." % ticker, ticker, "NYSE")
            for ticker in [
                "%s" % (letter * 3)
                for letter in string.ascii_uppercase[:9]
            ]
        ]
        forecasts = []

        # Create Exchange and SimulatedBroker
        prices = [
            45.34, 26.58, 62.432, 88.123, 12.876,
            103.56, 229.54, 650.98, 998.123
        ]
        exchange = ExchangeMock(assets, prices)
        zcm = ZeroBrokerCommission()
        broker = SimulatedBroker(
            start_dt, exchange,
            account_id=1234,
            initial_funds=cash,
            broker_commission=zcm
        )
        bpid = "2222"
        broker.create_portfolio(bpid)
        broker.subscribe_funds_to_portfolio(bpid, cash)

        tn1 = Transaction(
            assets[0], 100, start_dt, price=45.78,
            order_id=1, commission=0.0
        )
        tn2 = Transaction(
            assets[1], 200, start_dt, price=26.32,
github mhallsmoore / qstrader / qstrader / broker / simulated_broker.py View on Github external
def _set_broker_commission(self, broker_commission):
        """
        Check and set the BrokerCommission instance for
        the broker. The class default is no commission.
        """
        if broker_commission is None:
            return ZeroBrokerCommission()
        else:
            if (
                hasattr(broker_commission, "__class__") and
                hasattr(broker_commission.__class__, "__name__") and
                issubclass(broker_commission.__class__, BrokerCommission)
            ):
                return broker_commission
            else:
                raise BrokerException(
                    "Provided broker commission is not a "
                    "BrokerCommission subclass, so could not "