def merge_schedules(schedules, how='outer'):
    """
    Given a list of schedules will return a merged schedule. The merge method (how) will either return the superset
    of any datetime when any schedule is open (outer) or only the datetime where all markets are open (inner)

    :param schedules: list of schedules
    :param how: outer or inner
    :return: schedule DataFrame
    """
    result = schedules[0]
    for schedule in schedules[1:]:
        result = result.merge(schedule, how=how, right_index=True,
            left_index=True)
        if how == 'outer':
            result['market_open'] = result.apply(lambda x: min(x.
                market_open_x, x.market_open_y), axis=1)
            result['market_close'] = result.apply(lambda x: max(x.
                market_close_x, x.market_close_y), axis=1)
        elif how == 'inner':
            result['market_open'] = result.apply(lambda x: max(x.
                market_open_x, x.market_open_y), axis=1)
            result['market_close'] = result.apply(lambda x: min(x.
                market_close_x, x.market_close_y), axis=1)
        else:
            raise ValueError('how argument must be "inner" or "outer"')
        result = result[['market_open', 'market_close']]
    return result
