77
77
# #############################################################################
78
78
# Retrieve the data from Internet
79
79
80
+
80
81
def quotes_historical_google (symbol , date1 , date2 ):
81
82
"""Get the historical data from Google finance.
82
83
@@ -102,15 +103,15 @@ def quotes_historical_google(symbol, date1, date2):
102
103
'output' : 'csv'
103
104
})
104
105
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 )
114
115
115
116
116
117
# 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):
182
183
quotes_historical_google (symbol , d1 , d2 ) for symbol in symbols
183
184
]
184
185
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 ])
187
188
188
189
# The daily variations of the quotes are what carry most information
189
190
variation = close_prices - open_prices
0 commit comments