How to use the qstrader.algo.order.Order 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 / tests / algo / test_equal_weight_pcm.py View on Github external
broker_commission=tdcm
        )
        bpid = "5678"
        broker.create_portfolio(portfolio_id="5678")
        broker.subscribe_funds_to_portfolio("5678", cash)

        # Create portfolio construction model
        ewpcm = EqualWeightPCM(
            start_dt, broker, bpid,
            transaction_cost_model=tdcm
        )

        # Calculate order equivalence
        order_list = ewpcm.generate_orders(forecasts)
        test_order_list = [
            Order(start_dt, assets[i], val)
            for i, val in enumerate(
                [1007, 473, 389, 193]
            )
        ]
        check_equal_order_properties(self, order_list, test_order_list)

    # def test_check_maintenance_of_equal_weights_over_time(self):
        """
        Checks that after an initial portfolio construction that the
github mhallsmoore / qstrader / tests / algo / test_equal_weight_pcm.py View on Github external
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
        )

        # Calculate order equivalence
        order_list = ewpcm.generate_orders(forecasts)
        test_order_list = [
            Order(start_dt, assets[i], val)
            for i, val in enumerate(
                [
                    1225, 2090, 889, 630, 4314,
                    536, 242, 85, 55
                ]
            )
        ]
        check_equal_order_properties(self, order_list, test_order_list)
github mhallsmoore / qstrader / tests / algo / test_equal_weight_pcm.py View on Github external
broker.portfolios[bpid].transact_asset(tn1)
        broker.portfolios[bpid].transact_asset(tn2)
        broker.portfolios[bpid].transact_asset(tn3)

        # Create portfolio construction model
        ewpcm = EqualWeightPCM(
            start_dt, broker, bpid,
            transaction_cost_model=zcm
        )

        # Calculate order equivalence
        order_list = ewpcm.generate_orders(forecasts)
        test_order_list = [
            Order(start_dt, assets[0], -100),
            Order(start_dt, assets[1], -200),
            Order(start_dt, assets[2], 100),
        ]
        check_equal_order_properties(self, order_list, test_order_list)
github mhallsmoore / qstrader / tests / algo / test_portfolio_construction_model.py View on Github external
bp5 = {
            self.assets["III"]: {"quantity": 103},
            self.assets["JJJ"]: {"quantity": 38},
            self.assets["KKK"]: {"quantity": 221},
            self.assets["LLL"]: {"quantity": 59},
            self.assets["MMM"]: {"quantity": 76},
        }
        diff_orders5 = self.pcm._diff_desired_broker_portfolios(dp, bp5)
        test_orders5 = [
            Order(self.start_dt, self.assets["AAA"], 101),
            Order(self.start_dt, self.assets["BBB"], 50),
            Order(self.start_dt, self.assets["CCC"], 25),
            Order(self.start_dt, self.assets["DDD"], 34),
            Order(self.start_dt, self.assets["EEE"], 47),
            Order(self.start_dt, self.assets["FFF"], 99),
            Order(self.start_dt, self.assets["GGG"], 145),
            Order(self.start_dt, self.assets["HHH"], 55),
            Order(self.start_dt, self.assets["III"], -103),
            Order(self.start_dt, self.assets["JJJ"], -38),
            Order(self.start_dt, self.assets["KKK"], -221),
            Order(self.start_dt, self.assets["LLL"], -59),
            Order(self.start_dt, self.assets["MMM"], -76),
        ]
        check_equal_order_properties(self, diff_orders5, test_orders5)

        # Test #6 - Long only desired, strict superset at broker
        bp6 = {
            self.assets["AAA"]: {"quantity": 23},
            self.assets["BBB"]: {"quantity": 75},
            self.assets["CCC"]: {"quantity": 34},
            self.assets["DDD"]: {"quantity": 29},
            self.assets["EEE"]: {"quantity": 48},
github mhallsmoore / qstrader / tests / algo / test_portfolio_construction_model.py View on Github external
test_orders3 = []
        check_equal_order_properties(self, diff_orders3, test_orders3)

        # Test #4 - Long only desired, partial intersection at broker
        bp4 = {
            self.assets["EEE"]: {"quantity": 32},
            self.assets["FFF"]: {"quantity": 88},
            self.assets["GGG"]: {"quantity": 109},
            self.assets["HHH"]: {"quantity": 55},
            self.assets["III"]: {"quantity": 234},
            self.assets["JJJ"]: {"quantity": 8},
        }
        diff_orders4 = self.pcm._diff_desired_broker_portfolios(dp, bp4)
        test_orders4 = [
            Order(self.start_dt, self.assets["AAA"], 101),
            Order(self.start_dt, self.assets["BBB"], 50),
            Order(self.start_dt, self.assets["CCC"], 25),
            Order(self.start_dt, self.assets["DDD"], 34),
            Order(self.start_dt, self.assets["EEE"], 15),
            Order(self.start_dt, self.assets["FFF"], 11),
            Order(self.start_dt, self.assets["GGG"], 36),
            Order(self.start_dt, self.assets["III"], -234),
            Order(self.start_dt, self.assets["JJJ"], -8),
        ]
        check_equal_order_properties(self, diff_orders4, test_orders4)

        # Test #5 - Long only desired, zero intersection at broker
        bp5 = {
            self.assets["III"]: {"quantity": 103},
            self.assets["JJJ"]: {"quantity": 38},
            self.assets["KKK"]: {"quantity": 221},
            self.assets["LLL"]: {"quantity": 59},
github mhallsmoore / qstrader / tests / algo / test_portfolio_construction_model.py View on Github external
check_equal_order_properties(self, diff_orders4, test_orders4)

        # Test #5 - Long only desired, zero intersection at broker
        bp5 = {
            self.assets["III"]: {"quantity": 103},
            self.assets["JJJ"]: {"quantity": 38},
            self.assets["KKK"]: {"quantity": 221},
            self.assets["LLL"]: {"quantity": 59},
            self.assets["MMM"]: {"quantity": 76},
        }
        diff_orders5 = self.pcm._diff_desired_broker_portfolios(dp, bp5)
        test_orders5 = [
            Order(self.start_dt, self.assets["AAA"], 101),
            Order(self.start_dt, self.assets["BBB"], 50),
            Order(self.start_dt, self.assets["CCC"], 25),
            Order(self.start_dt, self.assets["DDD"], 34),
            Order(self.start_dt, self.assets["EEE"], 47),
            Order(self.start_dt, self.assets["FFF"], 99),
            Order(self.start_dt, self.assets["GGG"], 145),
            Order(self.start_dt, self.assets["HHH"], 55),
            Order(self.start_dt, self.assets["III"], -103),
            Order(self.start_dt, self.assets["JJJ"], -38),
            Order(self.start_dt, self.assets["KKK"], -221),
            Order(self.start_dt, self.assets["LLL"], -59),
            Order(self.start_dt, self.assets["MMM"], -76),
        ]
        check_equal_order_properties(self, diff_orders5, test_orders5)

        # Test #6 - Long only desired, strict superset at broker
        bp6 = {
            self.assets["AAA"]: {"quantity": 23},
            self.assets["BBB"]: {"quantity": 75},
github mhallsmoore / qstrader / tests / algo / test_portfolio_construction_model.py View on Github external
check_equal_order_properties(self, diff_orders3, test_orders3)

        # Test #4 - Long only desired, partial intersection at broker
        bp4 = {
            self.assets["EEE"]: {"quantity": 32},
            self.assets["FFF"]: {"quantity": 88},
            self.assets["GGG"]: {"quantity": 109},
            self.assets["HHH"]: {"quantity": 55},
            self.assets["III"]: {"quantity": 234},
            self.assets["JJJ"]: {"quantity": 8},
        }
        diff_orders4 = self.pcm._diff_desired_broker_portfolios(dp, bp4)
        test_orders4 = [
            Order(self.start_dt, self.assets["AAA"], 101),
            Order(self.start_dt, self.assets["BBB"], 50),
            Order(self.start_dt, self.assets["CCC"], 25),
            Order(self.start_dt, self.assets["DDD"], 34),
            Order(self.start_dt, self.assets["EEE"], 15),
            Order(self.start_dt, self.assets["FFF"], 11),
            Order(self.start_dt, self.assets["GGG"], 36),
            Order(self.start_dt, self.assets["III"], -234),
            Order(self.start_dt, self.assets["JJJ"], -8),
        ]
        check_equal_order_properties(self, diff_orders4, test_orders4)

        # Test #5 - Long only desired, zero intersection at broker
        bp5 = {
            self.assets["III"]: {"quantity": 103},
            self.assets["JJJ"]: {"quantity": 38},
            self.assets["KKK"]: {"quantity": 221},
            self.assets["LLL"]: {"quantity": 59},
            self.assets["MMM"]: {"quantity": 76},
github mhallsmoore / qstrader / tests / algo / test_portfolio_construction_model.py View on Github external
diff_orders3 = self.pcm._diff_desired_broker_portfolios(dp, bp3)
        test_orders3 = []
        check_equal_order_properties(self, diff_orders3, test_orders3)

        # Test #4 - Long only desired, partial intersection at broker
        bp4 = {
            self.assets["EEE"]: {"quantity": 32},
            self.assets["FFF"]: {"quantity": 88},
            self.assets["GGG"]: {"quantity": 109},
            self.assets["HHH"]: {"quantity": 55},
            self.assets["III"]: {"quantity": 234},
            self.assets["JJJ"]: {"quantity": 8},
        }
        diff_orders4 = self.pcm._diff_desired_broker_portfolios(dp, bp4)
        test_orders4 = [
            Order(self.start_dt, self.assets["AAA"], 101),
            Order(self.start_dt, self.assets["BBB"], 50),
            Order(self.start_dt, self.assets["CCC"], 25),
            Order(self.start_dt, self.assets["DDD"], 34),
            Order(self.start_dt, self.assets["EEE"], 15),
            Order(self.start_dt, self.assets["FFF"], 11),
            Order(self.start_dt, self.assets["GGG"], 36),
            Order(self.start_dt, self.assets["III"], -234),
            Order(self.start_dt, self.assets["JJJ"], -8),
        ]
        check_equal_order_properties(self, diff_orders4, test_orders4)

        # Test #5 - Long only desired, zero intersection at broker
        bp5 = {
            self.assets["III"]: {"quantity": 103},
            self.assets["JJJ"]: {"quantity": 38},
            self.assets["KKK"]: {"quantity": 221},
github mhallsmoore / qstrader / tests / algo / test_portfolio_construction_model.py View on Github external
bp4 = {
            self.assets["EEE"]: {"quantity": 32},
            self.assets["FFF"]: {"quantity": 88},
            self.assets["GGG"]: {"quantity": 109},
            self.assets["HHH"]: {"quantity": 55},
            self.assets["III"]: {"quantity": 234},
            self.assets["JJJ"]: {"quantity": 8},
        }
        diff_orders4 = self.pcm._diff_desired_broker_portfolios(dp, bp4)
        test_orders4 = [
            Order(self.start_dt, self.assets["AAA"], 101),
            Order(self.start_dt, self.assets["BBB"], 50),
            Order(self.start_dt, self.assets["CCC"], 25),
            Order(self.start_dt, self.assets["DDD"], 34),
            Order(self.start_dt, self.assets["EEE"], 15),
            Order(self.start_dt, self.assets["FFF"], 11),
            Order(self.start_dt, self.assets["GGG"], 36),
            Order(self.start_dt, self.assets["III"], -234),
            Order(self.start_dt, self.assets["JJJ"], -8),
        ]
        check_equal_order_properties(self, diff_orders4, test_orders4)

        # Test #5 - Long only desired, zero intersection at broker
        bp5 = {
            self.assets["III"]: {"quantity": 103},
            self.assets["JJJ"]: {"quantity": 38},
            self.assets["KKK"]: {"quantity": 221},
            self.assets["LLL"]: {"quantity": 59},
            self.assets["MMM"]: {"quantity": 76},
        }
        diff_orders5 = self.pcm._diff_desired_broker_portfolios(dp, bp5)
        test_orders5 = [
github mhallsmoore / qstrader / tests / algo / test_portfolio_construction_model.py View on Github external
self.assets["BBB"]: {"quantity": 4632},
            self.assets["CCC"]: {"quantity": 567},
            self.assets["DDD"]: {"quantity": -123},
        }
        bp = {
            "total_cash": 5000.0,
            "total_securities_value": 5832.0,
            "total_equity": 10832.0,
            self.assets["AAA"]: {"quantity": -24},
            self.assets["BBB"]: {"quantity": 3726},
        }
        diff_orders = self.pcm._diff_desired_broker_portfolios(dp, bp)
        test_orders = [
            Order(self.start_dt, self.assets["AAA"], -12),
            Order(self.start_dt, self.assets["BBB"], 906),
            Order(self.start_dt, self.assets["CCC"], 567),
            Order(self.start_dt, self.assets["DDD"], -123),
        ]
        check_equal_order_properties(self, diff_orders, test_orders)