def bollinger_bands(self, period=20, stds=2, verbose=False): """[The Bolinger Bands is essentially a confidence interval of stds Deviations where the price should be based on the last period periods of prices] Keyword Arguments: period {int} -- [The period over which to look over the prices] (default: {20}) stds {int} -- [The number of standard deviations the bands should take up] (default: {2}) Returns: [float[], float[]] -- [Upper Bolinger Band, Lower Bolinger Band vectors respectively] """ tp = self.typical_prices() ma = Indicators.sma(prices=tp, period=period) std = Indicators.calc_std(prices=tp, period=period) bolu = np.array([ma[i] + stds * std[i] for i in range(len(ma))]) bold = np.array([ma[i] + stds * std[i] for i in range(len(ma))]) return bolu, bold
def test_sma(self): prices = np.arange(10) expected = np.array([0, 0, 0, 0, 0, 2, 3, 4, 5, 6]) assert (Indicators.sma(period=5, prices=prices) == expected).all()
def test_sma(self, period): prices = np.arange(10) print(Indicators.sma(prices, period))
def sma_feature(eq, period): sma_vec = np.array(Indicators.sma(eq.closes, period)) sma_vec = sma_vec.T return [Indicator(sma_vec)]