import unittest2 from MultinomialNaiveBayes import MultinomialNaiveBayes as mnb my_bayes = mnb("test.db") #If no db, uncomment and run once, then recomment (so nums are not duplicated). my_bayes.train("Abracadabra", [ ["super", "awesome", "mega"], ["a", "a", "a", "a"], ["a", "b", "c"]]) my_bayes.train("Battery", [ ["sad", "sad", "negative"], ["my", "apple", "is", "red"], ["my", "my", "my", "what", "teeth", "you", "awesome"]]) my_bayes.train("Jesus", [ ["sad", "sad", "negative"], ["my", "apple", "is", "red"], ["my", "my", "my", "what", "teeth", "you", "awesome"]]) class test(unittest2.TestCase): def testUniqueWords1(self): cur = my_bayes.conn.cursor() cur.execute("SELECT COUNT(*) FROM Battery") self.failUnless(cur.fetchone()[0], 10) def testUniqueWords2(self): cur = my_bayes.conn.cursor()
import unittest2 from MultinomialNaiveBayes import MultinomialNaiveBayes as mnb my_bayes = mnb("test.db") #If no db, uncomment and run once, then recomment (so nums are not duplicated). my_bayes.train( "Abracadabra", [["super", "awesome", "mega"], ["a", "a", "a", "a"], ["a", "b", "c"]]) my_bayes.train("Battery", [["sad", "sad", "negative"], ["my", "apple", "is", "red"], ["my", "my", "my", "what", "teeth", "you", "awesome"]]) my_bayes.train("Jesus", [["sad", "sad", "negative"], ["my", "apple", "is", "red"], ["my", "my", "my", "what", "teeth", "you", "awesome"]]) class test(unittest2.TestCase): def testUniqueWords1(self): cur = my_bayes.conn.cursor() cur.execute("SELECT COUNT(*) FROM Battery") self.failUnless(cur.fetchone()[0], 10) def testUniqueWords2(self): cur = my_bayes.conn.cursor() cur.execute("SELECT COUNT(*) FROM Abracadabra") self.failUnless(cur.fetchone()[0], 6)
currProfit += (+currPrice - nextPrice) totProfit += currProfit if predic["NEUT"] > predic["POS"] and predic["NEUT"] > predic[ "NEG"]: print(" NOTHING") pass print("profit: " + str(currProfit)) print("total profit: " + str(totProfit)) #3. Update Bayesian classifier. returns = math.log(nextPrice / currPrice) if returns >= MIN_POS: clas = "POS" elif returns <= MAX_NEG: clas = "NEG" elif MAX_NEG < returns < MIN_POS: clas = "NEUT" bayes.train(clas, zip(*prevArts)[3]) except KeyError: print( "KeyError, probably because of beginning or ending of time range" ) bayes = mnb("backtest.db", ["POS", "NEG", "NEUT"]) train( tickerData[ticker], bayes, start, datetime.datetime(2016, 01, 14, 9, 30, 0).replace(tzinfo=EST).astimezone(pytz.utc)) backtest(tickerData[ticker], bayes, start, end)
print(" BUY") currProfit += (-currPrice + nextPrice) totProfit += currProfit elif predic["NEG"] > predic ["POS"] and predic["NEG"] > predic["NEUT"]: print(" SELL") currProfit += (+currPrice - nextPrice) totProfit += currProfit if predic["NEUT"] > predic ["POS"] and predic["NEUT"] > predic["NEG"]: print(" NOTHING") pass print("profit: "+str(currProfit)) print("total profit: "+str(totProfit)) #3. Update Bayesian classifier. returns = math.log(nextPrice / currPrice) if returns >= MIN_POS: clas = "POS" elif returns <= MAX_NEG: clas = "NEG" elif MAX_NEG < returns < MIN_POS: clas = "NEUT" bayes.train(clas, zip(*prevArts)[3]) except KeyError: print("KeyError, probably because of beginning or ending of time range") bayes = mnb("backtest.db", ["POS", "NEG", "NEUT"]) train(tickerData[ticker], bayes, start, datetime.datetime(2016, 01, 14, 9, 30, 0).replace(tzinfo=EST).astimezone(pytz.utc)) backtest(tickerData[ticker], bayes, start, end)