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


Python pandas.rolling_max方法代碼示例

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


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

示例1: getWilliam

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import rolling_max [as 別名]
def getWilliam(close, high, low):
    '''
    計算威廉指數
    :param DataFrame close: 收盤價
    :param DataFrame high: 當日最高價
    :param DataFrame low: 當日最低價
    :return: DataFrame w: 威廉指數
    '''
    # 取14日來算
    n = 14
    high = pd.rolling_max(high, n)
    high.index = range(high.shape[0])
    low = pd.rolling_min(low, n)
    low.index = range(low.shape[0])
    w = 100 - 100 * (close - low) / (high - low)
    w.replace([np.nan, np.inf, -np.inf], 0, inplace=True)
    return w 
開發者ID:icezerowjj,項目名稱:MultipleFactorRiskModel,代碼行數:19,代碼來源:own_tech.py

示例2: drawdown

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import rolling_max [as 別名]
def drawdown(x):
    ### Returns a ts of drawdowns for a time series x
    
    ## rolling max with infinite window
    maxx=pd.rolling_max(x, 99999999, min_periods=1)
    return (x - maxx)/maxx 
開發者ID:robcarver17,項目名稱:systematictradingexamples,代碼行數:8,代碼來源:common.py

示例3: results

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import rolling_max [as 別名]
def results(self, data_frame):
        try:
            data_frame[self.value] = pd.rolling_max(data_frame[self.data], self.period)
        except KeyError:
            data_frame[self.value] = np.nan 
開發者ID:edouardpoitras,項目名稱:NowTrade,代碼行數:7,代碼來源:technical_indicator.py

示例4: ichimoku

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import rolling_max [as 別名]
def ichimoku(price_objs):
    """
    computes the ichimoku cloud for price_objs
    """

    dates = [pd.to_datetime(str(obj.created_on)) for obj in price_objs]
    prices = [obj.price for obj in price_objs]

    d = {'date': dates,
         'price': prices}
    _prices = pd.DataFrame(d)

    # Tenkan-sen (Conversion Line): (9-period high + 9-period low)/2))
    period9_high = pd.rolling_max(_prices['price'], window=9)
    period9_low = pd.rolling_min(_prices['price'], window=9)
    tenkan_sen = (period9_high + period9_low) / 2

    # Kijun-sen (Base Line): (26-period high + 26-period low)/2))
    period26_high = pd.rolling_max(_prices['price'], window=26)
    period26_low = pd.rolling_min(_prices['price'], window=26)
    kijun_sen = (period26_high + period26_low) / 2

    # Senkou Span A (Leading Span A): (Conversion Line + Base Line)/2))
    senkou_span_a = ((tenkan_sen + kijun_sen) / 2).shift(26)

    # Senkou Span B (Leading Span B): (52-period high + 52-period low)/2))
    period52_high = pd.rolling_max(_prices['price'], window=52)
    period52_low = pd.rolling_min(_prices['price'], window=52)
    senkou_span_b = ((period52_high + period52_low) / 2).shift(26)

    # The most current closing price plotted 22 time periods behind (optional)
    chikou_span = _prices.shift(-22)  # 22 according to investopedia

    return {
        'tenkan_sen': tenkan_sen,
        'kijun_sen': kijun_sen,
        'senkou_span_a': senkou_span_a,
        'senkou_span_b': senkou_span_b,
        'chikou_span': chikou_span,
    } 
開發者ID:owocki,項目名稱:pytrader,代碼行數:42,代碼來源:technical_indicators.py

示例5: fast_stochastic

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import rolling_max [as 別名]
def fast_stochastic(lowp, highp, closep, period=14, smoothing=3):
    """ calculate slow stochastic
    Fast stochastic calculation
    %K = (Current Close - Lowest Low)/(Highest High - Lowest Low) * 100
    %D = 3-day SMA of %K
    """
    low_min = pd.rolling_min(lowp, period)
    high_max = pd.rolling_max(highp, period)
    k_fast = 100 * (closep - low_min)/(high_max - low_min)
    k_fast = k_fast.dropna()
    d_fast = simple_moving_average(k_fast, smoothing)
    return k_fast, d_fast 
開發者ID:Roibal,項目名稱:Cryptocurrency-Trading-Bots-Python-Beginner-Advance,代碼行數:14,代碼來源:Stochastic_Crypto_Pandas_Stock.py

示例6: getKDJ

# 需要導入模塊: import pandas [as 別名]
# 或者: from pandas import rolling_max [as 別名]
def getKDJ(close, high, low):
    '''
    calculate KDJ value
    :param DataFrame close:close price
    :param DataFrame high:highest price of a day
    :param DataFrame low: lowest price of a day
    :return: [DataFrame,DataFrame,DataFrame,DataFrame] [RSV, K, D, KDJ]:KDJ value and some subproducts
    '''
    # interval over which KDJ is calculated
    kdj_interval = 9
    N = 3
    # calculate RSV
    # get the close value to be used
    close = pd.DataFrame(close.iloc[(kdj_interval - 1):, :].values)
    # calculate maximum in (kdj_interval) days in high value
    high_max_in_interval = pd.rolling_max(high, kdj_interval)
    # rolling_sum function will set the first (kdj_interval-1) days as np.nan,drop them
    high_max_in_interval.dropna(inplace=True)
    # set index with 0,1,2...,otherwise it will be kdj_interval,kdj_interval+1,...(may not be explicit but fuck the index)
    high_max_in_interval.index = range(high_max_in_interval.shape[0])
    low_min_in_interval = pd.rolling_min(low, kdj_interval)
    low_min_in_interval.dropna(inplace=True)
    low_min_in_interval.index = range(low_min_in_interval.shape[0])
    # calculate RSV
    RSV = 100 * (close - low_min_in_interval) / (high_max_in_interval - low_min_in_interval)
    # replace np.nan and np.inf in RSV because there might be 0 in the denominator of the last formula
    RSV.replace([np.nan, np.inf,-np.inf], 0, inplace=True)
    # get matrix shape
    [row, col] = RSV.shape
    # calculate K
    # assuming N equals n in the formula
    # initialize both N and K with 50
    K = pd.DataFrame(np.zeros([row, col]))
    D = pd.DataFrame(np.zeros([row, col]))
    K.iloc[0, :] = 50 * np.ones([1, col])
    D.iloc[0, :] = 50 * np.ones([1, col])
    # calculate K and D iteratively
    for i in range(1, row):
        K.iloc[i, :] = (RSV.iloc[i, :] + K.iloc[(i - 1), :]) / N
        D.iloc[i, :] = (K.iloc[i, :] - D.iloc[(i - 1), :]) / N
    KDJ = 3 * K - 2 * D
    return [RSV, K, D, KDJ] 
開發者ID:icezerowjj,項目名稱:MultipleFactorRiskModel,代碼行數:44,代碼來源:own_tech.py


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