Without using matplotlib finance module. I like to get the url data into a numpy array. where I can to column heading to do math. Like:
prices = r.adj_close
From: http://matplotlib.sourceforge.net/examples/pylab_examples/finance_work2.html
except I dont want to use the:
fh = finance.fetch_historical_yahoo(ticker, startdate, enddate)
# a numpy record array with fields: date, open, high, low, close, volume, adj_close)
r = mlab.csv2rec(fh); fh.close()
r.sort()
Using manually create the url:
url = http://ichart.yahoo.com/table.csv?a=2&c=2011&b=30&e=7&d=7&g=d&f=2011&s=msft&ignore=.csv
f = urllib.urlopen(url)
fr = f.read()
hdata = np.asarray(fr, dtype='object')
prices = hdata.adj_close
print prices
It is also possible to use
S10
to tell numpy that the first entity is a string with length 10. This way, you don't need to use lambda.For more info on f, f8, u4, S, u8 etc, visit this link.
If you don't want to load
pylab
for time string conversion, you can use themktime
function as a lambda:use numpy.loadtxt() to load csv:
the first column is date, so use pylab.datestr2num to convert it to number.