def analyzeSymbol(stockSymbol): startTime = time.time() flag = 0 trainingData = getTrainingData(stockSymbol) network = NeuralNetwork(inputNodes=3, hiddenNodes=3, outputNodes=1) network.train(trainingData) # get rolling data for most recent day network.train(trainingData) for i in range(0, 5): # get rolling data for most recent day predictionData = getPredictionData(stockSymbol, flag) returnPrice = network.test(predictionData) # de-normalize and return predicted stock price predictedStockPrice = denormalizePrice(returnPrice, predictionData[1], predictionData[2]) print predictedStockPrice flag += 1 global new_value new_value = predictedStockPrice return predictedStockPrice
def analyzeSymbol(stockSymbol): startTime = time.time() trainingData = getTrainingData(stockSymbol) network = NeuralNetwork(inputNodes=3, hiddenNodes=3, outputNodes=1) network.train(trainingData) # get rolling data for most recent day predictionData = getPredictionData(stockSymbol) # get prediction returnPrice = network.test(predictionData) # de-normalize and return predicted stock price predictedStockPrice = denormalizePrice(returnPrice, predictionData[1], predictionData[2]) # create return object, including the amount of time used to predict returnData = {} returnData['price'] = predictedStockPrice returnData['time'] = time.time() - startTime return returnData
def analyzeSymbol(): trainingData = getTrainingData() network = NeuralNetwork(inputNodes = 3, hiddenNodes = 5, outputNodes = 1) model = network.train(trainingData) # get rolling data for most recent day predictionData = getPredictionData(0) returnPrice = network.test(predictionData) predictedStockPrice = denormalizePrice(returnPrice, predictionData[1], predictionData[2]) returnData = {} returnData[0] = predictedStockPrice return (predictedStockPrice)
def analyzeSymbol(stockSymbol): startTime = time.time() trainingData = getTrainingData(stockSymbol) network = NeuralNetwork(inputNodes = 3, hiddenNodes = 3, outputNodes = 1) network.train(trainingData) # get rolling data for most recent day predictionData = getPredictionData(stockSymbol) # get prediction returnPrice = network.test(predictionData) # de-normalize and return predicted stock price predictedStockPrice = denormalizePrice(returnPrice, predictionData[1], predictionData[2]) # create return object, including the amount of time used to predict returnData = {} returnData['price'] = predictedStockPrice returnData['time'] = time.time() - startTime return returnData
def analyzeId(c_id): startTime = time.time() count2 =0 itr = 0 if (c_id>0): network = NeuralNetwork(inputNodes = 5, hiddenNodes = 18, outputNodes = 1) #company id >0 for individual prediciton averageError = 1 while (averageError>0.01 and itr<2000): #for i in range(1000): count1 =0 resultBackProp =[] while (count1<295): trainingData = getTrainingData(c_id,count1) resultBackProp.append(network.train(trainingData)) count1 = count1 +1 averageError = sum(resultBackProp)/len(resultBackProp) print ("avgError = ", averageError) #================================================================== # get data for testing testError =[] while (count2<95): testData = getTestData(c_id,count2) testError.append(network.accuracyTest(testData)) count2 = count2 + 1 testErrorAverage = sum(testError)/len(testError) #==================================================================== # get data for tomorrow's prediction predictionData = getPredictionData(c_id) # get prediction result returnPrice = network.test(predictionData) # de-normalize and return predicted stock price final = InitialCalculation() predictedStockPrice = final.denormalizePrice(returnPrice) # create return object, including the accuracy of the testing returnData ={} returnData['price'] = predictedStockPrice #returnData['accuracy'] = accuracy returnData['error'] = testErrorAverage returnData['time'] = time.time() - startTime print(returnData) else: nep_network = NeuralNetwork(inputNodes = 8, hiddenNodes = 20, outputNodes = 1) #company id =0 for nepse prediciton averageError = 1 while (averageError>0.03 ): #for i in range(1000): count1 =0 resultBackProp =[] #print(getTrainingData(c_id,count1)) while (count1<95): trainingData = getTrainingData(c_id,count1) resultBackProp.append(nep_network.trainNepse(trainingData)) count1 = count1 +1 averageError = sum(resultBackProp)/len(resultBackProp) print ("avgError = ", averageError) #================================================================== # get data for testing # considering 50 test data, we nedd 45 loops testError =[] while (count2<10): testData = getTestData(c_id,count2) testError.append(nep_network.accuracyTestNepse(testData)) count2 = count2 + 1 testErrorAverage = sum(testError)/len(testError) #print ("test error =", testError) #print("te average = ", testErrorAverage) #accuracy = (1- testErrorAverage)*100 #==================================================================== # get data for tomorrow's prediction predictionData = getPredictionData(c_id) # get prediction result returnPrice = nep_network.test(predictionData) # de-normalize and return predicted stock price final = InitialCalculation() predictedStockPrice = final.denormalizePriceNepse(returnPrice) # create return object, including the accuracy of the testing returnData ={} returnData['price'] = predictedStockPrice #returnData['accuracy'] = accuracy returnData['error'] = testErrorAverage returnData['time'] = time.time() - startTime print(returnData)
def analyzeSymbol(name): filename = ('uploads/'+name) count = sum(1 for line in open(filename)) con = sql.connect("EBL.db") cur = con.cursor() y =name #cur.execute ("DROP TABLE if exists bankname ") #cur.execute ('''CREATE TABLE bankname (id INTEGER not null PRIMARY KEY, bankname)''') # cur.execute("insert into bankname (bankname) values (?)", (y,)) #cur.execute("insert into bankname (name) values (55)") con.commit() cur.execute ("DROP TABLE if exists {} ".format (name)) cur.execute( '''CREATE TABLE {}(id INTEGER not null PRIMARY KEY, date DATE, ltp INTEGER, percent INTEGER, high INTEGER, low INTEGER, prediction INTEGER)'''.format(y)) #cur.execute("CREATE TABLE fuche ( id INTEGER not null PRIMARY KEY, date, volume, lamo)") with open ('uploads/'+name) as csvfile: readCSV = csv.reader(csvfile, delimiter=',') #print(readCSV) for row in readCSV: cur.execute("insert into {} (date, ltp, percent, high, low) values (?,?, ?, ?, ?)".format(y), ( row[0], row[1], row[2], row[3], row[4])) con.commit() #b=b+1 #INSERT INTO MyTable(MyIntColumn) VALUES(NULL); # cur.execute("insert into {} (date, ltp, percent, high, low) values (NULL, NULL, NULL, NULL, NULL)".format(y)) # con.commit() x = name trainingData = getTrainingData(x) network = NeuralNetwork(inputNodes = 3, hiddenNodes = 2, outputNodes = 1) network.train(trainingData) f****n = [] pussy = [] for a in range (0,count-9): predictionData = getPredictionData(name, a) #returnPrice = loaded_model(network.test(predictionData)) returnPrice = network.test(predictionData) #result = loaded_model.returnPrice predictedStockPrice = denormalizePrice(returnPrice, predictionData[1], predictionData[2]) predictedStockPrice=math.floor(predictedStockPrice) returnData = {} returnData[a] = predictedStockPrice con = sql.connect("EBL.db") cur = con.cursor() pussy += [predictedStockPrice] #pussy[a]=predictedStockPrice cur.execute('update {} set prediction = ? WHERE (id = ?)'.format(y), (pussy[a], a+11,)) #cur.execute('insert into fuche (lamo) values (?) WHERE (id = 5)', (returnData[a],)) Working code con.commit() ''' for x in range (0,9): cur.execute ('SELECT * FROM plcs WHERE id=(SELECT max(id)-? FROM plcs)', (x,)) print(x) result = cur.fetchall() for row in result: #print (result) print (row[0]) ''' #cur.execute ('SELECT COUNT(1) from {}'.format(y) ) # totalrow = cur.fetchone()[0] #con.commit() #cur.execute('UPDATE fuche set lamo = "maya" where id = (?)', (a)) # con.commit() #print ("Return price") #print (returnData['price']) #print ("Prediction") #conn = sqlite3.connect('EBL.db') #curs = conn.cursor() #nm = '2036-12-30' #addr = '230' #city = '776' # curs.execute("INSERT INTO banks (date, value, luck) VALUES (?,?,?)",(nm, addr, returnData[a]) ) #conn.commit() # to insert the predicted value inside the database #print (returnData[a]) # print (b) for bipin in range (0, 9): xdata=[] for r in range (0,10): cur.execute ('SELECT * FROM {} WHERE id=(SELECT max(id)-? FROM {} )'.format(name, name), (r,)) # print(a) result = cur.fetchall() for row in result: #print (result) #print (row[0]) data = row[2] if data==None: data=row[6] xdata.append(data) # print (xdata) fuckoff = getTimeSeriesValues(xdata, 10) f****n = fuckoff[0][0] Predicted = network.test(f****n) predict = float(denormalizePrice(Predicted, f****n[1], f****n[2])) predict=math.floor(predict) # print ("Predicted") # print (predict) cur.execute("SELECT * from {} where id = (SELECT max(id) FROM {})".format(name, name)) result = cur.fetchall() for row in result: x = row[0] print (x) datee=row[1] # print(row[1]+1) # end_date = row[1] + datetime.timedelta(days=10) # print (end_date) date = datetime.strptime(row[1], "%Y-%m-%d") modified_date = date + timedelta(days=1) x = datetime.strftime(modified_date, "%Y-%m-%d") # print(row[1]) cur.execute("insert into {} (date, prediction) values (?, ?)".format(name), (x, predict,)) con.commit() return (returnData[a])