def marketCap(firm, date, pdatabase, printWarnings=True, sharesUnit=1000):
    """
    Market capitalization of firm as of market open on date
    Relies on naming of pdatabase (crsp)
    Returns -1 if no data available
    Returns FLOAT
    """
    if (firm, date) in pdatabase.mcap:
        return pdatabase.mcap[(firm, date)]
    dateQuery = pdatabase.data.query('(TICKER == "' + firm + '") & (date == "' + date + '")')
    if dateQuery.empty:
        if printWarnings:
            print("NO PRICE AND SHARES DATA: " + firm + ", " + date)
        return -1
    price = float(dateQuery["OPENPRC"].iat[0])
    # SHROUT in thousands
    sharesOutstanding = float(dateQuery["SHROUT"].iat[0]) * sharesUnit
    # print(price)
    # print(sharesOutstanding)
    mc = price * sharesOutstanding
    pdatabase.mcap[(firm, date)] = mc
    return mc