示例#1
0
def get_snp500(date='2015-10-30'):
    try:
        from snp500 import SNP500, print_symbol
    except:
        url = 'https://raw.githubusercontent.com/yangphysics/snp500/master/snp500.py'
        import subprocess
        msg = subprocess.check_output("wget {0}".format(url), shell=True)
        print(msg)
        from snp500 import SNP500, print_symbol

    #  read in symbols included in S&P 500
    snp0 = SNP500(is_print=True)
    snp = snp0(date=date)
    print_symbol(snp)
    return snp
示例#2
0
def get_snp500(date='2015-10-30'):
    try: 
        from snp500 import SNP500,print_symbol
    except:
        url = 'https://raw.githubusercontent.com/yangphysics/snp500/master/snp500.py'
        import subprocess
        msg = subprocess.check_output("wget {0}".format(url), shell=True)
        print(msg)
        from snp500 import SNP500,print_symbol

    #  read in symbols included in S&P 500
    snp0 = SNP500(is_print=True)
    snp = snp0(date=date)
    print_symbol(snp)
    return snp
示例#3
0
def prepare_database(db_name="./snp500_db_test.sqlite", date=pd.datetime(2015, 10, 30), period=4000):
    #  import snp500 package
    try: 
        from snp500 import SNP500,print_symbol
    except:
        url = 'https://raw.githubusercontent.com/yangphysics/snp500/master/snp500.py'
        import subprocess
        msg = subprocess.check_output("wget {0}".format(url), shell=True)
        print(msg)
        from snp500 import SNP500,print_symbol
    #  read in symbols included in S&P 500
    snp0 = SNP500(is_print=True)
    snp = snp0(date=date.strftime('%Y-%m-%d'))
    print_symbol(snp)
    #  open the data-base file to start writing
    con = sqlite3.connect(db_name)
    for i,symbol in enumerate(snp[:10]):
        print(' {0}  {1}'.format(i,symbol))
        s = get_stock_period(symbol, d=date, period=period)
        con.execute("DROP TABLE IF EXISTS sid_{0}".format(symbol.replace('-', '_')))
        s.to_sql('sid_{0}'.format(symbol.replace('-', '_')), con)