Beispiel #1
0
def update(option):
    global flag; global stock_list; global len_stock_list; global num_days
    if option!="Clustering":
        opt2.configure(state=NORMAL)
        num.configure(state=DISABLED)
        length.configure(state=NORMAL)
        if flag:
            stock_list, len_stock_list, num_days = LoadTimeseries.simple_scan(data_path)
            opt2['menu'].delete(0, 'end')
            for choice in stock_list:
                opt2['menu'].add_command(label=choice, command=tk._setit(stock, choice))
            label42.config(text='Length of timeseries (1 - '+str(num_days)+'):')
            
            flag = False
        
        label4.config(text='Number of timeseries:')
        if option == "Prediction":
            label4.config(text='Number of timeseries:')
            steps.configure(state=NORMAL)
        else:
            steps.configure(state=DISABLED)
 
    else:
        opt2.configure(state=DISABLED)
        num.configure(state=NORMAL)
        length.configure(state=NORMAL)
        
        stock_list, len_stock_list, num_days = LoadTimeseries.simple_scan(data_path)
        label4.config(text='Number of timeseries (1 - '+str(len_stock_list)+'):')
        label42.config(text='Length of timeseries (1 - '+str(num_days)+'):')
        steps.configure(state=DISABLED)
Beispiel #2
0
def update(option):
    global flag
    global stock_list
    global len_stock_list
    global num_days
    if option != "Clustering":
        opt2.configure(state=NORMAL)
        num.configure(state=DISABLED)
        length.configure(state=NORMAL)
        if flag:
            stock_list, len_stock_list, num_days = LoadTimeseries.simple_scan(
                data_path)
            opt2['menu'].delete(0, 'end')
            for choice in stock_list:
                opt2['menu'].add_command(label=choice,
                                         command=tk._setit(stock, choice))
            label42.config(text='Length of timeseries (1 - ' + str(num_days) +
                           '):')

            flag = False

        label4.config(text='Number of timeseries:')
        if option == "Prediction":
            label4.config(text='Number of timeseries:')
            steps.configure(state=NORMAL)
        else:
            steps.configure(state=DISABLED)

    else:
        opt2.configure(state=DISABLED)
        num.configure(state=NORMAL)
        length.configure(state=NORMAL)

        stock_list, len_stock_list, num_days = LoadTimeseries.simple_scan(
            data_path)
        label4.config(text='Number of timeseries (1 - ' + str(len_stock_list) +
                      '):')
        label42.config(text='Length of timeseries (1 - ' + str(num_days) +
                       '):')
        steps.configure(state=DISABLED)
Beispiel #3
0
def _Go():
    global flag
    global num_days
    global length
    global steps
    global num_days
    global f
    global sa
    global plots
    global curr_pos

    sel_task = task.get()

    if (data_path == None):
        display_error(1)
    elif (sel_task == 'None'):
        display_error(2)
    elif (sel_task == 'Summarize'):
        curr_pos = 0
        plots = []
        name = str(stock.get())
        if name != "None":
            lot = length.get()
            if lot == "":
                display_error(3)
            else:
                lot = int(lot)
                if type(lot) != int:
                    display_error(4)
                elif lot <= 0:
                    display_error(5)

            if lot != "" and type(int(lot)) == int and int(lot) > 0:
                data = LoadTimeseries.read_p_timeseries(data_path, name, lot)
                original, summarized = Summarize.summarize(data)
                plt.clf()

                #yearsFmt = mdates.DateFormatter('%b %Y')
                f = plt.figure(figsize=(6, 6), dpi=100, facecolor='white')
                plt.subplot(411)
                plt.title("Initial Timeserie")
                original[name].ix[original[name].index].plot(style='b')

                ##                print(summarized[name]["extremas-x"])
                ##                tps = []
                ##                tps_ind = []
                ##                for i in range(len(original[name])):
                ##                    if i in summarized[name]["extremas-x"]:
                ##                        tps.append(original[name][i])
                ##                        tps_ind.append(original[name].index[i])
                ##                print(tps_ind)
                ##                print(tps)
                ##                f = Series(tps, index=tps_ind).ix[tps_ind].plot(style='r',marker='o', linestyle="", markersize=7)

                plt.subplot(412)
                plt.title("Overall Timeserie Trend")
                plt.plot(summarized[name]["trend"]["x"],
                         summarized[name]["trend"]["r"], 'g')
                plt.xlim([0, lot])

                plt.subplot(413)
                plt.title("Turning Points")
                plt.plot(summarized[name]["extremas-x"],
                         summarized[name]["extremas"],
                         'o',
                         mfc='none',
                         markersize=7)
                plt.xlim([0, lot])

                plt.subplot(414)
                plt.title("Seasonality and Cycle")
                plt.plot(summarized[name]["Ds-x"], summarized[name]["Ds"], 'r')
                plt.xlim([0, lot])
                plt.tight_layout()
                canvas.figure = f
                canvas.draw()

        else:
            display_error(6)

    elif sel_task == 'Clustering':
        n = num.get()
        lot = length.get()

        if n == "":
            display_error(7)
        else:
            n = int(n)
            if type(n) != int:
                display_error(8)
            elif n <= 0:
                display_error(9)

        if lot == "":
            display_error(10)
        else:
            lot = int(lot)
            if type(lot) != int:
                display_error(11)
            elif lot <= 0:
                display_error(12)

        if type(lot) == int and type(n) == int and lot > 0 and n > 0:
            curr_pos = 0
            plots = []
            data, aDates = LoadTimeseries.read_c_timeseries(data_path, n, lot)
            original, summarized = Summarize4Clustering.summarize(
                data, aDates, lot)
            plt.clf()
            curr_pos = 0
            plots = Clustering.cluster(original, summarized, n)
            canvas.figure = plots[0]
            canvas.draw()

    elif sel_task == 'Prediction':
        curr_pos = 0
        plots = []
        name = str(stock.get())
        if name != "None":
            lot = length.get()
            sp = steps.get()
            if sp == "":
                display_error(13)
            else:
                sp = int(sp)
                if type(sp) != int:
                    display_error(14)
                elif sp <= 0:
                    display_error(15)

            if lot != "":
                lot = int(lot)
                if type(lot) != int:
                    display_error(11)
                elif lot <= 0:
                    display_error(12)

            if lot + sp > num_days:
                display_error(16)

            if type(lot) == int and lot > 0 and type(
                    sp) == int and sp > 0 and lot + sp <= num_days:
                data = LoadTimeseries.read_p_timeseries(
                    data_path, name, lot + sp)
                original, summarized = Summarize4Prediction.summarize(data, sp)
                orig_pre, orig_r_pre, sum_pre = Prediction.predict(
                    original, summarized[name]["Ds"], summarized[name]["AL"],
                    sp)
                plt.clf()
                # print(original)
                f = plt.figure(figsize=(6, 6), dpi=100, facecolor='white')
                original[name].ix[original[name].index[0]:].plot(
                    style='b', label="Actual")
                orig_pre.ix[orig_pre.index[0]:].plot(style='r', label="ARMA")
                orig_r_pre.ix[orig_r_pre.index[0]:].plot(style='purple',
                                                         label="r-ARMA")
                sum_pre.ix[orig_pre.index[0]:].plot(style='g',
                                                    label="Summarized")
                plt.legend(loc=2, prop={'size': 10})
                canvas.figure = f
                canvas.draw()
        else:
            display_error(3)
Beispiel #4
0
def _Go():
    global flag;global num_days;global length;global steps;
    global num_days;global f;global sa;global plots;global curr_pos

    sel_task = task.get()
   
    if (data_path == None):
        display_error(1)
    elif (sel_task == 'None'):
        display_error(2)
    elif (sel_task == 'Summarize'):
        curr_pos = 0
        plots = []
        name = str(stock.get())
        if name != "None":
            lot = length.get()
            if lot=="":
                display_error(3)
            else:
                lot = int(lot)
                if type(lot) != int:
                    display_error(4)
                elif lot <= 0:
                    display_error(5)
                    
            if lot != "" and type(int(lot)) == int and int(lot) > 0:
                data = LoadTimeseries.read_p_timeseries(data_path, name, lot)
                original, summarized = Summarize.summarize(data)
                plt.clf()

                #yearsFmt = mdates.DateFormatter('%b %Y')
                f = plt.figure(figsize=(6,6), dpi=100, facecolor='white')
                plt.subplot(411)
                plt.title("Initial Timeserie")
                original[name].ix[original[name].index].plot(style='b')
                
##                print(summarized[name]["extremas-x"])
##                tps = []
##                tps_ind = []
##                for i in range(len(original[name])):
##                    if i in summarized[name]["extremas-x"]:
##                        tps.append(original[name][i])
##                        tps_ind.append(original[name].index[i])
##                print(tps_ind)
##                print(tps)
##                f = Series(tps, index=tps_ind).ix[tps_ind].plot(style='r',marker='o', linestyle="", markersize=7)

                plt.subplot(412)
                plt.title("Overall Timeserie Trend")
                plt.plot(summarized[name]["trend"]["x"],summarized[name]["trend"]["r"],'g')
                plt.xlim([0,lot])
                
                plt.subplot(413)
                plt.title("Turning Points")
                plt.plot(summarized[name]["extremas-x"], summarized[name]["extremas"], 'o', mfc='none', markersize=7)
                plt.xlim([0,lot])
                
                plt.subplot(414)
                plt.title("Seasonality and Cycle")
                plt.plot(summarized[name]["Ds-x"], summarized[name]["Ds"], 'r')
                plt.xlim([0,lot])
                plt.tight_layout()
                canvas.figure = f
                canvas.draw()
                
        else:
            display_error(6)
        
        
    elif sel_task == 'Clustering':
        n = num.get()
        lot = length.get()
        
        if n == "":
            display_error(7)
        else:
            n = int(n)
            if type(n) != int:
                display_error(8)
            elif n <= 0:
                display_error(9)

        if lot == "":
            display_error(10)
        else:
            lot = int(lot)
            if type(lot) != int:
                display_error(11)
            elif lot <= 0:
                display_error(12)
            
        if type(lot) == int and type(n) == int and lot > 0 and n > 0:
            curr_pos = 0
            plots = []        
            data, aDates = LoadTimeseries.read_c_timeseries(data_path, n, lot)
            original, summarized = Summarize4Clustering.summarize(data, aDates, lot)
            plt.clf()
            curr_pos = 0
            plots = Clustering.cluster(original, summarized, n)
            canvas.figure = plots[0]
            canvas.draw()
       
    elif sel_task == 'Prediction':
        curr_pos = 0
        plots = []
        name = str(stock.get())
        if name != "None":
            lot = length.get()
            sp = steps.get()
            if sp == "":
                display_error(13)
            else:
                sp = int(sp)
                if type(sp) != int:
                    display_error(14)
                elif sp <= 0:
                    display_error(15)
                
            if lot != "":
                lot = int(lot)
                if type(lot) != int:
                    display_error(11)
                elif lot <= 0:
                    display_error(12)
                
            if lot+sp > num_days:
                display_error(16)

            if type(lot) == int and lot > 0 and type(sp) == int and sp > 0 and lot+sp<=num_days:
                data = LoadTimeseries.read_p_timeseries(data_path, name, lot+sp)
                original, summarized = Summarize4Prediction.summarize(data,sp)
                orig_pre, orig_r_pre, sum_pre = Prediction.predict(original, summarized[name]["Ds"], summarized[name]["AL"], sp)
                plt.clf()
               # print(original)
                f = plt.figure(figsize=(6,6), dpi=100, facecolor='white')
                original[name].ix[original[name].index[0]:].plot(style='b', label="Actual")
                orig_pre.ix[orig_pre.index[0]:].plot(style='r',label="ARMA")
                orig_r_pre.ix[orig_r_pre.index[0]:].plot(style='purple',label="r-ARMA")
                sum_pre.ix[orig_pre.index[0]:].plot(style='g', label="Summarized")
                plt.legend(loc=2,prop={'size':10})
                canvas.figure = f
                canvas.draw()
        else:
            display_error(3)