def simulateBySymbol(filename, combineByOrderDate=False, agentNums=[100]): """ Treat all bidders for the same symbol, in ALL dates, as a distribution of values for that symbol. """ datasetFilename = "datasets/"+filename+".CSV" resultsFilename = "results/"+filename+("-combined" if combineByOrderDate else "")+"-r"+str(max(agentNums))+".csv" resultsFilenameTemp = "results/"+filename+"-temp.csv" results = DataFrame(columns=COLUMNS) print("\t{}".format(COLUMNS)) for symbol,allTimeTraders in torq.auctionsBySymbol(datasetFilename, combineByOrderDate): date = 0 for agentNum in agentNums: traders = [random.choice(allTimeTraders) for i in range(agentNum)] print("Simulating auction {}-{} with {} traders".format(symbol,date,len(traders))) totalBuyers = sum([t.isBuyer for t in traders]) totalSellers = len(traders)-totalBuyers totalUnits = sum([t.totalUnits() for t in traders]) maxUnitsPerTrader = max([t.totalUnits() for t in traders]) # maxUnitsPerTrader is denoted in the paper by m. stddev = np.sqrt(sum([t.totalUnits()**2 for t in traders])) (buyersWALRAS, sellersWALRAS, sizeWALRAS, gainWALRAS) = WALRAS(traders) # sizeWALRAS is denoted in the paper by k. (sizeMIDALottery, gainMIDALottery, gainMIDALottery, sizeMIDAVickrey, tradersGainMIDAVickrey, totalGainMIDAVickrey) = MIDA(traders, Lottery=True, Vickrey=True) resultsRow = [ (symbol,date), totalBuyers, totalSellers, totalBuyers+totalSellers, min(totalBuyers,totalSellers), totalUnits, maxUnitsPerTrader, stddev, buyersWALRAS, sellersWALRAS, sizeWALRAS, gainWALRAS, gainMIDALottery, tradersGainMIDAVickrey, totalGainMIDAVickrey] print("\t{}".format(resultsRow)) results.loc[len(results)] = resultsRow results.to_csv(resultsFilenameTemp) results.to_csv(resultsFilename) os.remove(resultsFilenameTemp) return results
def torqSimulateBySymbol(filename, combineByOrderDate=False, agentNums=[100]): """ Treat all bidders for the same symbol, in ALL dates, as a distribution of values for that symbol. """ datasetFilename = "datasets/" + filename + ".CSV" resultsFilename = "results/" + filename + ( "-combined" if combineByOrderDate else "") + "-s" + str( max(agentNums)) + ".csv" return simulateAuctions(sampleAuctions( agentNums, torq.auctionsBySymbol(datasetFilename, combineByOrderDate)), resultsFilename, keyColumns=("symbol", ))