Skip to content

Commit f3d8cf9

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 7425abcb0022fe42ff84dcb4fd36355da4fee5d7
1 parent e19ab35 commit f3d8cf9

File tree

1,033 files changed

+3173
-3138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,033 files changed

+3173
-3138
lines changed
505 Bytes
Binary file not shown.
498 Bytes
Binary file not shown.

dev/_downloads/plot_stock_market.ipynb

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dev/_downloads/plot_stock_market.py

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,64 +89,68 @@ def wrapper(*args, **kwargs):
8989
return wrapper
9090

9191

92-
def quotes_historical_google(symbol, date1, date2):
92+
def quotes_historical_google(symbol, start_date, end_date,
93+
expected=None):
9394
"""Get the historical data from Google finance.
9495
9596
Parameters
9697
----------
9798
symbol : str
9899
Ticker symbol to query for, for example ``"DELL"``.
99-
date1 : datetime.datetime
100+
start_date : datetime.datetime
100101
Start date.
101-
date2 : datetime.datetime
102+
end_date : datetime.datetime
102103
End date.
103104
104105
Returns
105106
-------
106107
X : array
107-
The columns are ``date`` -- datetime, ``open``, ``high``,
108+
The columns are ``date`` -- date, ``open``, ``high``,
108109
``low``, ``close`` and ``volume`` of type float.
109110
"""
110-
params = urlencode({
111+
params = {
111112
'q': symbol,
112-
'startdate': date1.strftime('%b %d, %Y'),
113-
'enddate': date2.strftime('%b %d, %Y'),
114-
'output': 'csv'
115-
})
116-
url = 'http://www.google.com/finance/historical?' + params
113+
'startdate': start_date.strftime('%Y-%m-%d'),
114+
'enddate': end_date.strftime('%Y-%m-%d'),
115+
'output': 'csv',
116+
}
117+
url = 'https://finance.google.com/finance/historical?' + urlencode(params)
117118
response = urlopen(url)
118119
dtype = {
119120
'names': ['date', 'open', 'high', 'low', 'close', 'volume'],
120121
'formats': ['object', 'f4', 'f4', 'f4', 'f4', 'f4']
121122
}
122-
converters = {0: lambda s: datetime.strptime(s.decode(), '%d-%b-%y')}
123+
converters = {
124+
0: lambda s: datetime.strptime(s.decode(), '%d-%b-%y').date()}
123125
data = np.genfromtxt(response, delimiter=',', skip_header=1,
124126
dtype=dtype, converters=converters,
125127
missing_values='-', filling_values=-1)
126-
expected_len_data = 1258
127-
len_data = len(data)
128-
min_date = data['date'].min()
129-
max_date = data['date'].max()
130-
if (len_data != expected_len_data or min_date != d1 or max_date != d2):
131-
message = (
132-
'Got wrong data for symbol {}, url {}\n'
133-
' - min_date should be {}, got {}\n'
134-
' - max_date should be {}, got {}\n'
135-
' - len(data) should be {}, got {}'.format(
136-
symbol, url,
137-
d1.date(), min_date.date(),
138-
d2.date(), max_date.date(),
139-
expected_len_data, len_data))
140-
raise ValueError(message)
128+
if expected is not None:
129+
len_data = len(data)
130+
min_date = min(data['date'], default=None)
131+
max_date = max(data['date'], default=None)
132+
if (len_data != expected['len_data'] or
133+
min_date != expected['min_date'] or
134+
max_date != expected['max_date']):
135+
message = (
136+
'Got wrong data for symbol {}, url {}\n'
137+
' - min_date should be {}, got {}\n'
138+
' - max_date should be {}, got {}\n'
139+
' - len(data) should be {}, got {}'.format(
140+
symbol, url,
141+
expected['min_date'], min_date,
142+
expected['max_date'], max_date,
143+
expected['len_data'], len_data))
144+
raise ValueError(message)
141145
return data
142146

143147
# #############################################################################
144148
# Retrieve the data from Internet
145149

146150
# Choose a time period reasonably calm (not too long ago so that we get
147151
# high-tech firms, and before the 2008 crash)
148-
d1 = datetime(2003, 1, 2)
149-
d2 = datetime(2007, 12, 31)
152+
start_date = datetime(2003, 1, 2).date()
153+
end_date = datetime(2007, 12, 31).date()
150154

151155
symbol_dict = {
152156
'NYSE:TOT': 'Total',
@@ -212,10 +216,13 @@ def quotes_historical_google(symbol, date1, date2):
212216
# retry is used because quotes_historical_google can temporarily fail
213217
# for various reasons (e.g. empty result from Google API).
214218
quotes = []
219+
# expected min_date, max_date and length for each stock timeseries
220+
expected = {'min_date': start_date, 'max_date': end_date, 'len_data': 1258}
215221

216222
for symbol in symbols:
217223
print('Fetching quote history for %r' % symbol, file=sys.stderr)
218-
quotes.append(retry(quotes_historical_google)(symbol, d1, d2))
224+
quotes.append(retry(quotes_historical_google)(symbol, start_date, end_date,
225+
expected=expected))
219226

220227
close_prices = np.vstack([q['close'] for q in quotes])
221228
open_prices = np.vstack([q['open'] for q in quotes])

dev/_downloads/scikit-learn-docs.pdf

-495 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)