当前位置: 首页>>代码示例>>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;未经允许,请勿转载。