Example #1
0
 def test_buy_sell_classifier(self):
     classifier = cl.BuySellClassifier()
     res = classifier.classify(self.tf)
     rets = cl.n_day_returns(5, self.tf)
     for x in (np.random.rand(10) * len(rets)).round():
         i = int(x)
         self.assertTrue(np.equal(res[i], cl._buy_sell_threshold(rets[i])).all())
     self.assertTrue(all(map(lambda x: x == None, res[-5:])))
     self.assertFalse(res[-6] == None)
     self.assertTrue(res.index[0], self.tf.feature_data.index[0])
     self.assertTrue(res.index[-1], self.tf.feature_data.index[-1])
Example #2
0
 def test_buy_sell_threshold_classify(self):
     self.assertEqual(cl._buy_sell_threshold(0.011, threshold=0.01), [1, 0, 0])
     self.assertEqual(cl._buy_sell_threshold(0.01, threshold=0.01), [0, 1, 0])
     self.assertEqual(cl._buy_sell_threshold(0.0, threshold=0.01), [0, 1, 0])
     self.assertEqual(cl._buy_sell_threshold(-0.01, threshold=0.01), [0, 1, 0])
     self.assertEqual(cl._buy_sell_threshold(-0.011, threshold=0.01), [0, 0, 1])
     self.assertEqual(cl._buy_sell_threshold(float('NaN'), threshold=0.01), None)