def update_market_value(self, price):
"""Compute the current marke value of the position. This is the current
price multiplied by the direction of the trade (r2epresented by the sign
of the net number of shares bought and sold). The function also updated
the unrealized and realized profits and losses.
"""
# Compute the mean of the bid and ask price to compute the assumed value
# of the position.
#
# N.B. That the market value is akin to the amount of cash that is would
# be injected into the portfolio if the position were liquidated. This
# means that if a position is short, then a negative amount will be
# injected (i.e. paid out). On the other hand, the current value is the
# profit-and-loss on a position relative to the cost basis.
self.market_value = self.net * price
self.unrealized_pnl = self.market_value - self.cost_basis
self.realized_pnl = self.market_value + self.net_tot_incl_comm
评论列表
文章目录