當前位置: 首頁>>代碼示例>>Python>>正文


Python abstract.SMA屬性代碼示例

本文整理匯總了Python中talib.abstract.SMA屬性的典型用法代碼示例。如果您正苦於以下問題:Python abstract.SMA屬性的具體用法?Python abstract.SMA怎麽用?Python abstract.SMA使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在talib.abstract的用法示例。


在下文中一共展示了abstract.SMA屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: resample

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def resample( dataframe, interval, factor):
        # defines the reinforcement logic
        # resampled dataframe to establish if we are in an uptrend, downtrend or sideways trend
        df = dataframe.copy()
        df = df.set_index(DatetimeIndex(df['date']))
        ohlc_dict = {
            'open': 'first',
            'high': 'max',
            'low': 'min',
            'close': 'last'
        }
        df = df.resample(str(int(interval[:-1]) * factor) + 'min', plotoschow=ohlc_dict)

        df['resample_sma'] = ta.SMA(df, timeperiod=25, price='close')
        df = df.drop(columns=['open', 'high', 'low', 'close'])
        df = df.resample(interval[:-1] + 'min')
        df = df.interpolate(method='time')
        df['date'] = df.index
        df.index = range(len(df))
        dataframe = merge(dataframe, df, on='date', how='left')
        return dataframe 
開發者ID:freqtrade,項目名稱:freqtrade-strategies,代碼行數:23,代碼來源:SmoothOperator.py

示例2: resample

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def resample(self, dataframe, interval, factor):
        # defines the reinforcement logic
        # resampled dataframe to establish if we are in an uptrend, downtrend or sideways trend
        df = dataframe.copy()
        df = df.set_index(DatetimeIndex(df['date']))
        ohlc_dict = {
            'open': 'first',
            'high': 'max',
            'low': 'min',
            'close': 'last'
        }
        df = df.resample(str(int(interval[:-1]) * factor) + 'min',
                         label="right").agg(ohlc_dict).dropna(how='any')
        df['resample_sma'] = ta.SMA(df, timeperiod=25, price='close')
        df = df.drop(columns=['open', 'high', 'low', 'close'])
        df = df.resample(interval[:-1] + 'min')
        df = df.interpolate(method='time')
        df['date'] = df.index
        df.index = range(len(df))
        dataframe = merge(dataframe, df, on='date', how='left')
        return dataframe 
開發者ID:freqtrade,項目名稱:freqtrade-strategies,代碼行數:23,代碼來源:ReinforcedQuickie.py

示例3: resample

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def resample(self, dataframe, interval, factor):
        # defines the reinforcement logic
        # resampled dataframe to establish if we are in an uptrend, downtrend or sideways trend
        df = dataframe.copy()
        df = df.set_index(DatetimeIndex(df['date']))
        ohlc_dict = {
            'open': 'first',
            'high': 'max',
            'low': 'min',
            'close': 'last'
        }
        df = df.resample(str(int(interval[:-1]) * factor) + 'min',
                         label="right").agg(ohlc_dict).dropna(how='any')
        df['resample_sma'] = ta.SMA(df, timeperiod=50, price='close')
        df = df.drop(columns=['open', 'high', 'low', 'close'])
        df = df.resample(interval[:-1] + 'min')
        df = df.interpolate(method='time')
        df['date'] = df.index
        df.index = range(len(df))
        dataframe = merge(dataframe, df, on='date', how='left')
        return dataframe 
開發者ID:freqtrade,項目名稱:freqtrade-strategies,代碼行數:23,代碼來源:ReinforcedSmoothScalp.py

示例4: populate_indicators

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd['macd']
        dataframe['macdsignal'] = macd['macdsignal']
        dataframe['macdhist'] = macd['macdhist']

        dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)
        dataframe['sma_200'] = ta.SMA(dataframe, timeperiod=200)
        dataframe['sma_50'] = ta.SMA(dataframe, timeperiod=200)

        dataframe['adx'] = ta.ADX(dataframe)

        # required for graphing
        bollinger = qtpylib.bollinger_bands(dataframe['close'], window=20, stds=2)
        dataframe['bb_lowerband'] = bollinger['lower']
        dataframe['bb_middleband'] = bollinger['mid']
        dataframe['bb_upperband'] = bollinger['upper']

        return dataframe 
開發者ID:freqtrade,項目名稱:freqtrade-strategies,代碼行數:21,代碼來源:Quickie.py

示例5: resample

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def resample(self, dataframe, interval, factor):
        # defines the reinforcement logic
        # resampled dataframe to establish if we are in an uptrend, downtrend or sideways trend
        df = dataframe.copy()
        df = df.set_index(DatetimeIndex(df['date']))
        ohlc_dict = {
            'open': 'first',
            'high': 'max',
            'low': 'min',
            'close': 'last'
        }
        df = df.resample(str(int(interval[:-1]) * factor) + 'min', label="right").agg(ohlc_dict)
        df['resample_sma'] = ta.SMA(df, timeperiod=100, price='close')
        df['resample_medium'] = ta.SMA(df, timeperiod=50, price='close')
        df['resample_short'] = ta.SMA(df, timeperiod=25, price='close')
        df['resample_long'] = ta.SMA(df, timeperiod=200, price='close')
        df = df.drop(columns=['open', 'high', 'low', 'close'])
        df = df.resample(interval[:-1] + 'min')
        df = df.interpolate(method='time')
        df['date'] = df.index
        df.index = range(len(df))
        dataframe = merge(dataframe, df, on='date', how='left')
        return dataframe 
開發者ID:freqtrade,項目名稱:freqtrade-strategies,代碼行數:25,代碼來源:CCIStrategy.py

示例6: populate_indicators

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:

        dataframe['maShort'] = ta.EMA(dataframe, timeperiod=8)
        dataframe['maMedium'] = ta.EMA(dataframe, timeperiod=21)
        ##################################################################################
        # required for graphing
        bollinger = qtpylib.bollinger_bands(dataframe['close'], window=20, stds=2)
        dataframe['bb_lowerband'] = bollinger['lower']
        dataframe['bb_upperband'] = bollinger['upper']
        dataframe['bb_middleband'] = bollinger['mid']

        dataframe_long = resample_to_interval(dataframe, timeframe_to_minutes(self.ticker_interval) * 12)
        dataframe_long['sma'] = ta.SMA(dataframe_long, timeperiod=50, price='close')
        dataframe = resampled_merge(dataframe, dataframe_long, fill_na=True)

        return dataframe 
開發者ID:freqtrade,項目名稱:freqtrade-strategies,代碼行數:18,代碼來源:ReinforcedAverageStrategy.py

示例7: populate_indicators

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe['rsi'] = numpy.nan_to_num(ta.RSI(dataframe, timeperiod=5))
        rsiframe = DataFrame(dataframe['rsi']).rename(columns={'rsi': 'close'})
        dataframe['emarsi'] = numpy.nan_to_num(ta.EMA(rsiframe, timeperiod=5))
        dataframe['adx'] = numpy.nan_to_num(ta.ADX(dataframe))
        dataframe['minusdi'] = numpy.nan_to_num(ta.MINUS_DI(dataframe))
        minusdiframe = DataFrame(dataframe['minusdi']).rename(columns={'minusdi': 'close'})
        dataframe['minusdiema'] = numpy.nan_to_num(ta.EMA(minusdiframe, timeperiod=25))
        dataframe['plusdi'] = numpy.nan_to_num(ta.PLUS_DI(dataframe))
        plusdiframe = DataFrame(dataframe['plusdi']).rename(columns={'plusdi': 'close'})
        dataframe['plusdiema'] = numpy.nan_to_num(ta.EMA(plusdiframe, timeperiod=5))
        dataframe['lowsma'] = numpy.nan_to_num(ta.EMA(dataframe, timeperiod=60))
        dataframe['highsma'] = numpy.nan_to_num(ta.EMA(dataframe, timeperiod=120))
        dataframe['fastsma'] = numpy.nan_to_num(ta.SMA(dataframe, timeperiod=120))
        dataframe['slowsma'] = numpy.nan_to_num(ta.SMA(dataframe, timeperiod=240))
        dataframe['bigup'] = dataframe['fastsma'].gt(dataframe['slowsma']) & ((dataframe['fastsma'] - dataframe['slowsma']) > dataframe['close'] / 300)
        dataframe['bigdown'] = ~dataframe['bigup']
        dataframe['trend'] = dataframe['fastsma'] - dataframe['slowsma']
        dataframe['preparechangetrend'] = dataframe['trend'].gt(dataframe['trend'].shift())
        dataframe['preparechangetrendconfirm'] = dataframe['preparechangetrend'] & dataframe['trend'].shift().gt(dataframe['trend'].shift(2))
        dataframe['continueup'] = dataframe['slowsma'].gt(dataframe['slowsma'].shift()) & dataframe['slowsma'].shift().gt(dataframe['slowsma'].shift(2))
        dataframe['delta'] = dataframe['fastsma'] - dataframe['fastsma'].shift()
        dataframe['slowingdown'] = dataframe['delta'].lt(dataframe['delta'].shift())
        return dataframe 
開發者ID:freqtrade,項目名稱:freqtrade-strategies,代碼行數:26,代碼來源:BinHV27.py

示例8: analyze

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def analyze(self, historical_data, period_count=15):
        """Performs a SMA analysis on the historical data

        Args:
            historical_data (list): A matrix of historical OHCLV data.
            period_count (int, optional): Defaults to 15. The number of data points to consider for
                our simple moving average.

        Returns:
            pandas.DataFrame: A dataframe containing the indicators and hot/cold values.
        """

        dataframe = self.convert_to_dataframe(historical_data)
        sma_values = abstract.SMA(dataframe, period_count).to_frame()
        sma_values.dropna(how='all', inplace=True)
        sma_values.rename(columns={0: 'sma'}, inplace=True)

        return sma_values 
開發者ID:CryptoSignal,項目名稱:crypto-signal,代碼行數:20,代碼來源:sma.py

示例9: ema

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def ema(dataframe, period, field='close'):
    import talib.abstract as ta
    return ta.EMA(dataframe, timeperiod=period, price=field)


# HT_TRENDLINE         Hilbert Transform - Instantaneous Trendline
# KAMA                 Kaufman Adaptive Moving Average
# MA                   Moving average
# MAMA                 MESA Adaptive Moving Average
# MAVP                 Moving average with variable period
# MIDPOINT             MidPoint over period
# MIDPRICE             Midpoint Price over period
# SAR                  Parabolic SAR
# SAREXT               Parabolic SAR - Extended

# SMA                  Simple Moving Average 
開發者ID:freqtrade,項目名稱:technical,代碼行數:18,代碼來源:indicators.py

示例10: osc

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def osc(dataframe, periods=14) -> ndarray:
    """
    1. Calculating DM (i).
        If HIGH (i) > HIGH (i - 1), DM (i) = HIGH (i) - HIGH (i - 1), otherwise DM (i) = 0.
    2. Calculating DMn (i).
        If LOW (i) < LOW (i - 1), DMn (i) = LOW (i - 1) - LOW (i), otherwise DMn (i) = 0.
    3. Calculating value of OSC:
        OSC (i) = SMA (DM, N) / (SMA (DM, N) + SMA (DMn, N)).

    :param dataframe:
    :param periods:
    :return:
    """
    df = dataframe
    df['DM'] = (df['high'] - df['high'].shift()).apply(lambda x: max(x, 0))
    df['DMn'] = (df['low'].shift() - df['low']).apply(lambda x: max(x, 0))
    return Series.rolling_mean(df.DM, periods) / (
            Series.rolling_mean(df.DM, periods) + Series.rolling_mean(df.DMn, periods)) 
開發者ID:freqtrade,項目名稱:technical,代碼行數:20,代碼來源:indicators.py

示例11: populate_indicators

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Adds several different TA indicators to the given DataFrame

        Performance Note: For the best performance be frugal on the number of indicators
        you are using. Let uncomment only the indicator you are using in your strategies
        or your hyperopt configuration, otherwise you will waste your memory and CPU usage.
        """

        # MFI
        dataframe['mfi'] = ta.MFI(dataframe)

        # Stoch fast
        stoch_fast = ta.STOCHF(dataframe)
        dataframe['fastd'] = stoch_fast['fastd']
        dataframe['fastk'] = stoch_fast['fastk']

        # RSI
        dataframe['rsi'] = ta.RSI(dataframe)

        # Inverse Fisher transform on RSI, values [-1.0, 1.0] (https://goo.gl/2JGGoy)
        rsi = 0.1 * (dataframe['rsi'] - 50)
        dataframe['fisher_rsi'] = (numpy.exp(2 * rsi) - 1) / (numpy.exp(2 * rsi) + 1)

        # Bollinger bands
        bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
        dataframe['bb_lowerband'] = bollinger['lower']

        # EMA - Exponential Moving Average
        dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5)
        dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)
        dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50)
        dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)

        # SAR Parabol
        dataframe['sar'] = ta.SAR(dataframe)

        # SMA - Simple Moving Average
        dataframe['sma'] = ta.SMA(dataframe, timeperiod=40)

        return dataframe 
開發者ID:freqtrade,項目名稱:freqtrade-strategies,代碼行數:43,代碼來源:Strategy003.py

示例12: populate_indicators

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        # SMA - Simple Moving Average
        dataframe['fastMA'] = ta.SMA(dataframe, timeperiod=14)
        dataframe['slowMA'] = ta.SMA(dataframe, timeperiod=28)
        return dataframe 
開發者ID:freqtrade,項目名稱:freqtrade-strategies,代碼行數:7,代碼來源:Freqtrade_backtest_validation_freqtrade1.py

示例13: populate_indicators

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe['adx'] = ta.ADX(dataframe, timeperiod=14)
        dataframe['short'] = ta.SMA(dataframe, timeperiod=3)
        dataframe['long'] = ta.SMA(dataframe, timeperiod=6)

        return dataframe 
開發者ID:freqtrade,項目名稱:freqtrade-strategies,代碼行數:8,代碼來源:AdxSmas.py

示例14: algo_action

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def algo_action(self):
        # type: () -> object
        #數據轉換,方便調用ta-lib函數進行技術指標的計算,這裏用SMA指標
        close = np.asarray(self.close_buffer)
        ma = SMA({'close':close}, timeperiod=self.timeperiod)
        delta = round(close[-1] - ma[-1],4)     # 最新數據點,bar的收盤價跟ma的差
        last_ma = round(ma[-1], 4)  #  均線ma的最新值
        momentum = round(self.last_price - last_ma,4)  # 當前最新價格跟ma之間的差,成交價相對ma偏離
        cross = (close[-1] - ma[-1]) * (close[-3] - ma[-3]) < 0  ## 判斷有否交叉
        #print 'close: ', close
        print(('close ma delta: {0}, last_ma: {1}, momentum: {2}'.format(delta, last_ma, momentum)))

        b_p = self.get_position(self.exchange, self.sec_id, OrderSide_Bid)    #查詢策略所持有的多倉
        # 打印持倉信息
        print(('pos long: {0} vwap: {1:.2f}'.format(b_p.volume if b_p else 0.0, b_p.vwap if b_p else 0.0)))
        if cross < 0 and delta > threshold and momentum >= significant_diff:        ## 收盤價上穿均線,且當前價格偏離滿足門限過濾條件,多信號
            # 沒有超出下單次數限製
            if self.trade_count < self.trade_limit:
                # 依次獲取下單的交易量,下單量是配置的一個整數數列,用於倉位管理,可用配置文件中設置
                vol = self.trade_unit[self.trade_count]
                # 如果本次下單量大於0,  發出買入委托交易指令
                if vol > eps:
                    self.open_long(self.exchange, self.sec_id, self.last_price, vol)
                self.trade_count += 1    #增加計數
        elif cross < 0 and delta < -threshold and momentum <= - significant_diff:     ## bar 收盤價下穿ma均線,且偏離滿足信號過濾條件
            # 超出下單次數限製
            if b_p and b_p.available_yesterday > eps:
                self.close_long(self.exchange, self.sec_id, self.last_price, b_p.available_yesterday)
                self.trade_count = 0
        else:       ##  其他情況,忽略不處理
            pass

# 策略啟動入口 
開發者ID:myquant,項目名稱:strategy,代碼行數:35,代碼來源:ma_stock.py

示例15: evaluate_sma

# 需要導入模塊: from talib import abstract [as 別名]
# 或者: from talib.abstract import SMA [as 別名]
def evaluate_sma(self, period, field="close", prefix="sma", impact_buy=1, impact_sell=1):
        """
        evaluates a sma moving average
        :param dataframe:
        :param period:
        :param prefix:
        :return:
        """
        self._weights(impact_buy, impact_sell)
        name = '{}_{}_{}'.format(prefix, field, period)
        dataframe = self.dataframe
        dataframe[name] = ta.SMA(dataframe, timeperiod=period, field=field)

        dataframe.loc[
            (
                (dataframe[name] < dataframe[field])
            ),
            'buy_{}'.format(name)
        ] = (1 * impact_buy)

        dataframe.loc[
            (
                (dataframe[name] > dataframe[field])
            ),
            'sell_{}'.format(name)
        ] = (1 * impact_sell) 
開發者ID:freqtrade,項目名稱:technical,代碼行數:28,代碼來源:consensus.py


注:本文中的talib.abstract.SMA屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。