Skip to content

Commit 5b26bc7

Browse files
committed
Pushing the docs to dev/ for branch: master, commit 8b53659e41b33a1dde79bd977fff092e1c412cbf
1 parent fe3f26d commit 5b26bc7

File tree

1,001 files changed

+3095
-3093
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,001 files changed

+3095
-3093
lines changed
-189 Bytes
Binary file not shown.
-189 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: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ def wrapper(*args, **kwargs):
8989
return wrapper
9090

9191

92-
def quotes_historical_google(symbol, start_date, end_date,
93-
expected=None):
92+
def quotes_historical_google(symbol, start_date, end_date):
9493
"""Get the historical data from Google finance.
9594
9695
Parameters
@@ -125,32 +124,35 @@ def quotes_historical_google(symbol, start_date, end_date,
125124
data = np.genfromtxt(response, delimiter=',', skip_header=1,
126125
dtype=dtype, converters=converters,
127126
missing_values='-', filling_values=-1)
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)
127+
min_date = min(data['date'], default=datetime.min.date())
128+
max_date = max(data['date'], default=datetime.max.date())
129+
start_end_diff = (end_date - start_date).days
130+
min_max_diff = (max_date - min_date).days
131+
data_is_fine = (
132+
start_date <= min_date <= end_date and
133+
start_date <= max_date <= end_date and
134+
start_end_diff - 7 <= min_max_diff <= start_end_diff)
135+
136+
if not data_is_fine:
137+
message = (
138+
'Data looks wrong for symbol {}, url {}\n'
139+
' - start_date: {}, end_date: {}\n'
140+
' - min_date: {}, max_date: {}\n'
141+
' - start_end_diff: {}, min_max_diff: {}'.format(
142+
symbol, url,
143+
start_date, end_date,
144+
min_date, max_date,
145+
start_end_diff, min_max_diff))
146+
raise RuntimeError(message)
145147
return data
146148

147149
# #############################################################################
148150
# Retrieve the data from Internet
149151

150152
# Choose a time period reasonably calm (not too long ago so that we get
151153
# high-tech firms, and before the 2008 crash)
152-
start_date = datetime(2003, 1, 2).date()
153-
end_date = datetime(2007, 12, 31).date()
154+
start_date = datetime(2003, 1, 1).date()
155+
end_date = datetime(2008, 1, 1).date()
154156

155157
symbol_dict = {
156158
'NYSE:TOT': 'Total',
@@ -216,13 +218,11 @@ def quotes_historical_google(symbol, start_date, end_date,
216218
# retry is used because quotes_historical_google can temporarily fail
217219
# for various reasons (e.g. empty result from Google API).
218220
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}
221221

222222
for symbol in symbols:
223223
print('Fetching quote history for %r' % symbol, file=sys.stderr)
224-
quotes.append(retry(quotes_historical_google)(symbol, start_date, end_date,
225-
expected=expected))
224+
quotes.append(retry(quotes_historical_google)(
225+
symbol, start_date, end_date))
226226

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

dev/_downloads/scikit-learn-docs.pdf

-1.02 KB
Binary file not shown.

0 commit comments

Comments
 (0)