Ejemplo n.º 1
0
    def _add_position(
        self, action, ticker,
        quantity, price, commission
    ):
        """
        Adds a new Position object to the Portfolio. This
        requires getting the best bid/ask price from the
        price handler in order to calculate a reasonable
        "market value".

        Once the Position is added, the Portfolio values
        are updated.
        """
        self._reset_values()
        if ticker not in self.positions:
            if self.price_handler.type == "TICK_HANDLER":
                bid, ask = self.price_handler.get_best_bid_ask(ticker)
            else:
                close_price = self.price_handler.get_last_close(ticker)
                bid = close_price
                ask = close_price
            position = Position(
                action, ticker, quantity,
                price, commission, bid, ask
            )
            self.positions[ticker] = position
            self._update_portfolio()
        else:
            print(
                "Ticker %s is already in the positions list. " \
                "Could not add a new position." % ticker
            )
Ejemplo n.º 2
0
 def setUp(self):
     """
     Set up the Position object that will store the PnL.
     """
     self.position = Position("BOT", "XOM", Decimal('100'),
                              Decimal("74.78"), Decimal("1.00"),
                              Decimal('74.78'), Decimal('74.80'))
Ejemplo n.º 3
0
 def add_position(self, action, ticker, quantity, price, commission):
     self._reset_values()
     if ticker not in self.positions:
         bid, ask = self.price_handler.get_best_bid_ask(ticker)
         position = Position(action, ticker, quantity, price, commission,
                             bid, ask)
         self.positions[ticker] = position
         self._update_portfolio()
Ejemplo n.º 4
0
 def setUp(self):
     self.position = Position("SLD", "PG", Decimal('100'), Decimal("77.69"),
                              Decimal("1.00"), Decimal('77.68'),
                              Decimal('77.70'))