本文整理汇总了Python中store.Store.get_all_stocks方法的典型用法代码示例。如果您正苦于以下问题:Python Store.get_all_stocks方法的具体用法?Python Store.get_all_stocks怎么用?Python Store.get_all_stocks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类store.Store
的用法示例。
在下文中一共展示了Store.get_all_stocks方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: analyze_bonus
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import get_all_stocks [as 别名]
def analyze_bonus():
s = Store()
codes = s.get_all_stocks()
arr = []
for code in codes:
print "analyzing %s..."%(code)
bonus = s.get_bonus(code)
if len(bonus) > 0:
bonus = bonus.set_index("announce_date")
bonus = bonus.sort_index()
else:
continue
finance = s.get_finance(code)
if len(finance) > 0:
finance = finance.set_index("date")
finance = finance.sort_index()
sql = "select MIN(date) from market where code = \"%s\""%(code)
cursor = conn.cursor()
count = cursor.execute(sql)
if count == 0:
continue
start_date = cursor.fetchone()[0]
cursor.close()
bonus_index = 0
for i in range(0, len(finance)):
if bonus_index >= len(bonus):
break;
bonus_date = bonus.index[bonus_index]
date = finance.index[i]
if date < start_date:
continue
next_date = datetime.date(2199, 12, 31)
if i < len(finance) - 1:
next_date = finance.index[i + 1]
if bonus_date > date and bonus_date <= next_date:
f = finance.iloc[i]
b = bonus.iloc[bonus_index]
dict = {}
dict["date"] = date
dict["announce_date"] = bonus_date
dict["code"] = f.code
dict["fund"] = f.fund_per_share
dict["total"] = b.bonus_stock + b.tranadd_stock
dict["exright_date"] = b.exright_date
arr.append(dict)
bonus_index = bonus_index + 1
return pandas.DataFrame(arr)
示例2: analyze
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import get_all_stocks [as 别名]
def analyze():
s = Store()
codes = s.get_all_stocks()
result = pandas.DataFrame({"code": [], "start_date": [], "end_date": [], "last_date": [],
"one_day_change": [], "three_day_change": [], "five_day_change": [],
"ten_day_change":[], "twenty_day_change": []})
for code in codes:
stock_quotes = s.get_exright_quotes(code)
"""
йÉ
"""
if (len(stock_quotes) == 0):
print code
continue
result = analyze_extreme_changes(result, stock_quotes, [YIZI_ZT])
return result
示例3: __init__
# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import get_all_stocks [as 别名]
class Collector:
def __init__(self):
self.store = Store();
self.xueqiu = crawler.CrawlerForXueqiu()
self._10jqka = crawler.CrawlerFor10JQKA()
def collect_trades(self, conn, code, start, end, source):
sql_string = "insert into market (code, date, open, close, low, high, volume) values (%s, %s, %s, %s, %s, %s, %s)"
stock_data = None;
if source == SOHU:
stock_data = crawler.get_h_data(code, start, end)
elif source == XUEQIU:
stock_data = self.xueqiu.get_h_data(code, start, end)
elif source == TUSHARE:
stock_data = tushare.get_hist_data(code, start = start, end = end)
if (stock_data is None):
print "%s has no data"%(code)
else:
cursor = conn.cursor()
list = [];
for i in range(0, stock_data.count().open):
param = (code, stock_data.index[i],
stock_data.open[i], stock_data.close[i],
stock_data.low[i], stock_data.high[i],
stock_data.volume[i])
list.append(param)
cursor.executemany(sql_string, list)
conn.commit()
cursor.close()
def collect(self, start_date, source):
date = datetime.datetime.now();
date_string = date.strftime("%Y-%m-%d")
codes = self.store.get_all_stocks()
MAX_THREADS = 10
codes_num = len(codes)
codes_per_thread = codes_num / MAX_THREADS
# 这里应该多线程
for i in range(0, MAX_THREADS):
start = i * codes_per_thread
end = start + codes_per_thread
if i == MAX_THREADS - 1:
end = codes_num
t = threading.Thread(target=_collect_internal, args = (self, start_date, date_string, codes[start:end], source))
t.start()
t.join()
def collect_market(self, source):
self.collect("1989-01-01", source)
def collect_daily(self, source):
date = datetime.datetime.now();
date_string = date.strftime("%Y-%m-%d")
self.collect(date_string, source)
def collect_stock_information(self):
stocks = pandas.DataFrame()
try:
stocks = tushare.get_stock_basics()
except:
print "collect stock information error"
return
conn = ConnManager.get_conn()
cursor = conn.cursor()
update_list = [];
insert_list = [];
su = StringUtils()
cu = CalcUtils()
for code in stocks.index:
stock = stocks.loc[code]
query_sql = "select * from stock_information where code = '" + code + "'"
update_sql = "update stock_information s " +\
"set s.name = %s," +\
"s.industry = %s," +\
"s.area = %s," +\
"s.floating = %s," +\
"s.total = %s," +\
"s.pe = %s," +\
"s.pb = %s" +\
"where s.code = %s"
insert_sql = "insert into stock_information (code, name, industry, area, floating, total, pe, pb) " +\
"values (%s, %s, %s, %s, %s, %s, %s, %s)"
count = cursor.execute(query_sql)
if (count > 0):
param = (su.get_string(stock["name"]), su.get_string(stock.industry),
su.get_string(stock.area), cu.trim_float(stock.outstanding * 10000),
cu.trim_float(stock.totals * 10000), cu.trim_float(stock.pe),
cu.trim_float(stock.pb), code)
#print param
update_list.append(param)
else:
param = (code, su.get_string(stock["name"]),
su.get_string(stock.industry), su.get_string(stock.area),
#.........这里部分代码省略.........