示例#1
0
    def testAvgGainLoss(self):
        # We divide by 2 because N samples yield N-1 averages.

        # Gain only
        avgGain, avgLoss = rsi.avg_gain_loss([1, 2, 3], 0, 3)
        self.assertTrue(avgGain == 2 / float(2))
        self.assertTrue(avgLoss == 0)

        # Loss only
        avgGain, avgLoss = rsi.avg_gain_loss([3, 2, 1], 0, 3)
        self.assertTrue(avgGain == 0)
        self.assertTrue(avgLoss == 2 / float(2))

        # Gain and Loss equal
        avgGain, avgLoss = rsi.avg_gain_loss([1, 0, 1], 0, 3)
        self.assertTrue(avgGain == 1 / float(2))
        self.assertTrue(avgLoss == 1 / float(2))

        # Gain and Loss different
        avgGain, avgLoss = rsi.avg_gain_loss([1, 3, 2], 0, 3)
        self.assertTrue(avgGain == 2 / float(2))
        self.assertTrue(avgLoss == 1 / float(2))

        # Error
        self.assertEqual(rsi.avg_gain_loss([1, 1.5, 2], 0, 1), None)
        self.assertEqual(rsi.avg_gain_loss([1, 1.5, 2], 1, 2), None)
        with self.assertRaises(IndexError):
            rsi.avg_gain_loss([1, 1.5, 2], 2, 4)
示例#2
0
    def testAvgGainLoss(self):
        # We divide by 2 because N samples yield N-1 averages.

        # Gain only
        avgGain, avgLoss = rsi.avg_gain_loss([1, 2, 3], 0, 3)
        self.assertTrue(avgGain == 2 / float(2))
        self.assertTrue(avgLoss == 0)

        # Loss only
        avgGain, avgLoss = rsi.avg_gain_loss([3, 2, 1], 0, 3)
        self.assertTrue(avgGain == 0)
        self.assertTrue(avgLoss == 2 / float(2))

        # Gain and Loss equal
        avgGain, avgLoss = rsi.avg_gain_loss([1, 0, 1], 0, 3)
        self.assertTrue(avgGain == 1 / float(2))
        self.assertTrue(avgLoss == 1 / float(2))

        # Gain and Loss different
        avgGain, avgLoss = rsi.avg_gain_loss([1, 3, 2], 0, 3)
        self.assertTrue(avgGain == 2 / float(2))
        self.assertTrue(avgLoss == 1 / float(2))

        # Error
        self.assertEqual(rsi.avg_gain_loss([1, 1.5, 2], 0, 1), None)
        self.assertEqual(rsi.avg_gain_loss([1, 1.5, 2], 1, 2), None)
        with self.assertRaises(IndexError):
            rsi.avg_gain_loss([1, 1.5, 2], 2, 4)
	def testAvgGainLoss(self):
		# We divide by 2 because N samples yield N-1 averages.

		# Gain only
		avgGain, avgLoss = rsi.avg_gain_loss([1, 2, 3])
		self.assertTrue(avgGain == 2 / float(2))
		self.assertTrue(avgLoss == 0)

		# Loss only
		avgGain, avgLoss = rsi.avg_gain_loss([3, 2, 1])
		self.assertTrue(avgGain == 0)
		self.assertTrue(avgLoss == 2 / float(2))

		# Gain and Loss equal
		avgGain, avgLoss = rsi.avg_gain_loss([1, 0, 1])
		self.assertTrue(avgGain == 1 / float(2))
		self.assertTrue(avgLoss == 1 / float(2))

		# Gain and Loss different
		avgGain, avgLoss = rsi.avg_gain_loss([1, 3, 2])
		self.assertTrue(avgGain == 2 / float(2))
		self.assertTrue(avgLoss == 1 / float(2))
示例#4
0
    def testAvgGainLoss(self):
        # We divide by 2 because N samples yield N-1 averages.

        # Gain only
        avgGain, avgLoss = rsi.avg_gain_loss([1, 2, 3])
        self.assertTrue(avgGain == 2 / float(2))
        self.assertTrue(avgLoss == 0)

        # Loss only
        avgGain, avgLoss = rsi.avg_gain_loss([3, 2, 1])
        self.assertTrue(avgGain == 0)
        self.assertTrue(avgLoss == 2 / float(2))

        # Gain and Loss equal
        avgGain, avgLoss = rsi.avg_gain_loss([1, 0, 1])
        self.assertTrue(avgGain == 1 / float(2))
        self.assertTrue(avgLoss == 1 / float(2))

        # Gain and Loss different
        avgGain, avgLoss = rsi.avg_gain_loss([1, 3, 2])
        self.assertTrue(avgGain == 2 / float(2))
        self.assertTrue(avgLoss == 1 / float(2))