def feedWithStockData(self, limit_date = None, fresh = False): if self.last_day is None: stockData, x_data, y_data = self.__getStockData(to_date = limit_date, fresh=fresh) else: last_date = csvmgr.stockDayToDatetime(self.last_day) last_date += timedelta(1) stockData, x_data, y_data = self.__getStockData(from_date = last_date, to_date = limit_date, fresh=fresh) print "Fitting..." self.last_day = csvmgr.getLastDayFromStock(stockData)
def feedWithStockData(self, limit_date = None, fresh = False): if self.last_day is None: stockData, x_data, y_data = self.__getStockData(to_date = limit_date, fresh=fresh) else: last_date = csvmgr.stockDayToDatetime(self.last_day) last_date += timedelta(1) stockData, x_data, y_data = self.__getStockData(from_date = last_date, to_date = limit_date, fresh=fresh) print "Fitting..." self.model.fit(x_data, y_data, batch_size=self.batch_size, nb_epoch=self.nb_epoch, show_accuracy=True) self.last_day = csvmgr.getLastDayFromStock(stockData)
def __getStockData(self, from_date=None, to_date=None, fresh=False): maxlen = self.days_seq stockData = csvmgr.getStockData(self.csv_id, force_update=fresh) if from_date is None: from_date = csvmgr.stockDayToDatetime(csvmgr.getFirstDayFromStock(stockData)) if to_date is None: to_date = csvmgr.stockDayToDatetime(csvmgr.getLastDayFromStock(stockData)) if (to_date-from_date) <= timedelta(maxlen): from_date -= timedelta(maxlen+20) stockData = csvmgr.filterStockData(stockData, from_date, to_date) print "Getting stock data from "+csvmgr.getFirstDayFromStock(stockData) + " to " + csvmgr.getLastDayFromStock(stockData) stockValues = csvmgr.getPricesFromStock(stockData) x_data = numpy.array([stockValues[i:i+maxlen] for i in xrange(len(stockValues)-maxlen)]) y_data = numpy.array([floor(stockValues[i]/stockValues[i-1]) for i in xrange(maxlen,len(stockValues))]) return stockData, x_data, y_data