def on_show(self):
     history = HistoryController.History()
     self.symbol_data = history.get_all_symbol_from_history()
     self.symbol_list = SymbolList(self, self.symbol_data)
     self.symbol_list.grid(row=2,
                           column=10,
                           columnspan=2,
                           sticky=(tk.N, tk.S, tk.E, tk.W))
     self.symbol_list.config(relief=tk.GROOVE, bd=2)
     self.forecastOutput.set("")
     self.update()
    def update(self):
        symbol_selected = self.symbol_selected
        history = HistoryController.History()
        if not self.parameter:
            return
        if len(symbol_selected):
            # TODO remove the for loop
            self.setting_view.update_view(parameter=self.parameter,
                                          symbols=symbol_selected)
            for item in symbol_selected:
                # TODO: only for one
                # TODO: change data to be with Datum
                current_history_data = history.get_by_symbol_id_and_parameter_id(
                    item.id, self.parameter.id)

                # dropna() - entfernt die leere Daten
                # pct_change(12) - wie vie jeder Wert prozentual geändert wurde, von der Mitte und mir dem Schritt 12 gerechnet
                current_prices = 100 * current_history_data.ask_price.pct_change(
                    12).dropna()
                am = arch_model(current_history_data.ask_price)
                res = am.fit(update_freq=5)
                forecasts = res.forecast(horizon=5, method='bootstrap')
                self.forecastOutput.set(np.sqrt(forecasts.variance.tail()))
                #forecasts.variance['h.1'].tail(n=1).values[0]
                #self.setting_view.update_view(parameter=self.parameter, symbols=symbol_selected)

                # split_date = dt.datetime(2010, 1, 1)
                # res = am.fit(last_obs=split_date)

                # TODO: output this to frame
                print(res.summary())
                self.figureCorelation = res.plot()
                #self.a.plot(res, color='red', label=bitcoin_name)

                # ar = ARX(ann_inflation, lags=[1, 3, 12])
                # print(ar.fit().summary()
                # ar.volatility = ARCH(p=5)
                # res = ar.fit(update_freq=0, disp='off')
                # print(res.summary())
                # fig = res.plot()

        canvas = FigureCanvasTkAgg(self.figureCorelation, self)
        canvas.get_tk_widget().grid(row=1,
                                    rowspan=3,
                                    columnspan=10,
                                    sticky=(tk.N, tk.S, tk.E, tk.W))
        canvas.draw()

        toolbar_frame = tk.Frame(master=self)
        toolbar_frame.grid(row=4, columnspan=10, sticky=tk.W)
        toolbar = NavigationToolbar2Tk(canvas, toolbar_frame)
        toolbar.update()
        return True
示例#3
0
 def update(self):
     history = HistoryController.History()
     self.parameters = history.get_all_parameter_from_history()
     self.parameter_list = ParameterList(self, self.parameters)
     self.parameter_list.grid(row=1, column=1, sticky=(tk.N, tk.S, tk.E, tk.W))
     self.parameter_list.config(relief=tk.GROOVE, bd=2)
     df = self.get_correlation()
     tbm = TableModel(dataframe=df)
     if df.empty:
         return True
     self.table.model = tbm
     self.table.show()
     self.table.redraw()
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        # Set the grid size
        col = 0
        while col < 12:
            self.columnconfigure(col, weight=1)
            col += 1
        self.rowconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)
        self.rowconfigure(2, weight=2)
        self.rowconfigure(3, weight=1)
        self.rowconfigure(4, weight=1)

        label = tk.Label(self,
                         text="Price changing mean",
                         font=controller.LARGE_FONT)
        label.grid(row=0, columnspan=12)

        self.a = self.figureCorrelation.add_subplot(111)
        self.canvas = FigureCanvasTkAgg(self.figureCorrelation, self)
        self.canvas.get_tk_widget().grid(row=1,
                                         rowspan=3,
                                         columnspan=10,
                                         sticky=(tk.N, tk.S, tk.E, tk.W))

        history = HistoryController.History()
        self.symbol_data = history.get_all_symbol_from_history()
        self.parameters = history.get_all_parameter_from_history()

        self.setting_view = SettingView(self)
        self.setting_view.grid(row=1, column=10, sticky=(tk.N, tk.E))

        self.parameter_list = ParameterList(self, self.parameters)
        self.parameter_list.grid(row=1,
                                 column=11,
                                 sticky=(tk.N, tk.S, tk.E, tk.W))
        self.parameter_list.config(relief=tk.GROOVE, bd=2)

        self.symbol_list = SymbolList(self, self.symbol_data)
        self.symbol_list.grid(row=2,
                              column=10,
                              rowspan=2,
                              columnspan=2,
                              sticky=(tk.N, tk.S, tk.E, tk.W))
        self.symbol_list.config(relief=tk.GROOVE, bd=2)

        btn_update_selected = tk.Button(self,
                                        text="Update",
                                        command=self.renew)
        btn_update_selected.grid(row=4, column=11)
示例#5
0
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        # Set the grid size
        col = 0
        while col < 12:
            self.columnconfigure(col, weight=1)
            col += 1
        self.rowconfigure(0, weight=1)
        self.rowconfigure(1, weight=4)
        self.rowconfigure(2, weight=1)
        self.rowconfigure(3, weight=1)
        self.rowconfigure(4, weight=1)

        label = tk.Label(self,
                         text="Neural Forecast",
                         font=controller.LARGE_FONT)
        label.grid(row=0, columnspan=12)

        self.a = self.figureCorrelation.add_subplot(111)
        self.canvas = FigureCanvasTkAgg(self.figureCorrelation, self)
        self.canvas.get_tk_widget().grid(row=1,
                                         rowspan=3,
                                         columnspan=10,
                                         sticky=(tk.N, tk.S, tk.E, tk.W))

        history = HistoryController.History()
        self.symbol_data = history.get_all_symbol_from_history()
        self.symbol_list = SymbolList(self, self.symbol_data)
        self.symbol_list.grid(row=1,
                              column=10,
                              rowspan=3,
                              columnspan=2,
                              sticky=(tk.N, tk.S, tk.E, tk.W))
        self.symbol_list.config(relief=tk.GROOVE, bd=2)

        btn_update_selected = tk.Button(self,
                                        text="Update",
                                        command=self.renew)
        btn_update_selected.grid(row=4, column=11)

        btn_train_selected = tk.Button(self, text="Train", command=self.train)
        btn_train_selected.grid(row=4, column=12)

        btn_forecast_selected = tk.Button(self,
                                          text="Forecast",
                                          command=self.forecast)
        btn_forecast_selected.grid(row=4, column=13)
示例#6
0
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.columnconfigure(0, weight=10)
        self.columnconfigure(1, weight=1)
        self.rowconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)

        history = HistoryController.History()
        self.parameters = history.get_all_parameter_from_history()

        self.setting_view = SettingView(self)
        self.setting_view.grid(row=0, column=1, sticky=(tk.N, tk.E))

        self.parameter_list = ParameterList(self, self.parameters)
        self.parameter_list.grid(row=1, column=1, sticky=(tk.N, tk.S, tk.E, tk.W))
        self.parameter_list.config(relief=tk.GROOVE, bd=2)
        table_frame = tk.Frame(master=self)
        table_frame.grid(row=0,rowspan=2, column=0, sticky=(tk.N, tk.S, tk.E, tk.W))
        self.table = pt = Table(table_frame)
        pt.show()
示例#7
0
    def update(self):
        self.a.cla()  # which clears data but not axes
        symbol_selected = self.symbol_selected
        history = HistoryController.History()
        if not self.parameter:
            return
        if len(symbol_selected):
            self.setting_view.update_view(parameter=self.parameter,
                                          symbols=symbol_selected)
            for item in symbol_selected:
                current_history_data = history.get_by_symbol_id_and_parameter_id(
                    item.id, self.parameter.id)
                current_prices = current_history_data.ask_price
                self.a.acorr(current_prices,
                             label=item.symbol_global_id,
                             usevlines=False)
                self.a.grid(True)
                self.a.axhline(0, color='black', lw=2)
        # TODO remove this
        else:
            bitcoin_name = "BITSTAMP_SPOT_BTC_USD"
            bitcoin_symbol = list(
                filter(lambda x: x.symbol_global_id == bitcoin_name,
                       self.symbol_data))[0]
            history_data = history.get_by_symbol_id(bitcoin_symbol.id)
            current_prices = history_data.ask_price
            self.a.acorr(current_prices)
            self.a.grid(True)
            self.a.axhline(0, color='black', lw=2)

        self.a.legend()
        self.canvas.draw()

        toolbar_frame = tk.Frame(master=self)
        toolbar_frame.grid(row=4, columnspan=10, sticky=tk.W)
        toolbar = NavigationToolbar2Tk(self.canvas, toolbar_frame)
        toolbar.update()
        return True
示例#8
0
    def getData(self, maxLen=-1, maxfaktor=1.):
        symbol_selected = self.symbol_selected
        history = HistoryController.History()
        allData = []
        if len(symbol_selected):
            for item in symbol_selected:
                current_history_data = history.get_by_symbol_id(item.id)
                current_prices = current_history_data.ask_price.values  #pct_change(12).dropna()
                allData.append(current_prices.tolist())
        else:
            bitcoin_name = "BITSTAMP_SPOT_BTC_USD"
            bitcoin_symbol = list(
                filter(lambda x: x.symbol_global_id == bitcoin_name,
                       self.symbol_data))[0]
            history_data = history.get_by_symbol_id(bitcoin_symbol.id)
            current_prices = history_data.ask_price.values  #pct_change(12).dropna()
            if current_prices.size == 0:
                return
            allData.append(current_prices.tolist())
        data = []
        minlen = 100000  #Abfragen sind immer mit limit 10000, somit wird 100000 nie erreicht
        for i in range(
                len(allData)
        ):  # Eigentlich sollte man nat�rlich gleichlange reihen nehmen, sonst ist es irgendwie sinnlos...
            if minlen > len(allData[i]):
                minlen = len(allData[i])
        if maxfaktor < 1:
            maxLen = minlen * maxfaktor * len(allData)
        for i in range(minlen):
            for j in range(len(allData)):
                #data.append(int(allData[i][len(allData[i])-1-minlen+j]*1000))
                data.append(allData[j][len(allData[j]) - 1 - minlen + i])
                if maxLen > -1:
                    if len(data) > maxLen:
                        return data

        return data
    def update(self):
        self.a.cla()  # which clears data but not axes
        symbol_selected = self.symbol_selected
        history = HistoryController.History()
        if not self.parameter:
            return
        if len(symbol_selected):
            self.setting_view.update_view(parameter=self.parameter,
                                          symbols=symbol_selected)
            for item in symbol_selected:
                current_history_data = history.get_by_symbol_id_and_parameter_id(
                    item.id, self.parameter.id)
                current_prices = 100 * current_history_data.ask_price.pct_change(
                    12).dropna()
                self.a.plot(current_prices, label=item.symbol_global_id)

        self.a.legend()
        self.canvas.draw()

        toolbar_frame = tk.Frame(master=self)
        toolbar_frame.grid(row=4, columnspan=10, sticky=tk.W)
        toolbar = NavigationToolbar2Tk(self.canvas, toolbar_frame)
        toolbar.update()
        return True
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        # set the grid size
        col = 0
        while col < 12:
            self.columnconfigure(col, weight=1)
            col += 1
        self.rowconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)
        self.rowconfigure(2, weight=2)
        self.rowconfigure(3, weight=1)
        self.rowconfigure(4, weight=1)

        label = tk.Label(self, text="Garch", font=controller.LARGE_FONT)
        label.grid(row=0, columnspan=12)

        self.a = self.figureCorelation.add_subplot(111)
        canvas = FigureCanvasTkAgg(self.figureCorelation, self)
        canvas.get_tk_widget().grid(row=1,
                                    rowspan=3,
                                    columnspan=10,
                                    sticky=(tk.N, tk.S, tk.E, tk.W))
        canvas.draw()

        history = HistoryController.History()
        self.symbol_data = history.get_all_symbol_from_history()
        self.parameters = history.get_all_parameter_from_history()

        self.setting_view = SettingView(self)
        self.setting_view.grid(row=1, column=10, sticky=(tk.N, tk.E))

        self.parameter_list = ParameterList(self, self.parameters)
        self.parameter_list.grid(row=1,
                                 column=11,
                                 sticky=(tk.N, tk.S, tk.E, tk.W))
        self.parameter_list.config(relief=tk.GROOVE, bd=2)

        self.symbol_list = SymbolList(self, self.symbol_data)
        self.symbol_list.grid(row=2,
                              column=10,
                              columnspan=2,
                              sticky=(tk.N, tk.S, tk.E, tk.W))
        self.symbol_list.config(relief=tk.GROOVE, bd=2)

        self.forecastOutput = tk.StringVar(self)
        labels_groups = tk.Frame(self)
        label = tk.Label(labels_groups,
                         text="Forecasted variance:",
                         font=controller.LARGE_FONT)
        label.pack(side=tk.TOP)
        labelForecast = tk.Label(labels_groups,
                                 textvariable=self.forecastOutput,
                                 font=controller.SMALL_FONT)
        labelForecast.pack(side=tk.BOTTOM)
        labels_groups.grid(row=3,
                           column=10,
                           columnspan=2,
                           sticky=(tk.N, tk.S, tk.E, tk.W))

        btn_update_selected = tk.Button(self,
                                        text="Update",
                                        command=self.renew)
        btn_update_selected.grid(row=4, column=10, columnspan=2)
示例#11
0
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        # set the grid size
        col = 0
        while col < 12:
            self.columnconfigure(col, weight=1)
            col += 1
        self.rowconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)
        self.rowconfigure(2, weight=2)
        self.rowconfigure(3, weight=1)
        self.rowconfigure(4, weight=1)
        self.rowconfigure(5, weight=1)

        label = tk.Label(self,
                         text="Correlation graph",
                         font=controller.LARGE_FONT)
        label.grid(row=0, columnspan=12)
        self.type = tk.IntVar(self)
        self.type.set(1)
        tk.Radiobutton(self,
                       text="Normalize to bitcoin course",
                       variable=self.type,
                       value=1).grid(row=3, column=11)
        tk.Radiobutton(self,
                       text="Normalize auto",
                       variable=self.type,
                       value=2).grid(row=4, column=11)

        self.a = self.figureCorelation.add_subplot(111)
        self.canvas = FigureCanvasTkAgg(self.figureCorelation, self)
        self.canvas.get_tk_widget().grid(row=1,
                                         rowspan=3,
                                         columnspan=10,
                                         sticky=(tk.N, tk.S, tk.E, tk.W))

        history = HistoryController.History()
        self.symbol_data = history.get_all_symbol_from_history()
        self.parameters = history.get_all_parameter_from_history()

        self.setting_view = SettingView(self)
        self.setting_view.grid(row=1, column=10, sticky=(tk.N, tk.E))

        self.parameter_list = ParameterList(self, self.parameters)
        self.parameter_list.grid(row=1,
                                 column=11,
                                 sticky=(tk.N, tk.S, tk.E, tk.W))
        self.parameter_list.config(relief=tk.GROOVE, bd=2)

        self.symbol_list = SymbolList(self, self.symbol_data)
        self.symbol_list.grid(row=2,
                              column=10,
                              columnspan=2,
                              sticky=(tk.N, tk.S, tk.E, tk.W))
        self.symbol_list.config(relief=tk.GROOVE, bd=2)

        self.forecastOutput = tk.StringVar(self)
        labelForecast = tk.Label(self,
                                 textvariable=self.forecastOutput,
                                 font=controller.LARGE_FONT)
        labelForecast.grid(row=3, column=10, sticky=(tk.N, tk.S, tk.E, tk.W))

        btn_update_selected = tk.Button(self,
                                        text="Update",
                                        command=self.renew)
        btn_update_selected.grid(row=5, column=11)
示例#12
0
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        # set the grid size
        col = 0
        while col < 12:
            self.columnconfigure(col, weight=1)
            col += 1
        self.rowconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)
        self.rowconfigure(2, weight=2)
        self.rowconfigure(3, weight=1)
        self.rowconfigure(4, weight=1)

        self.a1 = self.figureLinearRegressionChart.add_subplot(331)
        self.a2 = self.figureLinearRegressionChart.add_subplot(332)
        self.a3 = self.figureLinearRegressionChart.add_subplot(333)
        self.a4 = self.figureLinearRegressionChart.add_subplot(334)
        self.a5 = self.figureLinearRegressionChart.add_subplot(335)
        self.a6 = self.figureLinearRegressionChart.add_subplot(336)
        self.a7 = self.figureLinearRegressionChart.add_subplot(337)
        self.a8 = self.figureLinearRegressionChart.add_subplot(338)
        self.a9 = self.figureLinearRegressionChart.add_subplot(339)
        plt.subplots_adjust(left=1,
                            bottom=1,
                            right=1.1,
                            top=1.1,
                            wspace=0.5,
                            hspace=0.5)
        self.canvas = FigureCanvasTkAgg(self.figureLinearRegressionChart, self)
        self.canvas.get_tk_widget().grid(row=1,
                                         rowspan=2,
                                         columnspan=2,
                                         sticky=(tk.N, tk.S, tk.E, tk.W))
        self.canvas.draw()

        label = tk.Label(self,
                         text="Linear Regression Price Prediction Charts",
                         font=controller.LARGE_FONT)
        label.grid(row=0, columnspan=12)

        history = HistoryController.History()
        self.symbol_data = history.get_all_symbol_from_history()

        history = HistoryController.History()
        self.parameters = history.get_all_parameter_from_history()

        self.setting_view = SettingView(self)
        self.setting_view.grid(row=1,
                               column=10,
                               sticky=(tk.N, tk.S, tk.E, tk.W))

        self.parameter_list = ParameterList(self, self.parameters)
        self.parameter_list.grid(row=1,
                                 column=11,
                                 sticky=(tk.N, tk.S, tk.E, tk.W))
        self.parameter_list.config(relief=tk.GROOVE, bd=2)

        self.symbol_list = SymbolList(self, self.symbol_data)
        self.symbol_list.grid(row=2,
                              column=10,
                              columnspan=2,
                              sticky=(tk.N, tk.S, tk.E, tk.W))
        self.symbol_list.config(relief=tk.GROOVE, bd=2)

        self.forecastOutput = tk.StringVar(self)
        labelForecast = tk.Label(self,
                                 textvariable=self.forecastOutput,
                                 font=controller.SMALL_FONT)
        labelForecast.grid(row=3, column=10, sticky=(tk.N, tk.S, tk.E, tk.W))

        btn_update_selected = tk.Button(self,
                                        text="Update",
                                        command=self.renew)
        btn_update_selected.grid(row=4, column=8, columnspan=4)
示例#13
0
    def update(self):
        self.a1.cla()
        self.a2.cla()
        self.a3.cla()
        self.a4.cla()
        self.a5.cla()
        self.a6.cla()
        self.a7.cla()
        self.a8.cla()
        self.a9.cla()

        symbol_selected = self.symbol_selected
        history = HistoryController.History()

        if not self.parameter:
            return
        if len(symbol_selected):
            self.setting_view.update_view(parameter=self.parameter,
                                          symbols=symbol_selected)
            for item in symbol_selected:
                current_history_data = history.get_by_symbol_id_and_parameter_id(
                    item.id, self.parameter.id)
                #print(current_history_data)
                #df = current_history_data.get_group(bitcoin_name)
                df = current_history_data
                #print(df)
                df['date'] = df['start_time_exchange'].map(mdates.date2num)
                #df = df.loc[df['symbol_id'] == item.id]
                df = df[['ask_price']]

                accuracies = []
                predictions = []

                for x in range(1, 10):
                    forecast_out = int(x)  # predict x days into future
                    df['Prediction'] = df[['ask_price']].shift(-forecast_out)
                    X = np.array(df.drop(['Prediction'],
                                         1))  # labels for linear regression
                    X = preprocessing.scale(X)
                    X_forecast = X[-forecast_out:]
                    X = X[:-forecast_out]

                    y = np.array(df['Prediction'])
                    y = y[:-forecast_out]

                    X_train, X_test, y_train, y_test = cross_validation.train_test_split(
                        X, y, test_size=0.2)

                    # train
                    clf = LinearRegression()
                    clf.fit(X_train, y_train)
                    # test
                    accuracy = clf.score(X_test, y_test)

                    forecast_prediction = clf.predict(X_forecast)

                    accuracies.append(accuracy)
                    predictions.append(forecast_prediction)

        self.a1.scatter([1],
                        predictions[0],
                        color='green',
                        label="Confidence: " + "{0:.2f}".format(accuracies[0]))
        self.a1.set_xticks([1])
        self.a1.set_yticks(predictions[0])
        self.a1.set_title("1 day forecast")

        self.a2.plot([1, 2],
                     predictions[1],
                     color='green',
                     label="Confidence: " + "{0:.2f}".format(accuracies[1]))
        self.a2.set_xticks([1, 2])
        self.a2.set_yticks(predictions[1])
        self.a2.set_title("2 days forecast")

        self.a3.plot(list(range(1, 4)),
                     predictions[2],
                     color='green',
                     label="Confidence: " + "{0:.2f}".format(accuracies[2]))
        self.a3.set_xticks(list(range(1, 4)))
        self.a3.set_yticks(predictions[2])
        self.a3.set_title("3 days forecast")

        self.a4.plot(list(range(1, 5)),
                     predictions[3],
                     color='green',
                     label="Confidence: " + "{0:.2f}".format(accuracies[3]))
        self.a4.set_xticks(list(range(1, 5)))
        self.a4.set_yticks(predictions[3])
        self.a4.set_title("4 days forecast")

        self.a5.plot(list(range(1, 6)),
                     predictions[4],
                     color='green',
                     label="Confidence: " + "{0:.2f}".format(accuracies[4]))
        self.a5.set_xticks(list(range(1, 6)))
        self.a5.set_yticks(predictions[4])
        self.a5.set_title("5 days forecast")

        self.a6.plot(list(range(1, 7)),
                     predictions[5],
                     color='green',
                     label="Confidence: " + "{0:.2f}".format(accuracies[5]))
        self.a6.set_xticks(list(range(1, 7)))
        self.a6.set_yticks(predictions[5])
        self.a6.set_title("6 days forecast")

        self.a7.plot(list(range(1, 8)),
                     predictions[6],
                     color='green',
                     label="Confidence: " + "{0:.2f}".format(accuracies[6]))
        self.a7.set_xticks(list(range(1, 8)))
        self.a7.set_yticks(predictions[6])
        self.a7.set_title("7 days forecast")

        self.a8.plot(list(range(1, 9)),
                     predictions[7],
                     color='green',
                     label="Confidence: " + "{0:.2f}".format(accuracies[7]))
        self.a8.set_xticks(list(range(1, 9)))
        self.a8.set_yticks(predictions[7])
        self.a8.set_title("8 days forecast")

        self.a9.plot(list(range(1, 10)),
                     predictions[8],
                     color='green',
                     label="Confidence: " + "{0:.2f}".format(accuracies[8]))
        self.a9.set_xticks(list(range(1, 10)))
        self.a9.set_yticks(predictions[8])
        self.a9.set_title("9 days forecast")

        self.a1.grid(True)
        self.a1.legend()

        self.a2.grid(True)
        self.a2.legend()

        self.a3.grid(True)
        self.a3.legend()

        self.a4.grid(True)
        self.a4.legend()

        self.a5.grid(True)
        self.a5.legend()

        self.a6.grid(True)
        self.a6.legend()

        self.a7.grid(True)
        self.a7.legend()

        self.a8.grid(True)
        self.a8.legend()

        self.a9.grid(True)
        self.a9.legend()

        self.canvas.draw()

        return True