Example #1
0
    def add_stock(self,
                  ticker,
                  name=None,
                  exchange=None,
                  sector=None,
                  industry=None):
        """ Add a stock to the stock database
        Add the stock to the symbols table and populate quotes table with all
        available historical quotes. If any of the optional parameters are left
        out, the corresponding information will be obtained from Yahoo!
        Finance.
        :param ticker: Stock ticker symbol
        :param name: (optional) Company/security name
        :param exchange: (optional) Exchange on which the security is traded
        :param sector: (optional) Company/security sector
        :param Industry (optional) Company/security industry
        """
        ticker = ticker.lower()
        session = self.db.Session()

        if self.check_stock_exists(ticker, session):
            print "Stock %s already exists!" % (ticker.upper())
            return

        if name is None:
            name = quotes.get_name(ticker)
        if exchange is None:
            exchange = quotes.get_stock_exchange(ticker)
        if sector is None:
            sector = quotes.get_sector(ticker)
        if industry is None:
            industry = quotes.get_industry(ticker)

        stock = Symbol(ticker, name, exchange, sector, industry)

        session.add(stock)
        q = self._download_quotes(ticker, date(1900, 01, 01), date.today())
        for quote in q:
            quote.Features = Indicator(quote.Id)
        session.add_all(q)
        session.commit()
        session.close()
        self.update_quotes(ticker)
Example #2
0
    def add_stock(self, ticker, name=None, exchange=None,
                  sector=None, industry=None):
        """ Add a stock to the stock database
        Add the stock to the symbols table and populate quotes table with all
        available historical quotes. If any of the optional parameters are left
        out, the corresponding information will be obtained from Yahoo!
        Finance.
        :param ticker: Stock ticker symbol
        :param name: (optional) Company/security name
        :param exchange: (optional) Exchange on which the security is traded
        :param sector: (optional) Company/security sector
        :param Industry (optional) Company/security industry
        """
        ticker = ticker.lower()
        session = self.db.Session()

        if self.check_stock_exists(ticker, session):
            log.warn("Stock {} already exists!".format((ticker.upper())))
            return

        #TODO Add start and end date in it, and store after downloads
        #TODO Plenty of checks
        if name is None:
            name = quotes.get_name(ticker)
        if exchange is None:
            exchange = quotes.get_stock_exchange(ticker)
        if sector is None:
            sector = quotes.get_sector(ticker)
        if industry is None:
            industry = quotes.get_industry(ticker)

        stock = Symbol(ticker, name, exchange, sector, industry)
        session.add(stock)

        q = self._download_quotes(ticker, date(1960, 01, 01), date.today())
        #for quote in q:
            #quote.Features = Indicator(quote.Id)
        session.add_all(q)
        session.commit()
        session.close()
        self.update_quotes(ticker)
Example #3
0
    def add_ticker(self,
                   ticker,
                   name=None,
                   exchange=None,
                   timezone=None,
                   index=None,
                   sector=None,
                   industry=None,
                   start=None,
                   end=None):
        '''
        Add the symbol to either Index or Equity table and populate quotes table with all
        available historical quotes. If any of the optional parameters are left
        out, the corresponding information will be obtained from Yahoo!
        Finance.
        :param ticker: Stock ticker symbol
        :param name: (optional) Company/security name
        :param exchange: (optional) Exchange on which the security is traded
        :param sector: (optional) Company/security sector
        :param Industry (optional) Company/security industry
        '''
        ticker = ticker.lower()
        session = self.db.Session()

        if self.check_ticker_exists(ticker, session):
            log.warn("Stock {} already exists!".format((ticker.upper())))
            return

        #TODO Add start and end date in it
        ## Shared informations
        if name is None:
            name = quotes.get_name(ticker)
        if exchange is None:
            exchange = quotes.get_stock_exchange(ticker)

        # Check if we have an index symbol
        if ticker.find('^') == 0:
            timezone = 'US/Eastern'
            stock = Index(ticker,
                          name=name,
                          exchange=exchange,
                          timezone=timezone)
        else:
            if index is None:
                index = quotes.get_indices(ticker)
            if sector is None:
                sector = quotes.get_sector(ticker)
            if industry is None:
                industry = quotes.get_industry(ticker)
            stock = Equity(ticker, name, exchange, index, sector, industry)

        session.add(stock)

        if start is None:
            log.info('Reading NeuronQuant MySQL configuration...')
            sql = json.load(
                open(
                    '/'.join(
                        (os.path.expanduser('~/.quantrade'), 'default.json')),
                    'r'))['mysql']
            start = datetime.strptime(sql['data_start'], '%Y-%m-%d').date()
        if end is None:
            end = date.today()

        q = self._download_quotes(ticker, start, end)
        session.add_all(q)
        session.commit()
        session.close()
Example #4
0
    def add_ticker(self,
                  ticker,
                  name     = None,
                  exchange = None,
                  timezone = None,
                  index    = None,
                  sector   = None,
                  industry = None,
                  start    = None,
                  end      = None):
        '''
        Add the symbol to either Index or Equity table and populate quotes table with all
        available historical quotes. If any of the optional parameters are left
        out, the corresponding information will be obtained from Yahoo!
        Finance.
        :param ticker: Stock ticker symbol
        :param name: (optional) Company/security name
        :param exchange: (optional) Exchange on which the security is traded
        :param sector: (optional) Company/security sector
        :param Industry (optional) Company/security industry
        '''
        ticker = ticker.lower()
        session = self.db.Session()

        if self.check_ticker_exists(ticker, session):
            log.warn("Stock {} already exists!".format((ticker.upper())))
            return

        #TODO Add start and end date in it
        ## Shared informations
        if name is None:
            name = quotes.get_name(ticker)
        if exchange is None:
            exchange = quotes.get_stock_exchange(ticker)

        # Check if we have an index symbol
        if ticker.find('^') == 0:
            timezone = 'US/Eastern'
            stock = Index(ticker, name=name, exchange=exchange, timezone=timezone)
        else:
            if index is None:
                index = quotes.get_indices(ticker)
            if sector is None:
                sector = quotes.get_sector(ticker)
            if industry is None:
                industry = quotes.get_industry(ticker)
            stock = Equity(ticker, name, exchange, index, sector, industry)

        session.add(stock)

        if start is None:
            log.info('Reading NeuronQuant MySQL configuration...')
            sql = json.load(open('/'.join((os.path.expanduser('~/.quantrade'), 'default.json')), 'r'))['mysql']
            start = datetime.strptime(sql['data_start'], '%Y-%m-%d').date()
        if end is None:
            end = date.today()

        q = self._download_quotes(ticker, start, end)
        session.add_all(q)
        session.commit()
        session.close()