Python, Yahoo API

Python, Yahoo API

So I found the solution.

You can download it under the Downloads section.

#Yahoo API

#!pip install fix_yahoo_finance
import fix_yahoo_finance as yf
import pandas_datareader as pdr
import datetime
import pandas as pd

yf.pdr_override() # <== that’s all it takes :-)

def get(tickers, startdate, enddate):
def data(ticker):
return (pdr.get_data_yahoo(ticker, start=startdate, end=enddate))
datas = map (data, tickers)
return(pd.concat(datas, keys=tickers, names=[‘Ticker’, ‘Date’]))

#tickers = [‘AAPL’, ‘MSFT’, ‘IBM’, ‘GOOG’]
tickers = [‘^GSPC’]
all_data = get(tickers, datetime.datetime(2006, 10, 1), datetime.datetime(2012, 1, 1))

 

import matplotlib.pyplot as plt
import numpy as np

sp500_close = np.array(all_data[‘Adj Close’])

plt.plot(sp500_close)
plt.show()

%d bloggers like this: