Пример #1
0
def get_MACD (time_series, Ls = 12, Ll = 26, Lsmoth = 9, alpha = -1):
    """ 
    Moving Average Convergence/Divergence (MACD) indicates the correlation between 
    two price moving averages.
    
    Usually 26-period and 12-period Exponential Moving Average (EMA).
    In order to clearly show buy/sell opportunities, 
    a so-called signal line (9-period indicators` moving average) is plotted on the MACD chart.
    The MACD proves most effective in wide-swinging trading markets. 
    There are three popular ways to use the Moving Average Convergence/Divergence: 
    crossovers, overbought/oversold conditions, and divergences.

    The MACD is calculated by subtracting the value of a 26-period exponential 
    moving average from a 12-period exponential moving average. 
    A 9-period dotted simple moving average of the MACD (the signal line) 
    is then plotted on top of the MACD.
    """
    
    eMlong = indl.get_EMA(time_series, Ll, alpha)
    eMshort = indl.get_EMA(time_series, Ls, alpha)
    
    MACD = indl.get_SMA(eMshort - eMlong, Lsmoth)
    
    return eMlong, eMshort, MACD
Пример #2
0
                       top=.95,
                       wspace=.20,
                       hspace=0)

    gl.savefig(folder_images + 'lagsMAs.png', dpi=100, sizeInches=[16, 9])

if (viewing_SEW_windows):
    # Some basic indicators.
    price = timeData.get_timeSeries(["Close"])
    dates = timeData.get_dates()

    nMA1 = 10
    nMA2 = 20

    SMAw = indl.get_SMA(bMA.delta(nMA1), nMA1, cval=1)
    EMAw = indl.get_EMA(bMA.delta(nMA1), nMA1, cval=1)
    WMAw = indl.get_WMA(bMA.delta(nMA1), nMA1, cval=1)

    SMAw2 = indl.get_SMA(bMA.delta(nMA2), nMA2, cval=1)
    EMAw2 = indl.get_EMA(bMA.delta(nMA2), nMA2, cval=1)
    WMAw2 = indl.get_WMA(bMA.delta(nMA2), nMA2, cval=1)

    SMA = timeData.SMA(n=nMA1)
    """ 1st GRAPH """
    ############## Average and Window ################
    ax1 = gl.subplot2grid((1, 5), (0, 0), rowspan=1, colspan=3)
    title = "Price and SMA. " + str(
        symbols[0]) + "(" + ul5.period_dic[timeData.period] + ")"

    gl.plot(dates, [price, SMA],
            AxesStyle="Normal",
Пример #3
0
    gl.savefig(folder_images +'OscillatorsMOM.png', 
               dpi = 100, sizeInches = [2*8, 2*2])
               
               
    
    price = timeData.get_timeSeries(["Close"]);
    dates = timeData.get_dates()
    df = timeData.get_timeData()
    
    # Momentum and Rate of convergence obtained from the real price.
    nMOMs = [10, 20, 30]
    MOM1 = timeData.MOM(n = 1)
    
    
    EMAMOMs = [indl.get_EMA(MOM1, nMOMi) for nMOMi in nMOMs]
    
    # Normalize ROC to MOM
    gl.set_subplots(2,1)
    
    gl.plot(dates, price , nf = 1,
            labels = ["Smoothed MOM(1)","","Price"],
            legend = ["Price", " Momentum", "ROC"])
            
    legend = ["EMA(MOM(1),%i)"%x for x in nMOMs]
    gl.plot(dates, EMAMOMs , nf = 1, na = 0,
            legend = legend)
            
    # The nect plot is just so that the vision starts in the first date
    gl.plot(dates, np.zeros((dates.size,1)) , nf = 0, na = 0)
 
Пример #4
0
def get_EMA(self, L, alpha=-1):
    timeSeries = self.get_timeSeries()
    EMA = indl.get_EMA(timeSeries, L, alpha)
    return EMA
Пример #5
0
    diffws = [diffw1,diffw2,diffw3]
    sel_diff = 0
    
    diff_final = diffws[sel_diff]

    SMAw  = indl.get_SMA(delta, nHMA, cval = 1)
    dSMAw = bMA.convolve(SMAw, diff_final)
#    SMASMA =  bMA.diff(SMASMA, cval = np.nan)
#    SMASMA  = indl.get_SMA(diffw1, nHMA, cval = 1)
    
    WMAw  = indl.get_WMA(delta, nHMA, cval = 1)
    dWMAw = bMA.convolve(WMAw, diff_final)
#    WMAWMA  = bMA.diff(WMAWMA, cval = np.nan)
#    WMAWMA  = indl.get_WMA(diffw1, nHMA, cval = 1)
    
    EMAw  = indl.get_EMA(delta, nHMA, cval = 1)
    dEMAw = bMA.convolve(EMAw, diff_final)
    
#    EMAEMA  = bMA.diff(EMAEMA, cval = np.nan)
#    EMAEMA  = indl.get_EMA(diffw1, nHMA, cval = 1)
    
    
    ## Plotting just the 3 windows
    gl.set_subplots(1,3)
    marker = [".",20,"r"]
    lw = 4
    # Plotting the 3 of them at the same time.

    ax1 = gl.stem([], diffw1, nf = 1, lw = lw,
            labels = ["MOMw(%i)"%ndiff1,"lag","Value"],
            xlimPad = [0.1,0.3], ylimPad = [0.1,0.1],
                       wspace=.20,
                       hspace=0)

    gl.savefig(folder_images + 'OscillatorsMOM.png',
               dpi=100,
               sizeInches=[2 * 8, 2 * 2])

    price = timeData.get_timeSeries(["Close"])
    dates = timeData.get_dates()
    df = timeData.get_timeData()

    # Momentum and Rate of convergence obtained from the real price.
    nMOMs = [10, 20, 30]
    MOM1 = timeData.MOM(n=1)

    EMAMOMs = [indl.get_EMA(MOM1, nMOMi) for nMOMi in nMOMs]

    # Normalize ROC to MOM
    gl.set_subplots(2, 1)

    gl.plot(dates,
            price,
            nf=1,
            labels=["Smoothed MOM(1)", "", "Price"],
            legend=["Price", " Momentum", "ROC"])

    legend = ["EMA(MOM(1),%i)" % x for x in nMOMs]
    gl.plot(dates, EMAMOMs, nf=1, na=0, legend=legend)

    # The nect plot is just so that the vision starts in the first date
    gl.plot(dates, np.zeros((dates.size, 1)), nf=0, na=0)
def get_EMA(self, L, alpha=-1):
    if (self.timeSeries == []):  # Check existence of timeSeries
        self.get_timeSeries()
    EMA = indl.get_EMA(self.timeSeries, L, alpha)

    return EMA
Пример #8
0
def get_EMA(self, L, alpha = -1):
    timeSeries = self.get_timeSeries()
    EMA = indl.get_EMA(timeSeries, L, alpha)
    return EMA
Пример #9
0
    gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.20, hspace=0)

    gl.savefig(folder_images +'lagsMAs.png', 
               dpi = 100, sizeInches = [16, 9])
               
if (viewing_SEW_windows):
    # Some basic indicators.
    price = timeData.get_timeSeries(["Close"]);
    dates = timeData.get_dates()

    nMA1 = 10
    nMA2 = 20

    SMAw = indl.get_SMA(bMA.delta(nMA1), nMA1, cval = 1)
    EMAw = indl.get_EMA(bMA.delta(nMA1), nMA1, cval = 1)
    WMAw = indl.get_WMA(bMA.delta(nMA1), nMA1, cval = 1)

    SMAw2 = indl.get_SMA(bMA.delta(nMA2), nMA2, cval = 1)
    EMAw2 = indl.get_EMA(bMA.delta(nMA2), nMA2, cval = 1)
    WMAw2 = indl.get_WMA(bMA.delta(nMA2), nMA2, cval = 1)

    SMA = timeData.SMA(n = nMA1)
    
    """ 1st GRAPH """
    ############## Average and Window ################
    ax1 = gl.subplot2grid((1,5), (0,0), rowspan=1, colspan=3)
    title = "Price and SMA. " + str(symbols[0]) + "(" + ul.period_dic[timeData.period]+ ")"

    gl.plot(dates, [price, SMA] ,AxesStyle = "Normal",
            labels = [title,"",r"Price ($\$$)"],