<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def midpoint(self) -> float: """ Return average of bid and ask, or NaN if no valid bid and ask are available. """

        return (self.bid + self.ask) / 2 if self.hasBidAsk() else nan