我正在开发一个将库存数据存储在数组中的程序。该计划仍在进行中。该程序从雅虎财务中提取数据,数据存储在一个numpy数组中。如果库存达到新的高位,则会弹出警报。
以下是一些问题:
为什么我必须使用numpy数组来执行此函数而不是常规列表?换句话说,numpy数组的优点或特征是什么?
您能告诉我如何了解有关numpy.loadtxt的更多信息吗?我试着寻找http://www.numpy.org
非常感谢,以下是我到目前为止的计划......
import urllib2
import time
import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
def pullData(stock):
try:
print 'Pulling ' + stock
print str(datetime.datetime.fromtimestamp(int(time.time())).strftime('%Y-%m-%d %H:%M:%S'))
urltovisit = 'http://chartapi.finance.yahoo.com/instrument/1.0/'+stock+'/chartdata;type=quote;range=1d/csv'
stockFile = []
try:
f = urllib2.urlopen(urltovisit)
sourceCode = f.read().decode('utf-8')
splitSource = sourceCode.split('\n')
for eachLine in splitSource:
splitLine = eachLine.split(',')
fixMe = splitLine[0]
if len(splitLine) == 6:
if 'values' not in eachLine:
fixed = eachLine.replace(fixMe,str(datetime.datetime.fromtimestamp(int(fixMe)).strftime('%Y-%m-%d %H:%M:%S')))
stockFile.append(fixed)
except Exception, e:
print str(e), 'failed to organize pulled data'
date, closep, highp, lowp, openp, volume = np.loadtxt(stockFile,delimiter=',', unpack=True, converters={ 0: mdates.strpdate2num('%Y-%m-%d %H:%M:%S')})
if highp[-1] == max(highp):
print stock + ' New high ' + str(max(highp))
else:
print ' no new high '
except Exception, e:
print str(e), 'failed to pull pricing data'
stockName = raw_input('Enter a stock: ')
pullData(stockName)