How to use the qstrader.price_parser.PriceParser.display 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 / test_position.py View on Github external
self.assertEqual(self.position.sells, 250)
        self.assertEqual(self.position.net, 0)
        self.assertEqual(
            PriceParser.display(self.position.avg_bot, 3), 77.746
        )
        self.assertEqual(
            PriceParser.display(self.position.avg_sld, 3), 77.688
        )
        self.assertEqual(PriceParser.display(self.position.total_bot), 19436.50)
        self.assertEqual(PriceParser.display(self.position.total_sld), 19422.00)
        self.assertEqual(PriceParser.display(self.position.net_total), -14.50)
        self.assertEqual(PriceParser.display(self.position.total_commission), 5.00)
        self.assertEqual(PriceParser.display(self.position.net_incl_comm), -19.50)

        self.assertEqual(
            PriceParser.display(self.position.avg_price, 5), 77.67600
        )
        self.assertEqual(PriceParser.display(self.position.cost_basis), 0.00)
        self.assertEqual(PriceParser.display(self.position.market_value), 0.00)
        self.assertEqual(PriceParser.display(self.position.unrealised_pnl), 0.00)
        self.assertEqual(PriceParser.display(self.position.realised_pnl), -19.50)
github mhallsmoore / qstrader / tests / test_position.py View on Github external
def test_open_short_position(self):
        self.assertEqual(PriceParser.display(self.position.cost_basis), -7768.00)
        self.assertEqual(PriceParser.display(self.position.market_value), -7769.00)
        self.assertEqual(PriceParser.display(self.position.unrealised_pnl), -1.00)
        self.assertEqual(PriceParser.display(self.position.realised_pnl), 0.00)

        self.position.update_market_value(
            PriceParser.parse(77.72), PriceParser.parse(77.72)
        )

        self.assertEqual(PriceParser.display(self.position.cost_basis), -7768.00)
        self.assertEqual(PriceParser.display(self.position.market_value), -7772.00)
        self.assertEqual(PriceParser.display(self.position.unrealised_pnl), -4.00)
        self.assertEqual(PriceParser.display(self.position.realised_pnl), 0.00)
github mhallsmoore / qstrader / tests / test_position.py View on Github external
self.position.update_market_value(
            PriceParser.parse(77.75), PriceParser.parse(77.77)
        )

        self.assertEqual(self.position.action, "BOT")
        self.assertEqual(self.position.ticker, "XOM")
        self.assertEqual(self.position.quantity, 0)

        self.assertEqual(self.position.buys, 450)
        self.assertEqual(self.position.sells, 450)
        self.assertEqual(self.position.net, 0)
        self.assertEqual(
            PriceParser.display(self.position.avg_bot, 5), 74.65778
        )
        self.assertEqual(
            PriceParser.display(self.position.avg_sld, 5), 74.95778
        )
        self.assertEqual(PriceParser.display(self.position.total_bot), 33596.00)
        self.assertEqual(PriceParser.display(self.position.total_sld), 33731.00)
        self.assertEqual(PriceParser.display(self.position.net_total), 135.00)
        self.assertEqual(PriceParser.display(self.position.total_commission), 5.50)
        self.assertEqual(PriceParser.display(self.position.net_incl_comm), 129.50)

        self.assertEqual(
            PriceParser.display(self.position.avg_price, 3), 74.665
        )
        self.assertEqual(PriceParser.display(self.position.cost_basis), 0.00)
        self.assertEqual(PriceParser.display(self.position.market_value), 0.00)
        self.assertEqual(PriceParser.display(self.position.unrealised_pnl), 0.00)
        self.assertEqual(PriceParser.display(self.position.realised_pnl), 129.50)
github mhallsmoore / qstrader / tests / test_position.py View on Github external
self.assertEqual(
            PriceParser.display(self.position.avg_sld, 5), 74.95778
        )
        self.assertEqual(PriceParser.display(self.position.total_bot), 33596.00)
        self.assertEqual(PriceParser.display(self.position.total_sld), 33731.00)
        self.assertEqual(PriceParser.display(self.position.net_total), 135.00)
        self.assertEqual(PriceParser.display(self.position.total_commission), 5.50)
        self.assertEqual(PriceParser.display(self.position.net_incl_comm), 129.50)

        self.assertEqual(
            PriceParser.display(self.position.avg_price, 3), 74.665
        )
        self.assertEqual(PriceParser.display(self.position.cost_basis), 0.00)
        self.assertEqual(PriceParser.display(self.position.market_value), 0.00)
        self.assertEqual(PriceParser.display(self.position.unrealised_pnl), 0.00)
        self.assertEqual(PriceParser.display(self.position.realised_pnl), 129.50)
github mhallsmoore / qstrader / tests / test_priceparser.py View on Github external
def test_display(self):
        parsed = PriceParser.parse(self.float)
        displayed = PriceParser.display(parsed)
        self.assertEqual(displayed, 10.12)
github mhallsmoore / qstrader / qstrader / compliance / example.py View on Github external
def record_trade(self, fill):
        """
        Append all details about the FillEvent to the CSV trade log.
        """
        fname = os.path.expanduser(os.path.join(self.config.OUTPUT_DIR, self.csv_filename))
        with open(fname, 'a') as csvfile:
            writer = csv.writer(csvfile)
            writer.writerow([
                fill.timestamp, fill.ticker,
                fill.action, fill.quantity,
                fill.exchange, PriceParser.display(fill.price, 4),
                PriceParser.display(fill.commission, 4)
            ])
github mhallsmoore / qstrader / qstrader / strategy / display.py View on Github external
def calculate_signals(self, event):
        if event.type in [EventType.TICK, EventType.BAR]:
            # Format the event for human display
            if event.type == EventType.BAR:
                event.open_price = PriceParser.display(event.open_price)
                event.high_price = PriceParser.display(event.high_price)
                event.low_price = PriceParser.display(event.low_price)
                event.close_price = PriceParser.display(event.close_price)
                event.adj_close_price = PriceParser.display(event.adj_close_price)
            else:  # event.type == EventType.TICK
                event.bid = PriceParser.display(event.bid)
                event.ask = PriceParser.display(event.ask)

            if self.i % self.n == 0 and self.i != 0:
                print(s_speed(event, self.i, self.t0))
                print("")
            if self.i % self.n in range(self.n_window):
                print("%d %s" % (self.i, event))
            self.i += 1
github mhallsmoore / qstrader / qstrader / strategy / display.py View on Github external
def calculate_signals(self, event):
        if event.type in [EventType.TICK, EventType.BAR]:
            # Format the event for human display
            if event.type == EventType.BAR:
                event.open_price = PriceParser.display(event.open_price)
                event.high_price = PriceParser.display(event.high_price)
                event.low_price = PriceParser.display(event.low_price)
                event.close_price = PriceParser.display(event.close_price)
                event.adj_close_price = PriceParser.display(event.adj_close_price)
            else:  # event.type == EventType.TICK
                event.bid = PriceParser.display(event.bid)
                event.ask = PriceParser.display(event.ask)

            if self.i % self.n == 0 and self.i != 0:
                print(s_speed(event, self.i, self.t0))
                print("")
            if self.i % self.n in range(self.n_window):
                print("%d %s" % (self.i, event))
            self.i += 1