Create a DataFrame of orders (signed share quantities) based on event triggers (T/F or 0/1 matrix)

    Arguments:
      events (DataFrame): mask table to indicate occurrence of buy event (1 = buy, NaN/0/False = do nothing)
      sell_delay (int): number of days after the buy order to initiate a sell order of those shares
      num_shares (int): number of shares to buy and sell at each event

    Returns:
      DataFrame: Signed integer numbers of shares to buy (+) or sell (-)
        columns are stock ticker symbols
        index is datetime at end of trading day (16:00 in NY)

def orders_from_events(events, sell_delay=5, num_shares=100):
    """Create a DataFrame of orders (signed share quantities) based on event triggers (T/F or 0/1 matrix)

    Arguments:
      events (DataFrame): mask table to indicate occurrence of buy event (1 = buy, NaN/0/False = do nothing)
      sell_delay (int): number of days after the buy order to initiate a sell order of those shares
      num_shares (int): number of shares to buy and sell at each event

    Returns:
      DataFrame: Signed integer numbers of shares to buy (+) or sell (-)
        columns are stock ticker symbols
        index is datetime at end of trading day (16:00 in NY)
    """

    buy = events.copy() * num_shares
    sell = -1 * pd.DataFrame(buy.copy().values[:-sell_delay], index=buy.index[sell_delay:], columns=buy.columns)
    sell = pd.concat([0 * buy.iloc[:sell_delay], sell])
    for i in range(sell_delay):
        sell.iloc[-1] -= buy.iloc[-sell_delay + i]
    orders = buy + sell
    return orders