def test_drop(self):
        '''Test node columns drop'''
        node_obj = {
            "id": "abc",
            "type": "IndicatorNode",
            "conf": self.conf,
            "inputs": []
        }
        task = Task(node_obj)
        inN = IndicatorNode(task)
        o = inN.process([self._cudf_data])
        msg = "bad error: df len %d is not right" % (len(o))
        self.assertTrue(len(o) == 162, msg)

        newConf = copy.deepcopy(self.conf)
        newConf['remove_na'] = False
        node_obj = {
            "id": "abc",
            "type": "IndicatorNode",
            "conf": newConf,
            "inputs": []
        }
        task = Task(node_obj)
        inN = IndicatorNode(task)
        o = inN.process([self._cudf_data])
        msg = "bad error: df len %d is not right" % (len(o))
        self.assertTrue(len(o) == 200, msg)
Exemple #2
0
    def test_indicator(self):
        '''Test indicator node'''
        conf = {
            "indicators": [{
                "function": "port_chaikin_oscillator",
                "columns": ["high", "low", "close", "volume"],
                "args": [10, 20]
            }, {
                "function": "port_bollinger_bands",
                "columns": ["close"],
                "args": [10],
                "outputs": ["b1", "b2"]
            }],
            "remove_na":
            True
        }
        node_obj = {
            "id": "abc",
            "type": "IndicatorNode",
            "conf": conf,
            "inputs": {}
        }
        task = Task(node_obj)
        inN = IndicatorNode(task)
        o = inN.process({'stock_in': self._cudf_data})['stock_out']
        err, index_err = error_function_index(o['CH_OS_10_20'], self.gt1)
        msg = "bad error %f\n" % (err, )
        self.assertTrue(np.isclose(err, 0, atol=1e-6), msg)
        msg = "bad error %f\n" % (index_err, )
        self.assertTrue(np.isclose(index_err, 0, atol=1e-6), msg)

        err, index_err = error_function_index(o['BO_BA_b1_10'], self.gt2)
        msg = "bad error %f\n" % (err, )
        self.assertTrue(np.isclose(err, 0, atol=1e-6), msg)
        msg = "bad error %f\n" % (index_err, )
        self.assertTrue(np.isclose(index_err, 0, atol=1e-6), msg)

        err, index_err = error_function_index(o['BO_BA_b2_10'], self.gt3)
        msg = "bad error %f\n" % (err, )
        self.assertTrue(np.isclose(err, 0, atol=1e-6), msg)
        msg = "bad error %f\n" % (index_err, )
        self.assertTrue(np.isclose(index_err, 0, atol=1e-6), msg)
Exemple #3
0
    def test_colums(self):
        '''Test node columns requirments'''
        node_obj = {
            "id": "abc",
            "type": "IndicatorNode",
            "conf": self.conf,
            "inputs": {}
        }
        task = Task(node_obj)
        inN = IndicatorNode(task)
        out_cols = inN.columns_setup()

        col = "indicator"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in inN.required['stock_in'], msg)
        col = "high"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in inN.required['stock_in'], msg)
        col = "low"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in inN.required['stock_in'], msg)
        col = "close"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in inN.required['stock_in'], msg)
        col = "volume"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in inN.required['stock_in'], msg)

        col = "CH_OS_10_20"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in out_cols['stock_out'], msg)
        col = "BO_BA_b1_10"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in out_cols['stock_out'], msg)
        col = "BO_BA_b2_10"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in out_cols['stock_out'], msg)
    def test_colums(self):
        '''Test node columns requirments'''
        node_obj = {
            "id": "abc",
            "type": "IndicatorNode",
            "conf": self.conf,
            "inputs": []
        }
        task = Task(node_obj)
        inN = IndicatorNode(task)

        col = "indicator"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in inN.required, msg)
        col = "high"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in inN.required, msg)
        col = "low"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in inN.required, msg)
        col = "close"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in inN.required, msg)
        col = "volume"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in inN.required, msg)

        col = "CH_OS_10_20"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in inN.addition, msg)
        col = "BO_BA_b1_10"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in inN.addition, msg)
        col = "BO_BA_b2_10"
        msg = "bad error: %s is missing" % (col)
        self.assertTrue(col in inN.addition, msg)
    def test_signal(self):
        '''Test signal computation'''

        newConf = copy.deepcopy(self.conf)
        newConf['remove_na'] = False
        node_obj = {
            "id": "abc",
            "type": "IndicatorNode",
            "conf": newConf,
            "inputs": []
        }
        task = Task(node_obj)
        inN = IndicatorNode(task)
        o = inN.process([self._cudf_data])
        # check chaikin oscillator computation
        r_cudf = gi.chaikin_oscillator(self._cudf_data[:self.half]['high'],
                                       self._cudf_data[:self.half]['low'],
                                       self._cudf_data[:self.half]['close'],
                                       self._cudf_data[:self.half]['volume'],
                                       10, 20)
        computed = o[:self.half]['CH_OS_10_20'].to_array('pandas')
        ref = r_cudf.to_array('pandas')
        err = np.abs(computed[~np.isnan(computed)] - ref[~np.isnan(ref)]).max()
        msg = "bad error %f\n" % (err, )
        self.assertTrue(np.isclose(err, 0, atol=1e-6), msg)

        r_cudf = gi.chaikin_oscillator(self._cudf_data[self.half:]['high'],
                                       self._cudf_data[self.half:]['low'],
                                       self._cudf_data[self.half:]['close'],
                                       self._cudf_data[self.half:]['volume'],
                                       10, 20)
        computed = o[self.half:]['CH_OS_10_20'].to_array('pandas')
        ref = r_cudf.to_array('pandas')
        err = np.abs(computed[~np.isnan(computed)] - ref[~np.isnan(ref)]).max()
        msg = "bad error %f\n" % (err, )
        self.assertTrue(np.isclose(err, 0, atol=1e-6), msg)

        # check bollinger bands computation
        r_cudf = gi.bollinger_bands(self._cudf_data[:self.half]['close'], 10)
        computed = o[:self.half]["BO_BA_b1_10"].to_array('pandas')
        ref = r_cudf.b1.to_array('pandas')
        err = np.abs(computed[~np.isnan(computed)] - ref[~np.isnan(ref)]).max()
        msg = "bad error %f\n" % (err, )
        self.assertTrue(np.isclose(err, 0, atol=1e-6), msg)

        computed = o[:self.half]["BO_BA_b2_10"].to_array('pandas')
        ref = r_cudf.b2.to_array('pandas')
        err = np.abs(computed[~np.isnan(computed)] - ref[~np.isnan(ref)]).max()
        msg = "bad error %f\n" % (err, )
        self.assertTrue(np.isclose(err, 0, atol=1e-6), msg)

        r_cudf = gi.bollinger_bands(self._cudf_data[self.half:]['close'], 10)
        computed = o[self.half:]["BO_BA_b1_10"].to_array('pandas')
        ref = r_cudf.b1.to_array('pandas')
        err = np.abs(computed[~np.isnan(computed)] - ref[~np.isnan(ref)]).max()
        msg = "bad error %f\n" % (err, )
        self.assertTrue(np.isclose(err, 0, atol=1e-6), msg)

        computed = o[self.half:]["BO_BA_b2_10"].to_array('pandas')
        ref = r_cudf.b2.to_array('pandas')
        err = np.abs(computed[~np.isnan(computed)] - ref[~np.isnan(ref)]).max()
        msg = "bad error %f\n" % (err, )
        self.assertTrue(np.isclose(err, 0, atol=1e-6), msg)