Reputation: 153
Just trying to get this code to run its very basic straight out of out of Python for Finance
import datetime
import matplotlib.pyplot as plt
from matplotlib.finance import quotes_historical_yahoo_ochl
from matplotlib.dates import MonthLocator,DateFormatter
ticker='AAPL'
begdate = datetime.date( 2012, 1, 2)
enddate = datetime.date( 2013, 12, 5)
months = MonthLocator(range (1,13), bymonthday=1, interval = 3)
monthsFmt = DateFormatter("%b '%y")
x = quotes_historical_yahoo_ochl(ticker,begdate,enddate)
if len(x) == 0:
print ("found no quotes")
raise SystemExit
dates =[q[0] for q in x]
closes = [q[4] for q in x]
fig, ax = plt.subplots()
ax.plot_date(dates,closes, '-')
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(monthsFmt)
ax.xaxis.set_minor_locator(mondays)
ax.autoscale_view()
ax.grid(True)
fig.autofmt_xdate()
when it runs i get this error:
File "C:\ProgramData\Anaconda3\lib\urllib\request.py", line 1320, in do_open
raise URLError(err)
URLError: <urlopen error [Errno 11001] getaddrinfo failed>
Upvotes: 2
Views: 7531
Reputation: 494
the quotes_historical_yahoo_ochl
function with your parameters tries to get the values from http://ichart.yahoo.com/table.csv?a=0&b=2&c=2012&d=11&e=5&f=2013&s=AAPL&y=0&g=d&ignore=.csv
that does not work at the moment or anymore...
You could try with Value Viz as an experiment:
import requests
params = {'tickers': 'MSFT', 'date': '2017-06-09'}
r = requests.get('https://quantprice.herokuapp.com/api/v1.1/scoop/day', params=params)
print r.text
HTH
Upvotes: 4