def get_stock_value(stock): start = dt.datetime(2010, 1, 1) end = dt.datetime.now() df = data.get_data_quandl(stock, start, end) values = list(df['Close']) labels = list(df.index) return values, labels
def get_symbol_returns_from_quandl(symbol, start=None, end=None): """ Wrapper for pandas.io.data.get_data_quandl(). Retrieves prices for symbol from quandl and computes returns based on adjusted closing prices. Parameters ---------- symbol : str Symbol name to load, e.g. 'SPY' start : pandas.Timestamp compatible, optional Start date of time period to retrieve end : pandas.Timestamp compatible, optional End date of time period to retrieve Returns ------- pandas.DataFrame Returns of symbol in requested period. """ px = web.get_data_quandl(symbol, start=start, end=end) rets = px[['AdjClose']] rets = rets.shift(-1) rets.iloc[-1]['AdjClose'] = px.tail(1)['AdjOpen'] rets = rets.shift(1) / rets - 1 rets = rets.dropna() rets.index = rets.index.to_datetime() rets.index = rets.index.tz_localize("UTC") rets.columns = [symbol] return rets
def test_db_tse_jp(self): # TSE/6758: Sony Corp. df = web.DataReader('TSE/6758', 'quandl', self.start10, self.end10, access_key=TEST_API_KEY) self.check_headers(df, ['Open', 'High', 'Low', 'Close', 'Volume']) assert df.Close.at[self.day10] == 5190.0 df2 = web.get_data_quandl('TSE/6758', self.start10, self.end10, api_key=TEST_API_KEY) assert_frame_equal(df, df2)
def test_db_tse_jp(self): # TSE/6758: Sony Corp. df = web.DataReader("TSE/6758", "quandl", self.start10, self.end10, api_key=TEST_API_KEY) self.check_headers(df, ["Open", "High", "Low", "Close", "Volume"]) assert df.Close.at[self.day10] == 5190.0 df2 = web.get_data_quandl("TSE/6758", self.start10, self.end10, api_key=TEST_API_KEY) assert_frame_equal(df, df2)
def _get(cls, symbol, date_from, date_to): quotes = get_data_quandl(symbol, date_from, date_to) quotes.sort_index(inplace=True) return quotes