Ejemplo n.º 1
0
def test_binary_class():
    stock_d = testdata()
    ti = TechnicalIndicators(stock_d)
    ti.calc_ret_index()

    ret_index = ti.stock['ret_index']
    f = Features()
    train_X, train_y = f.binary_class(ret_index, range=90)

    expected = [
        1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0,
        1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0,
        0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0,
        1, 1, 0
    ]
    for r, e in zip(train_y, expected):
        eq_(r, e)

    r = round(train_X[-1][-1], 5)
    expected = 1.35486
    eq_(r, expected)

    r = round(train_X[0][0], 5)
    expected = 1.19213
    eq_(r, expected)

    expected = 14
    r = len(train_X[0])
    eq_(r, expected)

    expected = 75
    r = len(train_X)
    eq_(r, expected)

    train_X, train_y = f.binary_class(ret_index)

    expected = 0
    eq_(train_y[0], expected)

    expected = 1
    eq_(len(train_y), expected)

    r = round(train_X[0][0], 5)
    expected = 1.30311
    eq_(r, expected)

    expected = 14
    r = len(train_X[0])
    eq_(r, expected)

    expected = 1
    r = len(train_X)
    eq_(r, expected)
Ejemplo n.º 2
0
def test_binary_class():
    stock_d = testdata()
    ti = TechnicalIndicators(stock_d)
    ti.calc_ret_index()

    ret_index = ti.stock['ret_index']
    f = Features()
    train_X, train_y = f.binary_class(ret_index, range=90)

    expected = [1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1,
                0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1,
                0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1,
                1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0,
                1, 1, 0]
    for r, e in zip(train_y, expected):
        eq_(r, e)

    r = round(train_X[-1][-1], 5)
    expected = 1.35486
    eq_(r, expected)

    r = round(train_X[0][0], 5)
    expected = 1.19213
    eq_(r, expected)

    expected = 14
    r = len(train_X[0])
    eq_(r, expected)

    expected = 75
    r = len(train_X)
    eq_(r, expected)

    train_X, train_y = f.binary_class(ret_index)

    expected = 0
    eq_(train_y[0], expected)

    expected = 1
    eq_(len(train_y), expected)

    r = round(train_X[0][0], 5)
    expected = 1.30311
    eq_(r, expected)

    expected = 14
    r = len(train_X[0])
    eq_(r, expected)

    expected = 1
    r = len(train_X)
    eq_(r, expected)
Ejemplo n.º 3
0
    def train(self, arr, remember=True, classifier="Decision Tree"):
        f = Features()

        if os.path.exists(self.filename):
            self.clf = self._load_clf()
            train_X, train_y = f.binary_class(arr)
        else:
            self.clf = self.new_clf(classifier=classifier)
            train_X, train_y = f.binary_class(arr, len(arr))

        self.clf.fit(train_X, train_y)
        if remember:
            self._save_clf()

        return train_X, train_y
Ejemplo n.º 4
0
    def train(self, arr, remember=True,
              classifier="Decision Tree"):
        f = Features()

        if os.path.exists(self.filename):
            self.clf = self._load_clf()
            train_X, train_y = f.binary_class(arr)
        else:
            self.clf = self.new_clf(classifier=classifier)
            train_X, train_y = f.binary_class(arr, len(arr))

        self.clf.fit(train_X, train_y)
        if remember:
            self._save_clf()

        return train_X, train_y