-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG] Updated plot_stock_market.py to use Google Finance #9010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MRG] Updated plot_stock_market.py to use Google Finance #9010
Conversation
The implementations is intentionally very basic not to distract the users from the example. Specifically unlike ``quotes_historical_yahoo_ochl`` it does not cache downloaded data. I also had to remove some symbols because the have no data on Google for the specified date interval. These are WBA, LMT, KFT and MTU. Closes scikit-learn#8899
Nice thanks for picking this up! |
'output': 'csv' | ||
}) | ||
url = 'http://www.google.com/finance/historical?' + params | ||
print(url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not print the url.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this is leftover debugging code. Will remove.
doc/conf.py
Outdated
@@ -241,8 +241,7 @@ | |||
'matplotlib': 'http://matplotlib.org', | |||
'numpy': 'http://docs.scipy.org/doc/numpy-1.8.1', | |||
'scipy': 'http://docs.scipy.org/doc/scipy-0.13.3/reference'}, | |||
'expected_failing_examples': [ | |||
'../examples/applications/plot_stock_market.py'] | |||
'expected_failing_examples': [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can remove the expected_failing_examples
but please double-check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. The key was added in this commit: 9759019.
I edited your title to have |
@GaelVaroquaux since you are the author of the example, maybe you can have a quick look at the differences in the plots? |
I think the differences are expected, since I had to change the data set (Google does not have the same data). However, I cannot comment whether the new plot makes sense. |
@@ -131,9 +161,7 @@ | |||
'CSCO': 'Cisco', | |||
'TXN': 'Texas instruments', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while we're at it, the i
should probably be uppercase, same for the 'e' in American Express, and I think "Mc Donalds" should be "McDonald's".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
open = np.array([q.open for q in quotes]).astype(np.float) | ||
close = np.array([q.close for q in quotes]).astype(np.float) | ||
close = np.stack([q['close'] for q in quotes]) | ||
open = np.stack([q['open'] for q in quotes]) | ||
|
||
# The daily variations of the quotes are what carry most information | ||
variation = close - open |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, not this pr's fault, but open is a reserved keyword in python, could we rename these close_quote
/ open_quote
or whatever the explicit finance terms are?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close_prices
/open_prices
seems fine with me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
except ImportError: | ||
# quotes_historical_yahoo_ochl was named quotes_historical_yahoo before matplotlib 1.4 | ||
from matplotlib.finance import quotes_historical_yahoo as quotes_historical_yahoo_ochl | ||
from matplotlib import pyplot as plt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason for changing this import from how it was?
We have it both ways in the codebase, but overwhelmingly more common in the first way. There should be no difference so it's not a big deal, just curious why you changed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a matter of personal preference. I'll revert it back, it is unrelated to the PR.
The code itself and the new plot look good to me. We still have similar clusters, e.g., most of the defense contractors. I think the only question is whether we need to cache the data or not, probably only for the sake of CI. If so, we might as well add the downloader to the datasets module... |
The example takes ~20s to run on my laptop, including download, so my take on it is not to bother about these aspects. |
And BTW thinking about it a bit more the data was not cached previously by the CIs since IIRC it was downloaded inside |
very good points. For simplicity let's leave it like this then. |
Not sure why Circle failed. Rebuilding. Cancelling travis and appveyour as irrelevant. |
Circle is happy thx @superbobry i'll fix the import matplotlib.pyplot as plt in master directly |
…n#9010) * DOC updated plot_stock_market.py to use Google Finance The implementations is intentionally very basic not to distract the users from the example. Specifically unlike ``quotes_historical_yahoo_ochl`` it does not cache downloaded data. I also had to remove some symbols because the have no data on Google for the specified date interval. These are WBA, LMT, KFT and MTU. Closes scikit-learn#8899 * DOC removed plot_stock_market.py from expected failing examples * Addressed review comments * Addressed another pass of review comments
…n#9010) * DOC updated plot_stock_market.py to use Google Finance The implementations is intentionally very basic not to distract the users from the example. Specifically unlike ``quotes_historical_yahoo_ochl`` it does not cache downloaded data. I also had to remove some symbols because the have no data on Google for the specified date interval. These are WBA, LMT, KFT and MTU. Closes scikit-learn#8899 * DOC removed plot_stock_market.py from expected failing examples * Addressed review comments * Addressed another pass of review comments
* Fix tests on numpy master (#7946) Until now we were in a edge case on assert_array_equal * Fix tests on numpy master (#8355) numpy.apply_along_axis has changed behaviour when the function passed in returns a 2d array * [MRG] Updated plot_stock_market.py to use Google Finance (#9010) * DOC updated plot_stock_market.py to use Google Finance The implementations is intentionally very basic not to distract the users from the example. Specifically unlike ``quotes_historical_yahoo_ochl`` it does not cache downloaded data. I also had to remove some symbols because the have no data on Google for the specified date interval. These are WBA, LMT, KFT and MTU. Closes #8899 * DOC removed plot_stock_market.py from expected failing examples * Addressed review comments * Addressed another pass of review comments * [MRG] Remove DeprecationWarnings in examples due to using floats instead of ints (#8040)
|
||
open = np.array([q.open for q in quotes]).astype(np.float) | ||
close = np.array([q.close for q in quotes]).astype(np.float) | ||
close_prices = np.stack([q['close'] for q in quotes]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stack was introduced in numpy 1.10, not present in our minimum requirement 1.8.2
'output': 'csv' | ||
}) | ||
url = 'http://www.google.com/finance/historical?' + params | ||
with urlopen(url) as response: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't work in python2.7
…n#9010) * DOC updated plot_stock_market.py to use Google Finance The implementations is intentionally very basic not to distract the users from the example. Specifically unlike ``quotes_historical_yahoo_ochl`` it does not cache downloaded data. I also had to remove some symbols because the have no data on Google for the specified date interval. These are WBA, LMT, KFT and MTU. Closes scikit-learn#8899 * DOC removed plot_stock_market.py from expected failing examples * Addressed review comments * Addressed another pass of review comments
…n#9010) * DOC updated plot_stock_market.py to use Google Finance The implementations is intentionally very basic not to distract the users from the example. Specifically unlike ``quotes_historical_yahoo_ochl`` it does not cache downloaded data. I also had to remove some symbols because the have no data on Google for the specified date interval. These are WBA, LMT, KFT and MTU. Closes scikit-learn#8899 * DOC removed plot_stock_market.py from expected failing examples * Addressed review comments * Addressed another pass of review comments
…n#9010) * DOC updated plot_stock_market.py to use Google Finance The implementations is intentionally very basic not to distract the users from the example. Specifically unlike ``quotes_historical_yahoo_ochl`` it does not cache downloaded data. I also had to remove some symbols because the have no data on Google for the specified date interval. These are WBA, LMT, KFT and MTU. Closes scikit-learn#8899 * DOC removed plot_stock_market.py from expected failing examples * Addressed review comments * Addressed another pass of review comments
…n#9010) * DOC updated plot_stock_market.py to use Google Finance The implementations is intentionally very basic not to distract the users from the example. Specifically unlike ``quotes_historical_yahoo_ochl`` it does not cache downloaded data. I also had to remove some symbols because the have no data on Google for the specified date interval. These are WBA, LMT, KFT and MTU. Closes scikit-learn#8899 * DOC removed plot_stock_market.py from expected failing examples * Addressed review comments * Addressed another pass of review comments
…n#9010) * DOC updated plot_stock_market.py to use Google Finance The implementations is intentionally very basic not to distract the users from the example. Specifically unlike ``quotes_historical_yahoo_ochl`` it does not cache downloaded data. I also had to remove some symbols because the have no data on Google for the specified date interval. These are WBA, LMT, KFT and MTU. Closes scikit-learn#8899 * DOC removed plot_stock_market.py from expected failing examples * Addressed review comments * Addressed another pass of review comments
…n#9010) * DOC updated plot_stock_market.py to use Google Finance The implementations is intentionally very basic not to distract the users from the example. Specifically unlike ``quotes_historical_yahoo_ochl`` it does not cache downloaded data. I also had to remove some symbols because the have no data on Google for the specified date interval. These are WBA, LMT, KFT and MTU. Closes scikit-learn#8899 * DOC removed plot_stock_market.py from expected failing examples * Addressed review comments * Addressed another pass of review comments
…n#9010) * DOC updated plot_stock_market.py to use Google Finance The implementations is intentionally very basic not to distract the users from the example. Specifically unlike ``quotes_historical_yahoo_ochl`` it does not cache downloaded data. I also had to remove some symbols because the have no data on Google for the specified date interval. These are WBA, LMT, KFT and MTU. Closes scikit-learn#8899 * DOC removed plot_stock_market.py from expected failing examples * Addressed review comments * Addressed another pass of review comments
Reference Issue
Fixes #8899.
What does this implement/fix? Explain your changes.
This PR replaces a dependency on
quotes_historical_yahoo_ochl
with a custom wrapper over Google Finance API.
The implementations is intentionally very basic not to distract the users
from the example. Specifically unlike
quotes_historical_yahoo_ochl
itdoes not cache downloaded data.
Any other comments?
I had to remove some symbols because the have no data on Google for
the specified date interval. These are WBA, LMT, KFT and MTU.