Skip to content

Instantly share code, notes, and snippets.

@umitanuki
Last active August 22, 2018 20:53
Show Gist options
  • Save umitanuki/11f0260b3a144d0cdfec23c5a5f20a5c to your computer and use it in GitHub Desktop.
Save umitanuki/11f0260b3a144d0cdfec23c5a5f20a5c to your computer and use it in GitHub Desktop.
import iexfinance
import pandas as pd
def iex_charts(symbols):
partlen = 99
result = {}
for i in range(0, len(symbols), partlen):
charts = iexfinance.Stock(symbols[i:i+partlen]).get_chart(range='1m')
if type(charts) == list:
charts = {symbols[i]: charts}
for symbol, data in charts.items():
df = pd.DataFrame(data)
df.date = pd.to_datetime(df.date)
df.set_index('date', inplace=True)
df.index.names = ['epoch']
df.index = df.index.tz_localize('America/New_York')
result[symbol] = df
return result
def get_closes(constituents):
symbols = list(constituents.columns)
charts = iex_charts(symbols)
return pd.DataFrame({symbol: df.close for symbol, df in charts.items()})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment