#NEWLINE# def update_market_value( self , bid , ask ) : #NEWLINE# #INDENT# '\n        The market value is tricky to calculate as we only have\n        access to the top of the order book through Interactive\n        Brokers, which means that the true redemption price is\n        unknown until executed.\n\n        However, it can be estimated via the mid-price of the\n        bid-ask spread. Once the market value is calculated it\n        allows calculation of the unrealised and realised profit\n        and loss of any transactions.\n        ' #NEWLINE# midpoint = ( ( bid + ask ) / Decimal ( '2.0' ) ) #NEWLINE# self . market_value = ( self . quantity * midpoint ) . quantize ( TWOPLACES ) #NEWLINE# self . unrealised_pnl = ( self . market_value - self . cost_basis ) . quantize ( TWOPLACES ) #NEWLINE# self . realised_pnl = ( self . market_value + self . net_incl_comm )