Ejemplo n.º 1
0
def stoc_osc(high, low, close, k_periods, k_slow_periods, d_periods, d_method):
    N = close.__len__();
    per_k = per_d = zeros(N);
    numerator = zeros(N);
    denominator  = zeros(N);
    for index in arange(0,k_periods-1):
        max_high    = max(high[0:index+1]);
        min_low     = min(low[0:index+1]);
        numerator[index]   = abs(close[index] - min_low);
        denominator[index] = abs(max_high - min_low); # abs to handle negative values

    for index in arange(k_periods-1,N):
        max_high    = max(high[index-k_periods+1:index+1]);
        min_low     = min(low[index-k_periods+1:index+1]);
        numerator[index]   = close[index] - min_low;
        denominator[index] = max_high - min_low;

    # %K Slowing periods, sum over last slowing periods (moving average work since we are doing a division)
    num = moving_average.sma(numerator, k_slow_periods);
    den = moving_average.sma(denominator, k_slow_periods);
    for index in arange(0, N):
        if(den[index] == 0):
            per_k[index] = 100;
        else:
            per_k[index] = num[index] / den[index] * 100;


    per_d = moving_average.ma(per_k, d_periods, d_method);

    return [per_k, per_d];
Ejemplo n.º 2
0
def stoc_osc(high, low, close, k_periods, k_slow_periods, d_periods, d_method):
    N = close.__len__()
    per_k = per_d = zeros(N)
    numerator = zeros(N)
    denominator = zeros(N)
    for index in arange(0, k_periods - 1):
        max_high = max(high[0:index + 1])
        min_low = min(low[0:index + 1])
        numerator[index] = abs(close[index] - min_low)
        denominator[index] = abs(max_high - min_low)
        # abs to handle negative values

    for index in arange(k_periods - 1, N):
        max_high = max(high[index - k_periods + 1:index + 1])
        min_low = min(low[index - k_periods + 1:index + 1])
        numerator[index] = close[index] - min_low
        denominator[index] = max_high - min_low

    # %K Slowing periods, sum over last slowing periods (moving average work since we are doing a division)
    num = moving_average.sma(numerator, k_slow_periods)
    den = moving_average.sma(denominator, k_slow_periods)
    for index in arange(0, N):
        if (den[index] == 0):
            per_k[index] = 100
        else:
            per_k[index] = num[index] / den[index] * 100

    per_d = moving_average.ma(per_k, d_periods, d_method)

    return [per_k, per_d]
Ejemplo n.º 3
0
def maCross(data, length):
    ma = moving_average.ma(data.vClose, length)
    N = size(data.vClose);
    # days going back
    M = 25;
    for index in arange(N-M, N):
        # find the last index associated with a value below the moving average
        if(ma[index-1] > data.vClose[index]):
            minIndex = index;
    for index in arange(minIndex, N):
        if(ma[minIndex] < data.vClose[index]):
            maxIndex = index;
            break

    print maxIndex;
    print data.vClose[maxIndex]
Ejemplo n.º 4
0
def maCross(data, length):
    ma = moving_average.ma(data.vClose, length)
    N = size(data.vClose)
    # days going back
    M = 25
    for index in arange(N - M, N):
        # find the last index associated with a value below the moving average
        if (ma[index - 1] > data.vClose[index]):
            minIndex = index
    for index in arange(minIndex, N):
        if (ma[minIndex] < data.vClose[index]):
            maxIndex = index
            break

    print maxIndex
    print data.vClose[maxIndex]