コード例 #1
0
class BollingerBands(object):
    """
    Bollinger Bands
    """

    def __init__(self):
        self.logger = structlog.get_logger()
        self.utils = Utils()
        self.sma = MovingAverages()

    '''
    Retrieves the upper and lower bollinger bands for the given parameters:

    :param historical_data: A list of historical data points for a coin pair
    :param period: The period of the moving average to be used in bollinger calculation (defaults to 21)
    :param k: The number of standard deviations away from the 'period'-length moving average
              to place the upper and lower band (defaults to 2)

    :returns A 2-element tuple containing the upper and lower band, respectively.
    '''

    def get_bollinger_bands(self, historical_data, period=21, k=2):
        sma = self.sma.calculate_sma(period, historical_data)
        closing_prices = self.utils.get_closing_prices(historical_data)
        std_dev = np.std(closing_prices[-period:])

        return sma + k * std_dev, sma - k * std_dev
コード例 #2
0
 def analyze_moving_averages(self, coin_pair, period_count=20, time_unit='5m'):
     ma_analyzer = MovingAverages()
     historical_data = self.exchange_aggregator.get_historical_data(
         coin_pair=coin_pair,
         period_count=period_count,
         time_unit=time_unit
     )
     sma_value = ma_analyzer.calculate_sma(period_count, historical_data)
     ema_value = ma_analyzer.calculate_ema(period_count, historical_data)
     return sma_value, ema_value
コード例 #3
0
ファイル: analysis.py プロジェクト: gilby125/crypto-signal
 def analyze_moving_averages(self, market_pair, period_count=20, time_unit='5m'):
     ma_analyzer = MovingAverages()
     historical_data = self.exchange_interface.get_historical_data(
         market_pair=market_pair,
         period_count=period_count,
         time_unit=time_unit
     )
     sma_value = ma_analyzer.calculate_sma(period_count, historical_data)
     ema_value = ma_analyzer.calculate_ema(period_count, historical_data)
     return sma_value, ema_value