7777# #############################################################################
7878# Retrieve the data from Internet
7979
80+
8081def quotes_historical_google (symbol , date1 , date2 ):
8182 """Get the historical data from Google finance.
8283
@@ -102,15 +103,15 @@ def quotes_historical_google(symbol, date1, date2):
102103 'output' : 'csv'
103104 })
104105 url = 'http://www.google.com/finance/historical?' + params
105- with urlopen (url ) as response :
106- dtype = {
107- 'names' : ['date' , 'open' , 'high' , 'low' , 'close' , 'volume' ],
108- 'formats' : ['object' , 'f4' , 'f4' , 'f4' , 'f4' , 'f4' ]
109- }
110- converters = {0 : lambda s : datetime .strptime (s .decode (), '%d-%b-%y' )}
111- return np .genfromtxt (response , delimiter = ',' , skip_header = 1 ,
112- dtype = dtype , converters = converters ,
113- missing_values = '-' , filling_values = - 1 )
106+ response = urlopen (url )
107+ dtype = {
108+ 'names' : ['date' , 'open' , 'high' , 'low' , 'close' , 'volume' ],
109+ 'formats' : ['object' , 'f4' , 'f4' , 'f4' , 'f4' , 'f4' ]
110+ }
111+ converters = {0 : lambda s : datetime .strptime (s .decode (), '%d-%b-%y' )}
112+ return np .genfromtxt (response , delimiter = ',' , skip_header = 1 ,
113+ dtype = dtype , converters = converters ,
114+ missing_values = '-' , filling_values = - 1 )
114115
115116
116117# Choose a time period reasonably calm (not too long ago so that we get
@@ -182,8 +183,8 @@ def quotes_historical_google(symbol, date1, date2):
182183 quotes_historical_google (symbol , d1 , d2 ) for symbol in symbols
183184]
184185
185- close_prices = np .stack ([q ['close' ] for q in quotes ])
186- open_prices = np .stack ([q ['open' ] for q in quotes ])
186+ close_prices = np .vstack ([q ['close' ] for q in quotes ])
187+ open_prices = np .vstack ([q ['open' ] for q in quotes ])
187188
188189# The daily variations of the quotes are what carry most information
189190variation = close_prices - open_prices
0 commit comments