def run(): initialized = False # open data row by row to avoid memory overflow fname = 'data_cleaned.csv' with open(fname, 'r+') as f: # this reads in one line at a time from stdin date_previous = None ticker_previous = None observation = {} observationPrevious = {} lineo = 0 for i, line in enumerate(f): #print line fList = line.split(",") date = fList[0] value = float(fList[1]) ticker = str(fList[2]) fundamental = str(fList[3]) # if lineo == 100000: # break if ticker_previous == None: ticker_previous = ticker date_previous = date if date == date_previous: observation[fundamental] = value if date != date_previous: lineo += 1 #print observation observedData = dataParser.getObservation(observation, observationPrevious) observationPrevious = observation observation = {} observation[fundamental] = value date_previous = date curState = state(observedData) if (not initialized): initialized = True print "register initial" agent.registerInitialState(curState) else: #print "called observe function" agent.observationFunction(curState) if (i % 100000 == 0): print "HERE" agent.final(curState) elif (i % 100 == 0): print "HERE NOW" agent.stopEpisode() initialized = False
def run(): initialized = False # open data row by row to avoid memory overflow fname = 'data_cleaned.csv' with open(fname, 'r+') as f: # this reads in one line at a time from stdin date_previous = None ticker_previous = None observation = {} observationPrevious = {} isFirstObservation = True lineo = 0 for i, line in enumerate(f): #print line fList = line.split(",") date = fList[0] value = float(fList[1]) ticker = str(fList[2]) fundamental = str(fList[3]) if (date_previous == None): date_previous = date elif (date_previous != date): if (not isFirstObservation): #break observedData = dataParser.getObservation(observationPrevious, observation) curState = state(observedData) action = agent.getAction(curState) priceChange = curState.getScore() reward = action * priceChange agent.update(reward, curState, action) #print observation #print observationPrevious print agent.getPercentCorrect() print agent.getTotalRewards() else: isFirstObservation = False observationPrevious = copy.deepcopy(observation) observation = {} date_previous = date if (ticker_previous == None): ticker_previous = ticker elif (ticker_previous != ticker): isFirstObservation = True ticker_previous = ticker observation[fundamental] = value