예제 #1
0
    def testRateOfReturnNoDivisor(self):
        """Test the rate of return function without a divisor"""
        data = np.arange(1, 10)
        ror = rateOfReturn(data)
        exp_ror = [1, 1 / 2.0, 1 / 3.0, 1 / 4.0, 1 / 5.0, 1 / 6.0, 1 / 7.0, 1 / 8.0]

        assert np.shape(ror) == np.shape(exp_ror), "Rate of return has incorrect size"
        assert (ror == exp_ror).all(), "Rate of return calculated incorrectly"

        data = np.random.rand(1000)
        ror = rateOfReturn(data)
        exp_ror = np.diff(data) / data[0:-1]

        assert np.shape(ror) == np.shape(exp_ror), "Rate of return has incorrect size"
        assert (ror == exp_ror).all(), "Rate of return calculated incorrectly"
예제 #2
0
 def testNormalizeDataBasic(self):
     """Test the normalize data function with basic inputs"""
     data = np.random.rand(3, 100)
     ndata = normalizeData(data)
     assert np.shape(ndata) == (3, 99), "Normalize Data gave incorrect shape"
     for nd, d in izip(ndata, data):
         assert close_enough(nd, rateOfReturn(d)), "Normalize Data did not use Rate of Return function correctly"
예제 #3
0
 def testNormalizeDataWithSelectedDivisor(self):
     """Test the normalize data function with a selected RateOfReturn divisor row"""
     data = np.random.rand(3, 100)
     data[2] += 100
     ndata = normalizeData(data, ror_divisor_row=2)
     assert np.shape(ndata) == (3, 99), "Normalize Data gave incorrect shape"
     for nd, d in izip(ndata, data):
         assert close_enough(
             nd, rateOfReturn(d, data[2][0:-1])
         ), "Normalize Data did not use Rate of Return with divisor function correctly"
예제 #4
0
 def testNormalizeDataWithVolume(self):
     """Test the normalize data function with a selected RateOfReturn divisor row"""
     data = np.random.rand(3, 100)
     data = np.array(data.tolist() + np.random.randint(100, 10000, (1, 100)).tolist())
     ndata = normalizeData(data, volume_row=3)
     assert np.shape(ndata) == (4, 99), "Normalize Data gave incorrect shape"
     for nd, d in izip(ndata[0:3], data[0:3]):
         assert close_enough(nd, rateOfReturn(d)), "Normalize Data did not use Rate of Return correctly"
     assert close_enough(
         ndata[3], normalizeVolume(data[3][1:])
     ), "Normalize Data did not use Normalize Volume correctly"
예제 #5
0
    def testRateOfReturnWithDivisor(self):
        """Test the rate of return function with a specified divisor"""
        data = [1, 2, 2.5, 2]
        div = [2, 2, 2]
        bad_div = [2, 2, 2, 2]
        ror = rateOfReturn(data, divisor=div)
        assert np.shape(ror) == (3,), "Rate of return has incorrect size"
        assert (np.array(ror) == np.array([0.5, 0.25, -0.25])).all(), "Rate of return is incorrect"

        try:
            ror = rateOfReturn(data, divisor=bad_div)
            assert False, "Rate of return did not assert error for incorrect sized divisor"
        except AssertionError:
            pass

        data = np.random.rand(100)
        div = np.random.rand(99) + 100
        ror = rateOfReturn(data, div)
        assert np.shape(ror) == (99,), "Rate of return has incorrect size"
        assert close_enough(ror, np.ones((99,))), "Rate of return is wrong!"
예제 #6
0
    def testMakeNormalizeDataGenerator(self):
        """Test the normalize data generator function"""
        data = np.random.rand(3, 100)
        simple_norm = DataNormalizer()
        ndata = simple_norm(data)
        assert np.shape(ndata) == (3, 99), "Normalize Data gave incorrect shape"
        for nd, d in izip(ndata, data):
            assert close_enough(nd, rateOfReturn(d)), "Normalize Data did not use Rate of Return function correctly"

        data = np.array(data.tolist() + np.random.randint(100, 10000, (1, 100)).tolist())
        complex_norm = DataNormalizer(1, 3)
        ndata = complex_norm(data)
        assert np.shape(ndata) == (4, 99), "Normalize Data gave incorrect shape"
        for nd, d in izip(ndata[0:3], data[0:3]):
            assert close_enough(
                nd, rateOfReturn(d, data[1][0:-1])
            ), "Normalize Data did not use Rate of Return correctly"
        assert close_enough(
            ndata[3], normalizeVolume(data[3][1:])
        ), "Normalize Data did not use Normalize Volume correctly"