def processIndividual(q): while not exitFlag: queueLock.acquire() if not workQueue.empty(): data = q.get() individualId = data[0] date = data[1] startTime = data[2] endTime = data[3] mtmObject = MTM() rewardMatrixObject = RewardMatrix() qMatrixObject = QMatrix() dbObject = DBUtils() dbObject.dbConnect() print('Calculating mtm for all trades of this individual') mtmObject.calculateMTM(individualId, gv.aggregationUnit, date, startTime, date, endTime, dbObject) print('Calculating reward matrix for these individuals') rewardMatrix = rewardMatrixObject.computeRM( individualId, date, startTime, date, endTime, dbObject) print('Calculating q matrix for these individuals') qMatrixObject.calculateQMatrix(rewardMatrix, individualId, dbObject) queueLock.release() #dbObject.dbClose() else: queueLock.release()
print( 'Since the individual has asset, adding the trade to new tradesheet' ) dbObject.insertNewTrade( tradeId, individualId, tradeType, entryDate, entryTime, entryPrice, entryQty, exitDate, exitTime, exitPrice) dbObject.updateIndividualAsset( gv.dummyIndividualId, usedAsset) dbObject.updateIndividualAsset( individualId, usedAsset) print('Calculating mtm for all the trades taken in last hour') mtmObject.calculateMTM(gv.aggregationUnit, date, startTime, date, endTime, dbObject) print('Fetching individuals which took trades in last hour') resultIndividuals = dbObject.getIndividuals( date, startTime, date, endTime) for individualId, dummy in resultIndividuals: print('Calculating reward matrix for these individuals') rewardMatrix = rewardMatrixObject.computeRM( individualId, date, startTime, date, endTime, dbObject) print('Calculating q matrix for these individuals') qMatrixObject.calculateQMatrix(rewardMatrix, individualId, dbObject) print('Reallocating asset for these individuals') reallocationObject.reallocate(date, startTime, date, endTime, dbObject) if endTime < dayEndTime: