'Modifies a current 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 modified, the Portfolio values
are updated.'

def _modify_position(self, action, ticker, quantity, price, commission):

    if (ticker in self.positions):
        self.positions[ticker].transact_shares(action, quantity, price, commission)
        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
        self.positions[ticker].update_market_value(bid, ask)
        if (self.positions[ticker].quantity == 0):
            closed = self.positions.pop(ticker)
            self.realised_pnl += closed.realised_pnl
            self.closed_positions.append(closed)
        self._update_portfolio()
    else:
        print ('Ticker    %s    not    in    the    current    position    list.    Could    not    modify    a    current    position.' % ticker)
