def compute_market_prices(prices):
    """Compute market prices according to the trading competition recipe.

    Parameters
    ----------
    prices : DataFrame
        Data frame with market prices. Should include columns 'bid_price',
        'bid_volume', 'aks_price', 'ask_volume'.

    Returns
    -------
    prices : DataFrame
        Same data frame, but with a column 'market_price' appended.
    """
    denom = prices.bid_volume + prices.ask_volume
    numer = (prices.bid_price * prices.ask_volume +
             prices.ask_price * prices.bid_volume)
    mask = denom == 0
    denom[mask] = 2
    numer[mask] = prices.bid_price[mask] + prices.ask_price[mask]
    prices = prices.copy()
    prices['market_price'] = numer / denom
    return prices