Re: [Tutor] Does matplotlib.finance still work?
Thanks Alan. You are right, the finance.py is there. I think quotes_historical_yahoo is from 3 years ago. It is replaced by quotes_historical_yahoo_ochl and quotes_historical_yahoo_ohlc. But the problem is, yahoo finance has also changed its API (2 years ago?). It is a complete overhaul. quotes_historical_yahoo_ochl has not kept up. Thus, the error message. help(quotes_historical_yahoo_ochl) -- Help on function quotes_historical_yahoo_ochl in module matplotlib.finance: quotes_historical_yahoo_ochl(ticker, date1, date2, asobject=False, adjusted=True, cachename=None) Get historical data for ticker between date1 and date2. See :func:`parse_yahoo_historical` for explanation of output formats and the *asobject* and *adjusted* kwargs. Parameters -- ticker : str stock ticker date1 : sequence of form (year, month, day), `datetime`, or `date` start date date2 : sequence of form (year, month, day), `datetime`, or `date` end date cachename : str or `None` is the name of the local file cache. If None, will default to the md5 hash or the url (which incorporates the ticker and date range) Examples >>> sp = f.quotes_historical_yahoo_ochl('^GSPC', d1, d2, asobject=True, adjusted=True) >>> returns = (sp.open[1:] - sp.open[:-1])/sp.open[1:] >>> [n,bins,patches] = hist(returns, 100) >>> mu = mean(returns) >>> sigma = std(returns) >>> x = normpdf(bins, mu, sigma) >>> plot(bins, x, color='red', lw=2) Thank you very much! On Fri, Aug 25, 2017 at 1:01 PM, Alan Gauld via Tutor wrote: > On 25/08/17 15:19, C W wrote: > > I did not mean to leave out the error message, it was very long. > > That just means it has a lot of information in it :-) > > > I think the package has been removed. > > I don;t think so based on the traceback... > > quotes = quotes_historical_yahoo_ochl('APX', start, ... ) > > -- > > TypeError: quotes_historical_yahoo_ochl() missing 1 required positional > > argument: 'date2' > > Did you check what parameters were required for this function? > The error says you are missing one. > > > /Users/anaconda/lib/python3.6/site-packages/matplotlib/finance.py in > > Note the filename. That suggests finance.py is still there. > > > quotes_historical_yahoo_ochl(ticker, date1, date2, asobject, adjusted, > > cachename) 411 return _quotes_historical_yahoo(ticker, date1, date2, > > asobject=asobject, 412 adjusted=adjusted, cachename=cachename, --> 413 > > ochl=True) 414 415 > > /Users/anaconda/lib/python3.6/site-packages/matplotlib/finance.py in > > _quotes_historical_yahoo(ticker, date1, date2, asobject, adjusted, > > cachename, ochl) 501 # warnings.warn("Recommend changing to > asobject=None") > > 502 --> 503 fh = fetch_historical_yahoo(ticker, date1, date2, cachename) > 504 > > 505 try: > > Some warnings there that might be relevant, I don't know > anything about the package or function. > > You could try running the help() function: > > >>> help(quotes_historical_yahoo_ochl) > > And see if it shows anything useful. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Does matplotlib.finance still work?
On 25/08/17 15:19, C W wrote: > I did not mean to leave out the error message, it was very long. That just means it has a lot of information in it :-) > I think the package has been removed. I don;t think so based on the traceback... quotes = quotes_historical_yahoo_ochl('APX', start, ... ) > -- > TypeError: quotes_historical_yahoo_ochl() missing 1 required positional > argument: 'date2' Did you check what parameters were required for this function? The error says you are missing one. > /Users/anaconda/lib/python3.6/site-packages/matplotlib/finance.py in Note the filename. That suggests finance.py is still there. > quotes_historical_yahoo_ochl(ticker, date1, date2, asobject, adjusted, > cachename) 411 return _quotes_historical_yahoo(ticker, date1, date2, > asobject=asobject, 412 adjusted=adjusted, cachename=cachename, --> 413 > ochl=True) 414 415 > /Users/anaconda/lib/python3.6/site-packages/matplotlib/finance.py in > _quotes_historical_yahoo(ticker, date1, date2, asobject, adjusted, > cachename, ochl) 501 # warnings.warn("Recommend changing to asobject=None") > 502 --> 503 fh = fetch_historical_yahoo(ticker, date1, date2, cachename) 504 > 505 try: Some warnings there that might be relevant, I don't know anything about the package or function. You could try running the help() function: >>> help(quotes_historical_yahoo_ochl) And see if it shows anything useful. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Does matplotlib.finance still work?
I did not mean to leave out the error message, it was very long. I think the package has been removed. Anyways, it's here: >>> quotes = quotes_historical_yahoo_ochl('APX', start, ... ) -- TypeError: quotes_historical_yahoo_ochl() missing 1 required positional argument: 'date2' --- TypeError Traceback (most recent call last) in () > 1 quotes = quotes_historical_yahoo_ochl('APX', start, 2 ) TypeError: quotes_historical_yahoo_ochl() missing 1 required positional argument: 'date2' -- -- >>> -- >>> quotes = quotes_historical_yahoo_ochl('APX', start, today) -- URLError: --- gaierror Traceback (most recent call last) /Users/anaconda/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args) 1317 h.request(req.get_method(), req.selector, req.data, headers, -> 1318 encode_chunked=req.has_header('Transfer-encoding')) 1319 except OSError as err: # timeout error /Users/anaconda/lib/python3.6/http/client.py in request(self, method, url, body, headers, encode_chunked) 1238 """Send a complete request to the server.""" -> 1239 self._send_request(method, url, body, headers, encode_chunked) 1240 /Users/anaconda/lib/python3.6/http/client.py in _send_request(self, method, url, body, headers, encode_chunked) 1284 body = _encode(body, 'body') -> 1285 self.endheaders(body, encode_chunked=encode_chunked) 1286 /Users/anaconda/lib/python3.6/http/client.py in endheaders(self, message_body, encode_chunked) 1233 raise CannotSendHeader() -> 1234 self. _send_output(message_body, encode_chunked=encode_chunked) 1235 /Users/anaconda/lib/python3.6/http/client.py in _send_output(self, message_body, encode_chunked) 1025 del self._buffer[:] -> 1026 self.send(msg ) 1027 /Users/anaconda/lib/python3.6/http/client.py in send(self, data) 963 if self .auto_open: --> 964 self.connect() 965 else: /Users/anaconda/lib/python3.6/http/client.py in connect(self) 935 self.sock = self._create_connection( --> 936 (self.host,self.port), self.timeout, self.source_address) 937 self.sock.setsockopt(socket.IPPROTO_TCP, socket. TCP_NODELAY, 1) /Users/anaconda/lib/python3.6/socket.py in create_connection(address, timeout, source_address) 703 err = None --> 704 for res in getaddrinfo(host, port, 0, SOCK_STREAM): 705 af, socktype, proto, canonname, sa = res /Users/anaconda/lib/python3.6/socket.py in getaddrinfo(host, port, family, type, proto, flags) 742 addrlist = [] --> 743 for res in _socket.getaddrinfo (host, port, family, type, proto, flags): 744 af, socktype, proto, canonname , sa = res gaierror: [Errno 8] nodename nor servname provided, or not known During handling of the above exception, another exception occurred: URLError Traceback (most recent call last) in () > 1 quotes = quotes_historical_yahoo_ochl('APX', start, today) /Users/anaconda/lib/python3.6/site-packages/matplotlib/finance.py in quotes_historical_yahoo_ochl(ticker, date1, date2, asobject, adjusted, cachename) 411 return _quotes_historical_yahoo(ticker, date1, date2, asobject=asobject, 412 adjusted=adjusted, cachename=cachename, --> 413 ochl=True) 414 415 /Users/anaconda/lib/python3.6/site-packages/matplotlib/finance.py in _quotes_historical_yahoo(ticker, date1, date2, asobject, adjusted, cachename, ochl) 501 # warnings.warn("Recommend changing to asobject=None") 502 --> 503 fh = fetch_historical_yahoo(ticker, date1, date2, cachename) 504 505 try: /Users/anaconda/lib/python3.6/site-packages/matplotlib/finance.py in fetch_historical_yahoo(ticker, date1, date2, cachename, dividends) 360 else: 361 mkdirs(os.path.abspath(os.path.dirname(cachename))) --> 362 with contextlib.closing(urlopen(url)) as urlfh: 363 with open(cachename, 'wb') as fh: 364 fh.write(urlfh.read()) /Users/anaconda/lib/python3.6/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context) 221 else: 222 opener = _opener --> 223 return opener.open(url, data, timeout) 224 225 def install_opener(opener ): /Users/anaconda/lib/python3.6/urllib/request.py in open(self, fullurl, data, timeout) 524 req = meth(req) 525 --> 526 response = self._open(req, data) 527 528 # post-process response /Users/anaconda/lib/python3.6/urllib/request.py in _open(self, req, data) 542 protocol = req.type 543 result = self._call_chain(self.handle_open, protocol, protocol + --> 544 '_open', req) 545 if result: 546 return result /Users/anaconda/lib/python3.6/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args) 502 for handler in handlers: 503 func = getattr( handler, meth_name) --> 504 result = func(*args) 505 if result is not None: 506 return result /Users/anaconda/lib/python3.6/urllib/request.py in http_open(self, req) 1344 1345 def http_open(self, req): -> 1346 return self.do_open(http.client. HTTPConnec
Re: [Tutor] Does matplotlib.finance still work?
On 24/08/2017 18:46, Alan Gauld via Tutor wrote: On 24/08/17 14:51, C W wrote: I have the following code, I get an error at the first line. So don't make us guess. What is the error(full text please)? from matplotlib.finance import quotes_historical_yahoo_ochl And what does a dir() show for matplotlib.finance? Are you sure the name is spelled right etc? I have heard this package is either upgraded or replaced. If so, what do you recommend? Contact its author perhaps? Is this the answer, perhaps. >>>import matplotlib >>>dir(matplotlib.finance) >>>Traceback (most recent call last): File "", line 1, in dir(matplotlib.finance) AttributeError: module 'matplotlib' has no attribute 'finance' Thanks to Alan G? for his excellent teaching. -- Sydney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Does matplotlib.finance still work?
On 24/08/17 14:51, C W wrote: > I have the following code, I get an error at the first line. So don't make us guess. What is the error(full text please)? > from matplotlib.finance import quotes_historical_yahoo_ochl And what does a dir() show for matplotlib.finance? Are you sure the name is spelled right etc? > I have heard this package is either upgraded or replaced. If so, what do > you recommend? Contact its author perhaps? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Does matplotlib.finance still work?
Hello all, I have the following code, I get an error at the first line. from matplotlib.finance import quotes_historical_yahoo_ochl from datetime import date import pandas as pd today = date.today() start = date(today.year-1, today.month, today.day) quotes = quotes_historical_yahoo_ochl('APX', start, today) I have heard this package is either upgraded or replaced. If so, what do you recommend? Thanks! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor