def run(stockName, interval_days): nnetwork = NeuralNetwork() nnetwork.setSupervisedDataSetSize(9, 1) objStock = datahandler.getStock(stockName) neural_network_input = objStock.getData() if debug: print '##################################################################' print stockName print '##################################################################\n' total_tests = 0 total_hits = total_hits_highs = total_hits_lows = 0 total_highs = total_lows = 0 fout_highs = open( './results/' + stockName + '_' + str(interval_days) + '_highs', 'w') fout_lows = open( './results/' + stockName + '_' + str(interval_days) + '_lows', 'w') fout_all = open( './results/' + stockName + '_' + str(interval_days) + '_all', 'w') try: # Sliding Window for i in range(len(neural_network_input) - 3 * interval_days): ret = run_day(nnetwork, neural_network_input, i, interval_days, total_tests, total_hits, total_hits_highs, total_hits_lows, total_highs, total_lows) total_tests = ret[0] total_hits = ret[1] total_hits_highs = ret[2] total_hits_lows = ret[3] total_highs = ret[4] total_lows = ret[5] rel_highs = rel_lows = '' if total_highs == 0: rel_highs = ',-1' else: rel_highs = ',' + str(float(total_hits_highs) / total_highs) if total_lows == 0: rel_lows = ',-1' else: rel_lows = ',' + str(float(total_hits_lows) / total_lows) rel_all = ',' + str(float(total_hits) / total_tests) fout_highs.write(rel_highs) fout_lows.write(rel_lows) fout_all.write(rel_all) except KeyboardInterrupt: fout_highs.close() fout_lows.close() fout_all.close()
def run(stockName, interval_days): nnetwork = NeuralNetwork() nnetwork.setSupervisedDataSetSize(9, 1) objStock = datahandler.getStock(stockName) neural_network_input = objStock.getData() if debug: print '##################################################################' print stockName print '##################################################################\n' total_tests=0 total_hits=total_hits_highs=total_hits_lows=0 total_highs=total_lows=0 fout_highs = open('./results/'+stockName+'_'+str(interval_days)+'_highs', 'w') fout_lows = open('./results/'+stockName+'_'+str(interval_days)+'_lows', 'w') fout_all = open('./results/'+stockName+'_'+str(interval_days)+'_all', 'w') try: # Sliding Window for i in range(len(neural_network_input)-3*interval_days): ret = run_day(nnetwork, neural_network_input, i, interval_days, total_tests, total_hits, total_hits_highs, total_hits_lows, total_highs, total_lows) total_tests = ret[0] total_hits = ret[1] total_hits_highs = ret[2] total_hits_lows = ret[3] total_highs = ret[4] total_lows = ret[5] rel_highs=rel_lows='' if total_highs==0: rel_highs = ',-1' else: rel_highs = ','+str(float(total_hits_highs)/total_highs) if total_lows==0: rel_lows=',-1' else: rel_lows = ','+str(float(total_hits_lows)/total_lows) rel_all = ','+str(float(total_hits)/total_tests) fout_highs.write(rel_highs) fout_lows.write(rel_lows) fout_all.write(rel_all) except KeyboardInterrupt: fout_highs.close() fout_lows.close() fout_all.close()
def run(stockName, interval_days, year): nnetwork = NeuralNetwork() nnetwork.setSupervisedDataSetSize(9, 1) objStock = datahandler.getStock(stockName) neural_network_input = objStock.getData() yearLimits = objStock.getYearLimits(year) yearLimits[0] = max(0, yearLimits[0] - 2 * interval_days) #print '##################################################################' #print stockName #print '##################################################################\n' total_tests = 0 total_hits = total_hits_highs = total_hits_lows = 0 total_highs = total_lows = 0 # Sliding Window #for i in range(len(neural_network_input)-3*interval_days): for i in range(yearLimits[0], yearLimits[1] - 3 * interval_days): ret = run_day(nnetwork, neural_network_input, i, interval_days, total_tests, total_hits, total_hits_highs, total_hits_lows, total_highs, total_lows) total_tests = ret[0] total_hits = ret[1] total_hits_highs = ret[2] total_hits_lows = ret[3] total_highs = ret[4] total_lows = ret[5] rel_highs = rel_lows = '' if total_highs == 0: rel_highs = '-1' else: rel_highs = str(float(total_hits_highs) / total_highs) if total_lows == 0: rel_lows = '-1' else: rel_lows = str(float(total_hits_lows) / total_lows) rel_all = str(float(total_hits) / total_tests) #print 'All: ' + rel_all + ' High: ' + rel_highs + ' Low: ' + rel_lows print 'Total:\n' + str(total_hits) + ' out of ' + str(total_tests) print str(total_hits_highs) + ' out of ' + str(total_highs) + ' highs.' print str(total_hits_lows) + ' out of ' + str(total_lows) + ' lows.' + '\n'
def run(stockName, interval_days, year): nnetwork = NeuralNetwork() nnetwork.setSupervisedDataSetSize(9, 1) objStock = datahandler.getStock(stockName) neural_network_input = objStock.getData() yearLimits = objStock.getYearLimits(year) yearLimits[0] = max(0, yearLimits[0]-2*interval_days) #print '##################################################################' #print stockName #print '##################################################################\n' total_tests=0 total_hits=total_hits_highs=total_hits_lows=0 total_highs=total_lows=0 # Sliding Window #for i in range(len(neural_network_input)-3*interval_days): for i in range(yearLimits[0], yearLimits[1]-3*interval_days): ret = run_day(nnetwork, neural_network_input, i, interval_days, total_tests, total_hits, total_hits_highs, total_hits_lows, total_highs, total_lows) total_tests = ret[0] total_hits = ret[1] total_hits_highs = ret[2] total_hits_lows = ret[3] total_highs = ret[4] total_lows = ret[5] rel_highs=rel_lows='' if total_highs==0: rel_highs = '-1' else: rel_highs = str(float(total_hits_highs)/total_highs) if total_lows==0: rel_lows='-1' else: rel_lows = str(float(total_hits_lows)/total_lows) rel_all = str(float(total_hits)/total_tests) #print 'All: ' + rel_all + ' High: ' + rel_highs + ' Low: ' + rel_lows print 'Total:\n' + str(total_hits) + ' out of ' + str(total_tests) print str(total_hits_highs) + ' out of ' + str(total_highs) + ' highs.' print str(total_hits_lows) + ' out of ' + str(total_lows) + ' lows.' + '\n'