2 Star 0 Fork 16

wangqiyuan/traderStock-gui

forked from macroan/traderStock-gui 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
xuangu.py 4.85 KB
一键复制 编辑 原始数据 按行查看 历史
macroan 提交于 2018-03-15 14:07 . no commit message
#coding=utf-8
from __future__ import division
import pandas as pd
import db
import utils
import volume
import ma
import macd
import kdj
import kline
import log
import multiprocessing as mp
import stock
import public
import config
#选股结果列表
result_list = []
def reset_resultlist():
global result_list
result_list = []
def xuangu(cycle, techniquedata, funcstr, funcdesc, opttype=1):
public.cls_progressbar()
reset_resultlist()
d = db.DB.getInstance()
basics = d.get_basics()
pool = mp.Pool(config.XUGU_CPU_COUNT)
progress = 0
totalCount = len(basics.index)
try:
for code in basics.index:
progress += 1
pool.apply_async(xuangu_handle, (cycle, techniquedata, code, progress, totalCount, funcstr, opttype), callback=xuangu_result)
pool.close()
pool.join()
except Exception, e:
print(e)
#xuangu_handle(cycle, techniquedata, '300602', progress, totalCount, funcstr, opttype)
xuangu_output(cycle, techniquedata, funcstr, funcdesc, opttype)
def xuangu_handle(cycle, techniquedata, code, progress, totalCount, funcstr, opttype):
d = db.DB.getInstance()
s = stock.Stock.getInstance()
ret = progress/totalCount*100
if opttype == 1:
tbname = code+'_'+cycle.lower()+config.TABLENAME_STR_RECENT+config.DATA_SOURCE
df = d.get_df(tbname)
else:
start = '2017-01-01'
df = s.get_stock_data(code, ty=cycle, start=start)
df = s.set_integrated_data(df)
if df is None or df.shape[0] == 0 or (not utils.xuangu_filter(code, df)):
return 0, ret, code, techniquedata
func = getattr(eval(techniquedata), funcstr)
if func is None:
return 0, ret, code, techniquedata
retcode = func(df, code)
return retcode, ret, code, techniquedata
def xuangu_result(ret):
global result_list
retcode = ret[0]
progress = ret[1]
code = ret[2]
techniquedata = ret[3]
if ret[0] != 0:
result_list.append(retcode)
print(techniquedata+'_xuangu_progress===============:%s, %d%%'%(code, progress))
public.setprogressbar(progress)
def xuangu_output(cycle, techniquedata, funcstr, funcdesc, opttype):
if len(result_list) == 0:
return
ret = {}
ret[funcstr] = pd.Series(result_list)
df = pd.DataFrame(ret)
if opttype == 1:
df.to_csv(u'./output/选股/'+techniquedata+'/'+funcdesc+cycle.lower()+'.csv', encoding='gbk', index=False)
else:
df.to_csv(u'./output/选股/'+techniquedata+u'/尾盘'+funcdesc+cycle.lower()+'.csv', encoding='gbk', index=False)
'''
ret = {}
ret = {u'代码':[], u'名字':[], u'主力流入':[], u'主力流出':[], u'主力净流入':[],
u'主力净流入/资金流入流出总和':[], u'散户流入':[],
u'散户流出':[], u'散户净流入':[], u'散户净流入/资金流入流出总和':[],
u'资金流入流出总和':[]}
s = stock.Stock.getInstance()
for code in result_list:
info = s.get_realtime_capital(code)
if info is None or len(info) == 0:
continue
ret[u'代码'].append(info[0])
ret[u'名字'].append(info[12])
ret[u'主力流入'].append(info[1])
ret[u'主力流出'].append(info[2])
ret[u'主力净流入'].append(info[3])
ret[u'主力净流入/资金流入流出总和'].append(info[4])
ret[u'散户流入'].append(info[5])
ret[u'散户流出'].append(info[6])
ret[u'散户净流入'].append(info[7])
ret[u'散户净流入/资金流入流出总和'].append(info[8])
ret[u'资金流入流出总和'].append(info[9])
df = pd.DataFrame(ret).T
#todaylist = []
#fivedaylist = []
#buycountlist = []
#sellcountlist = []
#for code in result_list:
#todaymoney, fivedaymoney, buy_count, sell_count = s.get_capital_info(code)
#todaylist.append(todaymoney)
#fivedaylist.append(fivedaymoney)
#buycountlist.append(buy_count)
#sellcountlist.append(sell_count)
#df[u'今天资金'] = pd.Series(todaylist)
#df[u'5日资金'] = pd.Series(fivedaylist)
#df[u'今天买盘次数'] = pd.Series(buycountlist)
#df[u'今天卖盘次数'] = pd.Series(sellcountlist)
if opttype == 1:
df.to_csv(u'./output/选股/'+techniquedata+'/'+funcdesc+cycle.lower()+'.csv', encoding='gbk')
else:
df.to_csv(u'./output/选股/'+techniquedata+u'/尾盘'+funcdesc+cycle.lower()+'.csv', encoding='gbk')
'''
def testxuangu():
s = stock.Stock.getInstance()
d = db.DB.getInstance()
basics = d.get_basics()
pool = mp.Pool(mp.cpu_count())
progress = 0
totalCount = len(basics.index)
try:
for code in basics.index:
progress += 1
df = s.get_stock_data(code, 'D')
if df is not None and df.shape[0] > 0:
df = df.sort_values('date', ascending=False)
df = s.set_integrated_data(df, type='R')
df = df[:60]
if df is None or df.shape[0] == 0 or utils.isnew(df):
continue
pool.apply_async(xuangu_handle, (df, 'macd', code, progress, totalCount, 'macd.macd_zeroup_first_gc'), callback=xuangu_result)
pool.close()
pool.join()
except Exception, e:
print(e)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wangqiyuan2/traderStock-gui.git
git@gitee.com:wangqiyuan2/traderStock-gui.git
wangqiyuan2
traderStock-gui
traderStock-gui
master

搜索帮助