Ejemplo n.º 1
0
def update_summary_table(symbol):
  """
  If information about the symbol is not known yet (stock_type, sector, industry/activity),
  create a new entry in the summary table
  """
  try:
    if not cur:
      db,cur = connection()
  except:
    db,cur = connection()

  dic = stock_helper.load_symbol_dic()
  info = dic[symbol]

  cur.execute('INSERT OR IGNORE INTO SUMMARY(Symbol,Name,Type,Sector,Industry) VALUES(?,?,?,?,?)', (symbol,info[0],info[1],info[2],info[3]))
  db.commit()
  db.close()
  return  
Ejemplo n.º 2
0
def regular_download(start=None):
  """
  Download last month of data for all symbols, to update the database regularly
  """
  symbols = stock_helper.load_symbol_dic()
  
  for item in symbols:
    if start == None:
      stk = stock(item)
    else:
      stk = stock(item,start)
    try:
      stk.get_historical()
      update_summary_table(stk._symbol)
      update_data(stk)
      print 'updated %s' %item
    except:
      continue
  return
Ejemplo n.º 3
0
def full_download(start):
  """
  Download all the data from yahoo.finance from start to today
  (takes several days)
  """
  symbols = stock_helper.load_symbol_dic()

  con = sqlite3.connect('/home/gilles/projects/trading/quant_trading/database/market.db')
  cur = con.cursor()
  cur.execute('SELECT name FROM sqlite_master WHERE type="table"')
  tables = cur.fetchall()

  for key in symbols.keys():
    if '^' in key or '/' in key:
      del symbols[key]
      continue
#    if (key,) in tables:
#      cur.execute('SELECT COUNT(*) FROM %s' %key)
#      entries = cur.fetchall()
#      pdb.set_trace()
#      if entries[0][0] > 0:
#        del symbols[key]
  print len(symbols)

#  sys.exit()
  for item in symbols:
    stk = stock(item,start)
    try:
      stk.get_historical()
    except:
      continue

    try:
      update_summary_table(stk._symbol)
      update_data(stk)
    except:
      continue
    print '%s completed' %stk._symbol
  return
Ejemplo n.º 4
0
import os
import sys
import shutil
import urllib
import datetime
import pandas as pd
from pandas.io.data import DataReader
import easygui as eg
import stock_helper
import stock_database
import numpy as np
import pdb
import matplotlib.pyplot as plt

SYMBOL_DIC = stock_helper.load_symbol_dic()

class stock:
  """
  Class for creating and analyzing stocks from yahoo finance
  """

  def __init__(self,symbol='unknown',start=datetime.date.today()-datetime.timedelta(365/12),
              end=datetime.date.today(),name='unknown',mode='online',interactive=True,
              historical=None):
    """
    Parameters:
    		- symbol : string, optional. !! CAREFUL!! Either the symbol or the name has to be
                   provided. It is strongy recommended to provide the symbol rather than the name
                   Ticker symbol of the stock

        - start : string, optional (default: 30 days before today)