Example #1
0
    def doPredict(self, data: StockData) -> float:
        """
        Use the loaded trained neural network to predict the next stock value.
    
        Args:
          data: historical stock values of a company

        Returns:
          predicted next stock value for that company
        """
        #self.model.compile(loss='mean_squared_error', optimizer='sgd')
        tmp_data = data.get_from_offset(data.get_row_count() - 5)
        tmp = np.array([[
            tmp_data[0][1], tmp_data[1][1], tmp_data[2][1], tmp_data[3][1],
            tmp_data[4][1]
        ]])

        pred = self.model.predict(tmp)

        res = data.get_last()[1]

        if (pred <= 0.5):
            res = res * 0.9
        else:
            res = res * 1.1

        # TODO: extract needed data for neural network and predict result
        return res
Example #2
0
    def doPredict(self, data: StockData) -> float:
        """
        Use the loaded trained neural network to predict the next stock value.

        Args:
          data: The historical stock values of a company

        Returns:
          The predicted next stock value for that company
        """
        # Assumptions about data: at least INPUT_SIZE pairs of type (_, float)
        assert data is not None and data.get_row_count() >= INPUT_SIZE

        # Extract last INPUT_SIZE floats (here: stock values) as input for neural network
        # (format: numpy array of arrays)
        input_values = np.array([[x[1] for x in data.get_from_offset(-INPUT_SIZE)]])

        normalized_prices = []

        vector_min = np.min(input_values)
        vector_max = np.max(input_values)

        for price in input_values:
            normalized_prices.append((price - vector_min) / (vector_max - vector_min))

        input_values = np.asarray(normalized_prices)

        try:
            # Let network predict the next stock value based on last 100 stock values
            prediction = self.model.predict(input_values)[0][0]
            return data.get_last()[1] + calculate_delta(prediction)
        except:
            logger.error("Error in predicting next stock value.")
            assert False
Example #3
0
    def doPredict(self, data: StockData) -> float:
        """ Use the loaded trained neural network to predict the next stock value.
    
        Args:
          data: The historical stock values of a company

        Returns:
          The predicted next stock value for that company
        """
        # Assumptions about data: at least 100 pairs of type (_, float)
        assert data is not None and data.get_row_count() >= 100

        # Extract last 100 floats (here: stock values) as input for neural network (format: numpy array of arrays)
        input_values = np.array([[x[1] for x in data.get_from_offset(-100)]])

        try:
            # Let network predict the next stock value based on last 100 stock values
            return self.model.predict(input_values)
        except:
            logger.error("Error in predicting next stock value.")
            assert False