code: def update_position(position, trade):
      r"""Add the new trade to the position and revalue.
  
      Parameters
      ----------
      position : alphapy.Position
          The position to be update.
      trade : alphapy.Trade
          Trade for updating the position.
  
      Returns
      -------
      position : alphapy.Position
          New value of the position.
  
      """
      position.trades.append(trade)
      position.ntrades = position.ntrades + 1
      position.date = trade.tdate
      position.held = trade.tdate - position.opened
      position = valuate_position(position, trade.tdate)
      if position.quantity > 0:
          position.mpos = "long"
      if position.quantity < 0:
          position.mpos = "short"
      return position
  
imports: from alphapy.frame import Frame
  from alphapy.frame import frame_name
  from alphapy.frame import read_frame
  from alphapy.frame import write_frame
  from alphapy.globals import MULTIPLIERS, SSEP
  from alphapy.globals import Orders
  from alphapy.space import Space
  import logging
  import math
  import numpy
  from pandas import DataFrame
  from pandas import date_range
  from pandas import Series
label_desc: Use image node_id 5 for calling a global function with example usage: update_position(position, trade) and returns: position