Last active
August 22, 2018 20:53
-
-
Save umitanuki/11f0260b3a144d0cdfec23c5a5f20a5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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