Beispiel #1
0
def MFI(df, n, high='High', low='Low', close='Close', volume='Volume'):
    """
    Money Flow Index
    """
    mfi_list = []
    typprice_list = jhta.TYPPRICE(df, high, low, close)
    mf_pos_list = []
    mf_neg_list = []
    i = 0
    while i < len(df[low]):
        mf = typprice_list[i] * df[volume][i]
        if i + 1 < n:
            mfi = float('NaN')
            mf_pos_list.append(float('NaN'))
            mf_neg_list.append(float('NaN'))
        else:
            start = i + 1 - n
            end = i + 1
            if typprice_list[i] > typprice_list[i - 1]:
                mf_pos_list.append(mf)
                mf_neg_list.append(.0)
            else:
                mf_pos_list.append(.0)
                mf_neg_list.append(mf)
            x = sum(mf_pos_list[start:end])
            # FIX ZeroDivisionError: float division by zero:
            y = sum(mf_neg_list[start:end]) or .00000001
            mr = x / y
            mfi = 100 - (100 / (1 + mr))
        mfi_list.append(mfi)
        i += 1
    return mfi_list
Beispiel #2
0
def MFI(df, n, high='High', low='Low', close='Close', volume='Volume'):
    """
    Money Flow Index
    Returns: list of floats = jhta.MFI(df, n, high='High', low='Low', close='Close', volume='Volume')
    Source: https://www.fmlabs.com/reference/default.htm?url=MoneyFlowIndex.htm
    """
    mfi_list = []
    typprice_list = jhta.TYPPRICE(df, high, low, close)
    mf_pos_list = []
    mf_neg_list = []
    for i in range(len(df[low])):
        mf = typprice_list[i] * df[volume][i]
        if i + 1 < n:
            mfi = float('NaN')
            mf_pos_list.append(float('NaN'))
            mf_neg_list.append(float('NaN'))
        else:
            start = i + 1 - n
            end = i + 1
            if typprice_list[i] > typprice_list[i - 1]:
                mf_pos_list.append(mf)
                mf_neg_list.append(.0)
            else:
                mf_pos_list.append(.0)
                mf_neg_list.append(mf)
            x = sum(mf_pos_list[start:end])
            # FIX ZeroDivisionError: float division by zero:
            y = sum(mf_neg_list[start:end]) or .00000001
            mr = x / y
            mfi = 100 - (100 / (1 + mr))
        mfi_list.append(mfi)
    return mfi_list
Beispiel #3
0
def STYPP(df, high='High', low='Low', close='Close'):
    """
    Swing Typical Price - previous Typical Price
    Returns: list of floats = jhta.STYPP(df, high='High', low='Low', close='Close')
    """
    stypp_list = []
    typp_list = jhta.TYPPRICE(df, high, low, close)
    for i in range(len(df[close])):
        if i < 1:
            stypp = float('NaN')
        else:
            stypp = typp_list[i] - typp_list[i - 1]
        stypp_list.append(stypp)
    return stypp_list
Beispiel #4
0
def JH_STYPP(df):
    """
    Swing Typical Price - previous Typical Price
    """
    stypp_list = []
    typp_list = jhta.TYPPRICE(df)
    i = 0
    while i < len(df['Close']):
        if i < 1:
            stypp = float('NaN')
        else:
            stypp = typp_list[i] - typp_list[i - 1]
        stypp_list.append(stypp)
        i += 1
    return stypp_list
Beispiel #5
0
def BBANDW(df, n, f=2, high='High', low='Low', close='Close'):
    """
    Bollinger Band Width
    Returns: list of floats = jhta.BBANDW(df, n, f=2, high='High', low='Low', close='Close')
    Source: https://www.fmlabs.com/reference/default.htm?url=BollingerWidth.htm
    """
    bbandw_list = []
    tp_dict = {'tp': jhta.TYPPRICE(df, high, low, close)}
    stdev_list = jhta.STDEV(tp_dict, n, 'tp')
    for i in range(len(df[close])):
        if i + 1 < n:
            bbandw = float('NaN')
        else:
            bbandw = 2 * f * stdev_list[i]
        bbandw_list.append(bbandw)
    return bbandw_list
Beispiel #6
0
def BBANDW(df, n, f=2, high='High', low='Low', close='Close'):
    """
    Bollinger Band Width
    """
    bbandw_list = []
    tp_dict = {'tp': jhta.TYPPRICE(df, high, low, close)}
    stdev_list = jhta.STDEV(tp_dict, n, 'tp')
    i = 0
    while i < len(df[close]):
        if i + 1 < n:
            bbandw = float('NaN')
        else:
            bbandw = 2 * f * stdev_list[i]
        bbandw_list.append(bbandw)
        i += 1
    return bbandw_list
Beispiel #7
0
def BBANDW(df, n, f=2):
    """
    Bollinger Band Width
    """
    bbandw_list = []
    tp_dict = {'tp': jhta.TYPPRICE(df)}
    stdev_list = jhta.STDEV(tp_dict, n, 'tp')
    i = 0
    while i < len(df['Close']):
        if i + 1 < n:
            bbandw = float('NaN')
        else:
            bbandw = 2 * f * stdev_list[i]
        bbandw_list.append(bbandw)
        i += 1
    return bbandw_list
Beispiel #8
0
def BBANDS(df, n, f=2, high='High', low='Low', close='Close'):
    """
    Bollinger Bands
    Returns: dict of lists of floats = jhta.BBANDS(df, n, f=2, high='High', low='Low', close='Close')
    Source: https://www.fmlabs.com/reference/default.htm?url=Bollinger.htm
    """
    bbands_dict = {'midband': [], 'upperband': [], 'lowerband': []}
    tp_dict = {'tp': jhta.TYPPRICE(df, high, low, close)}
    sma_list = jhta.SMA(tp_dict, n, 'tp')
    stdev_list = jhta.STDEV(tp_dict, n, 'tp')
    for i in range(len(df[close])):
        if i + 1 < n:
            midband = float('NaN')
            upperband = float('NaN')
            lowerband = float('NaN')
        else:
            midband = sma_list[i]
            upperband = midband + f * stdev_list[i]
            lowerband = midband - f * stdev_list[i]
        bbands_dict['midband'].append(midband)
        bbands_dict['upperband'].append(upperband)
        bbands_dict['lowerband'].append(lowerband)
    return bbands_dict
Beispiel #9
0
def BBANDS(df, n, f=2, high='High', low='Low', close='Close'):
    """
    Bollinger Bands
    """
    bbands_dict = {'midband': [], 'upperband': [], 'lowerband': []}
    tp_dict = {'tp': jhta.TYPPRICE(df, high, low, close)}
    sma_list = SMA(tp_dict, n, 'tp')
    stdev_list = jhta.STDEV(tp_dict, n, 'tp')
    i = 0
    while i < len(df[close]):
        if i + 1 < n:
            midband = float('NaN')
            upperband = float('NaN')
            lowerband = float('NaN')
        else:
            midband = sma_list[i]
            upperband = midband + f * stdev_list[i]
            lowerband = midband - f * stdev_list[i]
        bbands_dict['midband'].append(midband)
        bbands_dict['upperband'].append(upperband)
        bbands_dict['lowerband'].append(lowerband)
        i += 1
    return bbands_dict