def test_rsi_same_returns(self): """ RSI indicator should be the same for two price series with the same returns, even if the prices are different. """ rsi = RSI() today = np.datetime64(1, "ns") assets = np.arange(2) out = np.empty((2, ), dtype=float) example_case = np.array([ 46.125, 47.125, 46.4375, 46.9375, 44.9375, 44.25, 44.625, 45.75, 47.8125, 47.5625, 47.0, 44.5625, 46.3125, 47.6875, 46.6875, ]) double = example_case * 2 closes = np.vstack((example_case, double)).T rsi.compute(today, assets, out, closes) np.testing.assert_almost_equal(out[0], out[1], decimal=8)
def test_rsi(self, seed_value, expected): rsi = RSI() today = datetime64(1, 'ns') assets = arange(3) out = empty((3, ), dtype=float) seed(seed_value) # Seed so we get deterministic results. test_data = abs(randn(15, 3)) out = empty((3, ), dtype=float) rsi.compute(today, assets, out, test_data) check_allclose(expected, out)
def test_rsi_all_negative_returns(self): """ RSI indicator should be 0 in the case of 14 days of negative returns. """ rsi = RSI() today = np.datetime64(1, "ns") assets = np.arange(1) out = np.empty((1, ), dtype=float) closes = np.linspace(46, 32, num=15) closes.shape = (15, 1) rsi.compute(today, assets, out, closes) assert out[0] == 0.0
def test_rsi(self, seed_value, expected): rsi = RSI() today = np.datetime64(1, "ns") assets = np.arange(3) out = np.empty((3, ), dtype=float) np.random.seed(seed_value) # Seed so we get deterministic results. test_data = np.abs(np.random.randn(15, 3)) out = np.empty((3, ), dtype=float) rsi.compute(today, assets, out, test_data) check_allclose(expected, out)
def test_rsi(self, seed_value, expected): rsi = RSI() today = datetime64(1, 'ns') assets = arange(3) out = empty((3,), dtype=float) seed(seed_value) # Seed so we get deterministic results. test_data = abs(randn(15, 3)) out = empty((3,), dtype=float) rsi.compute(today, assets, out, test_data) check_allclose(expected, out)
def test_rsi_all_negative_returns(self): """ RSI indicator should be 0 in the case of 14 days of negative returns. """ rsi = RSI() today = np.datetime64(1, 'ns') assets = np.arange(1) out = np.empty((1,), dtype=float) closes = np.linspace(46, 32, num=15) closes.shape = (15, 1) rsi.compute(today, assets, out, closes) self.assertEqual(out[0], 0.0)
def test_rsi_all_positive_returns(self): """ RSI indicator should be 100 in the case of 14 days of positive returns. """ rsi = RSI() today = np.datetime64(1, 'ns') assets = np.arange(1) out = np.empty((1,), dtype=float) closes = np.linspace(46, 60, num=15) closes.shape = (15, 1) rsi.compute(today, assets, out, closes) self.assertEqual(out[0], 100.0)
def test_rsi_same_returns(self): """ RSI indicator should be the same for two price series with the same returns, even if the prices are different. """ rsi = RSI() today = np.datetime64(1, 'ns') assets = np.arange(2) out = np.empty((2,), dtype=float) example_case = np.array([46.125, 47.125, 46.4375, 46.9375, 44.9375, 44.25, 44.625, 45.75, 47.8125, 47.5625, 47., 44.5625, 46.3125, 47.6875, 46.6875]) double = example_case * 2 closes = np.vstack((example_case, double)).T rsi.compute(today, assets, out, closes) self.assertAlmostEqual(out[0], out[1])