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. """ if ticker not in self.positions: if self.price_handler.istick(): 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 )
def setUp(self): """ Set up the Position object that will store the PnL. """ self.position = Position("BOT", "XOM", 100, PriceParser.parse(74.78), PriceParser.parse(1.00), PriceParser.parse(74.78), PriceParser.parse(74.80))
def setUp(self): self.position = Position("SLD", "PG", 100, PriceParser.parse(77.69), PriceParser.parse(1.00), PriceParser.parse(77.68), PriceParser.parse(77.70))
def setUp(self): self.position = Position("BOT", "XOM", 100, PriceParser.parse(74.78), PriceParser.parse(1.00), PriceParser.parse(74.77), PriceParser.parse(74.79))