Exemplo n.º 1
0
	def test_calc_sma(self, patched_rolling_mean):
		# for some reason, the test doesn't pass when I directly pass in
		# self.stock.data['Adj Close'] to the assert_called_with function. It
		# bombs out somewhere deep in Pandas... I'll need to figure that out later
		adj_close = self.stock.data['Adj Close']
		Stock.calc_sma(self.stock, 3)
		patched_rolling_mean.assert_called_with(adj_close, 3)
		assert(isinstance(self.stock.data['sma3'], Series) is not None)
Exemplo n.º 2
0
	def test_NaN(self):
		Stock.calc_sma(self.stock,3)
		# After calculating an average, ensure their are NaNs in the right places
		assert(pd.isnull(self.stock.data.iloc[0]['sma3']))
		assert(not pd.isnull(self.stock.data.iloc[2]['sma3']))
		shape_before_clearing = self.stock.data.shape # tuple of (rows, columns)
		Stock.clear_NaN(self.stock)
		# assert the number of rows decreases by 2
		assert(self.stock.data.shape[0] == shape_before_clearing[0] - 2)
		# assert the number of columns remains the same
		assert(self.stock.data.shape[1] == shape_before_clearing[1])
		# Ensure there are no more NaNs.
		assert(not pd.isnull(self.stock.data.iloc[0]['sma3']))