Exemple #1
0
    def _open_db(self):
        #
        # Open Name Db
        #
        self.nameArray = []
        reader = db_util.open_reader_fixed('names')
        for row in reader:
            self.nameArray.append(row)

        #
        # Open Price Db
        #
        self.priceArray = []
        reader = db_util.open_reader('price')
        for row in reader:
            self.priceArray.append(row)

        #
        # Open SMA Db
        #
        self.smaArray = []
        reader = db_util.open_reader('sma')
        for row in reader:
            self.smaArray.append(row)
        #
        # Open 50day SMA
        #
        self.sma50Array = []
        reader = db_util.open_reader('sma50')
        for row in reader:
            self.sma50Array.append(row)
Exemple #2
0
    def update_sma_db(self):
        stocks = db_util.open_reader('sma')
        self.smaArray = []

        for arr2 in stocks:
            newarr = []
            symbol = arr2[0]
            sma = self._calc_200_day_sma(symbol)
            newarr.append(symbol)
            newarr.append(sma)
            newarr.extend(arr2[1:self.numSma])
            self.smaArray.append(newarr)

        writer = db_util.open_writer('sma')
        writer.writerows(self.smaArray)

        stocks = db_util.open_reader('sma50')
        self.sma50Array = []
        for arr2 in stocks:
            newarr50 = []
            symbol = arr2[0]
            sma50 = self._calc_50_day_sma(symbol)
            newarr50.append(symbol)
            newarr50.append(sma50)
            newarr50.extend(arr2[1:self.numSma])
            self.sma50Array.append(newarr50)

        writer = db_util.open_writer('sma50')
        writer.writerows(self.sma50Array)
Exemple #3
0
	def update_sma_db(self):
    		stocks = db_util.open_reader('sma')
    		self.smaArray = [];

    		for arr2 in stocks:
  			newarr = [];
			symbol = arr2[0]
			sma = self._calc_200_day_sma(symbol)
			newarr.append(symbol)
			newarr.append(sma)
	    		newarr.extend(arr2[1:self.numSma])
			self.smaArray.append(newarr)

    		writer = db_util.open_writer('sma');
    		writer.writerows(self.smaArray);

    		stocks = db_util.open_reader('sma50')
    		self.sma50Array = [];
    		for arr2 in stocks:
  			newarr50 = [];
			symbol = arr2[0]
			sma50 = self._calc_50_day_sma(symbol)
			newarr50.append(symbol)
			newarr50.append(sma50)
	    		newarr50.extend(arr2[1:self.numSma])
			self.sma50Array.append(newarr50)

    		writer = db_util.open_writer('sma50');
    		writer.writerows(self.sma50Array);
Exemple #4
0
	def _open_db(self):
		#
	 	# Open Name Db
		#
		self.nameArray = []
		reader = db_util.open_reader_fixed('names')
		for row in reader:
	    	    self.nameArray.append(row)
		 
		#
	 	# Open Price Db
		#
		self.priceArray = []
		reader = db_util.open_reader('price')
		for row in reader:
	    	    self.priceArray.append(row)

		#
	 	# Open SMA Db
		#
		self.smaArray = []
		reader = db_util.open_reader('sma')
		for row in reader:
	    	    self.smaArray.append(row)
		#
		# Open 50day SMA
		#
		self.sma50Array = []
		reader = db_util.open_reader('sma50')
		for row in reader:
	    	    self.sma50Array.append(row)
Exemple #5
0
def update_price_db():
    stocks = db_util.open_reader('price')
    priceArray = []
    for arr2 in stocks:
        newarr = []
        symbol = arr2[0]
        price = _fetch_price(symbol)
        newarr.append(symbol)
        newarr.append(price)
        for i in range(1, 239):
            newarr.append(arr2[i])
        priceArray.append(newarr)

    writer = db_util.open_writer('price')
    writer.writerows(priceArray)
    def _open_db(self):
        #
        # Open Name Db
        #
        self.nameArray = []
        reader = db_util.open_reader_fixed("names")
        for row in reader:
            self.nameArray.append(row)

        #
        # Open Price Db
        #
        self.priceArray = []
        reader = db_util.open_reader("price")
        for row in reader:
            self.priceArray.append(row)

        #
        # Open SMA Db
        #
        self.smaArray = []
        reader = db_util.open_reader("sma")
        for row in reader:
            self.smaArray.append(row)
    def update_price_db(self):
        stocks = db_util.open_reader("price")
        self.priceArray = []
        for arr2 in stocks:
            newarr = []
            symbol = arr2[0]
            price = self._fetch_price(symbol)
            print symbol, price
            newarr.append(symbol)
            newarr.append(price)
            newarr.extend(arr2[1:240])
            self.priceArray.append(newarr)

        writer = db_util.open_writer("price")
        writer.writerows(self.priceArray)
    def update_sma_db(self):
        stocks = db_util.open_reader("sma")
        self.smaArray = []

        for arr2 in stocks:
            newarr = []
            symbol = arr2[0]
            sma = self._calc_200_day_sma(symbol)
            newarr.append(symbol)
            newarr.append(sma)
            newarr.extend(arr2[1 : self.numSma])
            self.smaArray.append(newarr)

        writer = db_util.open_writer("sma")
        writer.writerows(self.smaArray)
Exemple #9
0
def update_price_db():
    stocks = db_util.open_reader('price')
    priceArray = []
    for arr2 in stocks:
  	newarr = [];
	symbol = arr2[0]
	price = _fetch_price(symbol)
	newarr.append(symbol)
	newarr.append(price)
	for i in range(1,239):
	    newarr.append(arr2[i])
	priceArray.append(newarr)
     
    writer = db_util.open_writer('price');
    writer.writerows(priceArray);
Exemple #10
0
    def update_price_db(self):
        stocks = db_util.open_reader('price')
        self.priceArray = []
        for arr2 in stocks:
            newarr = []
            symbol = arr2[0]
            price = self._fetch_price(symbol)
            print symbol, price
            newarr.append(symbol)
            newarr.append(price)
            newarr.extend(arr2[1:240])
            self.priceArray.append(newarr)

        writer = db_util.open_writer('price')
        writer.writerows(self.priceArray)
Exemple #11
0
	def update_price_db(self):
    		self.priceArray = []
	        updatedPriceArray = self._fetch_updated_prices();
    		stocks = db_util.open_reader('price')
		lIndex = 0;
    		for arr2 in stocks:
  			newarr = [];
			symbol = arr2[0]
			price = updatedPriceArray[lIndex];
			#print symbol,price
			newarr.append(symbol)
			newarr.append(price)
	    		newarr.extend(arr2[1:240])
			self.priceArray.append(newarr)
			lIndex = lIndex + 1;
     	
    		writer = db_util.open_writer('price');
    		writer.writerows(self.priceArray);
Exemple #12
0
	def _fetch_updated_prices(self):
    		stockArray = db_util.open_reader('price')
		newPriceArray = [];
		symArr = [];
		for arr in stockArray:
			symArr.append(arr[0])
		totalLen = len(symArr);
		startIndex = 0;

		while ((startIndex +30) < totalLen):
			newPriceArray.extend(yahoostock.get_price_for_list(symArr[startIndex:startIndex+30]));
			startIndex = startIndex + 30;
			print "Fetched Updated prices for %s" % (startIndex);

		if (startIndex < totalLen):
			newPriceArray.extend(yahoostock.get_price_for_list(symArr[startIndex:totalLen]));

		return newPriceArray;
Exemple #13
0
    def update_price_db(self):
        self.priceArray = []
        updatedPriceArray = self._fetch_updated_prices()
        stocks = db_util.open_reader('price')
        lIndex = 0
        for arr2 in stocks:
            newarr = []
            symbol = arr2[0]
            price = updatedPriceArray[lIndex]
            #print symbol,price
            newarr.append(symbol)
            newarr.append(price)
            newarr.extend(arr2[1:240])
            self.priceArray.append(newarr)
            lIndex = lIndex + 1

        writer = db_util.open_writer('price')
        writer.writerows(self.priceArray)
Exemple #14
0
def update_sma_db():
    stocks = db_util.open_reader('sma')
    writeArray = [];

    if len(priceArray) == 0:
	update_price_db()

    for arr2 in stocks:
  	newarr = [];
	symbol = arr2[0]
	sma = _calc_200_day_sma(symbol)
	newarr.append(symbol)
	newarr.append(sma)
	for i in range(1,29):
	    newarr.append(arr2[i])
	writeArray.append(newarr)
     
    writer = db_util.open_writer('sma');
    writer.writerows(writeArray);
Exemple #15
0
def update_sma_db():
    stocks = db_util.open_reader('sma')
    writeArray = []

    if len(priceArray) == 0:
        update_price_db()

    for arr2 in stocks:
        newarr = []
        symbol = arr2[0]
        sma = _calc_200_day_sma(symbol)
        newarr.append(symbol)
        newarr.append(sma)
        for i in range(1, 29):
            newarr.append(arr2[i])
        writeArray.append(newarr)

    writer = db_util.open_writer('sma')
    writer.writerows(writeArray)
Exemple #16
0
    def _fetch_updated_prices(self):
        stockArray = db_util.open_reader('price')
        newPriceArray = []
        symArr = []
        for arr in stockArray:
            symArr.append(arr[0])
        totalLen = len(symArr)
        startIndex = 0

        while ((startIndex + 30) < totalLen):
            newPriceArray.extend(
                yahoostock.get_price_for_list(symArr[startIndex:startIndex +
                                                     30]))
            startIndex = startIndex + 30
            print "Fetched Updated prices for %s" % (startIndex)

        if (startIndex < totalLen):
            newPriceArray.extend(
                yahoostock.get_price_for_list(symArr[startIndex:totalLen]))

        return newPriceArray
Exemple #17
0
    last_date = last_quote[0].split('-');
    day = last_date[2];
    today = date.today().day
    if int(today) == int(day):
        return 1
    else:
        return 0


#
# Update for today if needed
#
def _update_and_open_db()
#	Check if todays file is created
	if db_util.check_update('price'):
	    priceArray = db_util.open_reader('price')
	    smaArray = db_util.open_reader('sma')
	else:
	    # Check if today is a market day
	    if today_is_market_day():
		# Update Price and SMA DB
		update_price_db():
		update_sma_db():
		arrayUpdated = 1
	    else:
	        priceArray = db_util.open_reader('price')
	        smaArray = db_util.open_reader('sma')
		
def _update_symbol_list()
    FilePtr = open('.update_symbols')
    someArr = [];