def test_get_components_nasdaq_100(self): df = web.get_components_yahoo('^NDX') #NASDAQ-100 assert isinstance(df, pd.DataFrame) # Usual culprits, should be around for a while assert 'AAPL' in df.index assert 'GOOG' in df.index assert 'AMZN' in df.index
def test_get_components_dow_jones(self): raise nose.SkipTest( 'unreliable test, receive partial components back for dow_jones') df = web.get_components_yahoo('^DJI') #Dow Jones self.assertIsInstance(df, pd.DataFrame) self.assertEqual(len(df), 30)
def test_get_data(self): #single symbol #http://finance.yahoo.com/q/hp?s=GOOG&a=09&b=08&c=2010&d=09&e=10&f=2010&g=d df = web.get_data_yahoo('GOOG') assert df.Volume.ix['OCT-08-2010'] == 2859200 sl = ['AAPL', 'AMZN', 'GOOG'] pan = web.get_data_yahoo(sl, '2012') ts = pan.Close.GOOG.index[pan.Close.AAPL > pan.Close.GOOG] assert ts[0].dayofyear == 96 dfi = web.get_components_yahoo('^DJI') pan = web.get_data_yahoo(dfi, 'JAN-01-12', 'JAN-31-12') expected = [19.02, 28.23, 25.39] result = pan.Close.ix['01-18-12'][['GE', 'MSFT', 'INTC']].tolist() assert result == expected pan = web.get_data_yahoo(dfi, 'JAN-01-12', 'JAN-31-12', adjust_price=True) expected = [18.38, 27.45, 24.54] result = pan.Close.ix['01-18-12'][['GE', 'MSFT', 'INTC']].tolist() assert result == expected pan = web.get_data_yahoo(dfi, '2011', ret_index=True) d = [[ 1.01757469, 1.01130524, 1.02414183], [ 1.00292912, 1.00770812, 1.01735194], [ 1.00820152, 1.00462487, 1.01320257], [ 1.08025776, 0.99845838, 1.00113165]] expected = pd.DataFrame(d) result = pan.Ret_Index.ix['01-18-11':'01-21-11'][['GE', 'INTC', 'MSFT']] assert_almost_equal(result.values, expected.values)
def main(): # db = psql.get_db() # product_codes = db.prepare('''SELECT p.code AS code, p.id as id # FROM products p LEFT JOIN companies c ON p.company_id = c.id # WHERE c.sector IS NOT NULL # and p.id < 9354 # ORDER BY p.id''')() product_codes = get_components_yahoo('^DJI').index total = len(product_codes) cur = 0 products=[] logger.info('Start downloading of %d products.', len(product_codes)) for code in product_codes: cur += 1 try: product = DataReader(code, 'yahoo', start=date_from, end=date_to) except: logger.warn('(%d/%d) Fail downloading %s.', cur, total, code) continue product.code = code products.append(product) logger.info('(%d/%d) Downloaded %s.', cur, total, code) logger.info('Download complete.') return opt(products)
def test_get_components_dax(self): raise nose.SkipTest('unreliable test, receive partial components back for dax') df = web.get_components_yahoo('^GDAXI') #DAX self.assertIsInstance(df, pd.DataFrame) self.assertEqual(len(df), 30) self.assertEqual(df[df.name.str.contains('adidas', case=False)].index, 'ADS.DE')
def test_get_components(self): df = web.get_components_yahoo('^DJI') #Dow Jones assert isinstance(df, pd.DataFrame) assert len(df) == 30 df = web.get_components_yahoo('^GDAXI') #DAX assert isinstance(df, pd.DataFrame) assert len(df) == 30 assert df[df.name.str.contains('adidas', case=False)].index == 'ADS.DE' df = web.get_components_yahoo('^NDX') #NASDAQ-100 assert isinstance(df, pd.DataFrame) #assert len(df) == 100 #Usual culprits, should be around for a while assert 'AAPL' in df.index assert 'GOOG' in df.index assert 'AMZN' in df.index
def test_get_components(self): df = web.get_components_yahoo("^DJI") # Dow Jones assert isinstance(df, pd.DataFrame) assert len(df) == 30 df = web.get_components_yahoo("^GDAXI") # DAX assert isinstance(df, pd.DataFrame) assert len(df) == 30 assert df[df.name.str.contains("adidas", case=False)].index == "ADS.DE" df = web.get_components_yahoo("^NDX") # NASDAQ-100 assert isinstance(df, pd.DataFrame) # assert len(df) == 100 # Usual culprits, should be around for a while assert "AAPL" in df.index assert "GOOG" in df.index assert "AMZN" in df.index
def test_get_components_nasdaq_100(self): """as of 7/12/13 the conditional will test false because the link is invalid""" df = web.get_components_yahoo("^NDX") # NASDAQ-100 assert isinstance(df, pd.DataFrame) if len(df) > 1: # Usual culprits, should be around for a while assert "AAPL" in df.index assert "GOOG" in df.index assert "AMZN" in df.index else: expected = DataFrame({"exchange": "N/A", "name": "@^NDX"}, index=["@^NDX"]) assert_frame_equal(df, expected)
def test_get_components_nasdaq_100(self): """as of 7/12/13 the conditional will test false because the link is invalid""" df = web.get_components_yahoo('^NDX') #NASDAQ-100 assert isinstance(df, pd.DataFrame) if len(df) > 1: # Usual culprits, should be around for a while assert 'AAPL' in df.index assert 'GOOG' in df.index assert 'AMZN' in df.index else: expected = DataFrame({'exchange': 'N/A', 'name': '@^NDX'}, index=['@^NDX']) assert_frame_equal(df, expected)
def test_get_components_nasdaq_100(self): # as of 7/12/13 the conditional will test false because the link is invalid raise nose.SkipTest('unreliable test, receive partial components back for nasdaq_100') df = web.get_components_yahoo('^NDX') #NASDAQ-100 self.assertIsInstance(df, pd.DataFrame) if len(df) > 1: # Usual culprits, should be around for a while self.assertTrue('AAPL' in df.index) self.assertTrue('GOOG' in df.index) self.assertTrue('AMZN' in df.index) else: expected = DataFrame({'exchange': 'N/A', 'name': '@^NDX'}, index=['@^NDX']) assert_frame_equal(df, expected)
def test_get_data(self): import numpy as np #single symbol #http://finance.yahoo.com/q/hp?s=GOOG&a=09&b=08&c=2010&d=09&e=10&f=2010&g=d df = web.get_data_yahoo('GOOG') assert df.Volume.ix['OCT-08-2010'] == 2859200 sl = ['AAPL', 'AMZN', 'GOOG'] pan = web.get_data_yahoo(sl, '2012') ts = pan.Close.GOOG.index[pan.Close.AAPL > pan.Close.GOOG] assert ts[0].dayofyear == 96 dfi = web.get_components_yahoo('^DJI') pan = web.get_data_yahoo(dfi, 'JAN-01-12', 'JAN-31-12') expected = [19.02, 28.23, 25.39] result = pan.Close.ix['01-18-12'][['GE', 'MSFT', 'INTC']].tolist() assert result == expected # sanity checking t= np.array(result) assert np.issubdtype(t.dtype, np.floating) assert t.shape == (3,) expected = [[ 18.99, 28.4 , 25.18], [ 18.58, 28.31, 25.13], [ 19.03, 28.16, 25.52], [ 18.81, 28.82, 25.87]] result = pan.Open.ix['Jan-15-12':'Jan-20-12'][['GE', 'MSFT', 'INTC']].values assert (result == expected).all() #Check ret_index pan = web.get_data_yahoo(['GE', 'INTC', 'IBM'], '1977', '1987', ret_index=True) tstamp = pan.Ret_Index.INTC.first_valid_index() result = pan.Ret_Index.ix[tstamp]['INTC'] expected = 1.0 assert result == expected # sanity checking t= np.array(pan) assert np.issubdtype(t.dtype, np.floating)
def test_get_data(self): import numpy as np # single symbol # http://finance.yahoo.com/q/hp?s=GOOG&a=09&b=08&c=2010&d=09&e=10&f=2010&g=d df = web.get_data_yahoo("GOOG") assert df.Volume.ix["OCT-08-2010"] == 2859200 sl = ["AAPL", "AMZN", "GOOG"] pan = web.get_data_yahoo(sl, "2012") ts = pan.Close.GOOG.index[pan.Close.AAPL > pan.Close.GOOG] assert ts[0].dayofyear == 96 dfi = web.get_components_yahoo("^DJI") pan = web.get_data_yahoo(dfi, "JAN-01-12", "JAN-31-12") expected = [19.02, 28.23, 25.39] result = pan.Close.ix["01-18-12"][["GE", "MSFT", "INTC"]].tolist() assert result == expected # sanity checking t = np.array(result) assert np.issubdtype(t.dtype, np.floating) assert t.shape == (3,) expected = [[18.99, 28.4, 25.18], [18.58, 28.31, 25.13], [19.03, 28.16, 25.52], [18.81, 28.82, 25.87]] result = pan.Open.ix["Jan-15-12":"Jan-20-12"][["GE", "MSFT", "INTC"]].values assert (result == expected).all() # Check ret_index pan = web.get_data_yahoo(["GE", "INTC", "IBM"], "1977", "1987", ret_index=True) tstamp = pan.Ret_Index.INTC.first_valid_index() result = pan.Ret_Index.ix[tstamp]["INTC"] expected = 1.0 assert result == expected # sanity checking t = np.array(pan) assert np.issubdtype(t.dtype, np.floating)
def test_get_data(self): #single symbol #http://finance.yahoo.com/q/hp?s=GOOG&a=09&b=08&c=2010&d=09&e=10&f=2010&g=d df = web.get_data_yahoo('GOOG') assert df.Volume.ix['OCT-08-2010'] == 2859200 sl = ['AAPL', 'AMZN', 'GOOG'] pan = web.get_data_yahoo(sl, '2012') ts = pan.Close.GOOG.index[pan.Close.AAPL > pan.Close.GOOG] assert ts[0].dayofyear == 96 dfi = web.get_components_yahoo('^DJI') pan = web.get_data_yahoo(dfi, 'JAN-01-12', 'JAN-31-12') expected = [19.02, 28.23, 25.39] result = pan.Close.ix['01-18-12'][['GE', 'MSFT', 'INTC']].tolist() assert result == expected pan = web.get_data_yahoo(dfi, 'JAN-01-12', 'JAN-31-12', adjust_price=True) expected = [18.38, 27.45, 24.54] result = pan.Close.ix['01-18-12'][['GE', 'MSFT', 'INTC']].tolist() assert result == expected pan = web.get_data_yahoo(dfi, '2011', ret_index=True) d = [[1.01757469, 1.01130524, 1.02414183], [1.00292912, 1.00770812, 1.01735194], [1.00820152, 1.00462487, 1.01320257], [1.08025776, 0.99845838, 1.00113165]] expected = pd.DataFrame(d) result = pan.Ret_Index.ix['01-18-11':'01-21-11'][[ 'GE', 'INTC', 'MSFT' ]] assert_almost_equal(result.values, expected.values)
def test_get_components_dax(self): df = web.get_components_yahoo('^GDAXI') #DAX assert isinstance(df, pd.DataFrame) self.assertEqual(len(df), 30) self.assertEqual(df[df.name.str.contains('adidas', case=False)].index, 'ADS.DE')
def idx_components(idx): return get_components_yahoo(idx)
def test_get_components_dow_jones(self): df = web.get_components_yahoo('^DJI') #Dow Jones assert isinstance(df, pd.DataFrame) self.assertEqual(len(df), 30)
def test_get_components_dow_jones(self): raise nose.SkipTest('unreliable test, receive partial components back for dow_jones') df = web.get_components_yahoo('^DJI') #Dow Jones self.assertIsInstance(df, pd.DataFrame) self.assertEqual(len(df), 30)