1 Star 0 Fork 16

timeskid/traderStock-gui

forked from macroan/traderStock-gui 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
successrate.py 2.83 KB
一键复制 编辑 原始数据 按行查看 历史
macroan 提交于 2018-03-14 20:57 . no commit message
#coding=utf-8
from __future__ import division
import sys
#sys.path.append('E:\\traderStock-gui\kline.pyd')
import pandas as pd
import db
import volume
import ma
import macd
import kdj
import kline
import config
import log
import multiprocessing as mp
import public
g_meettotalCount = 0 #成功次数
g_meettotal = {} #每天的涨幅,成功次数
#重置统计变量
def reset_statistics_var():
global g_meettotalCount, g_meettotal
g_meettotalCount = 0
g_meettotal = {day:{'totalrate':0, 'successcount':0} for day in config.ZF_DAY}
#获得的成功率
def get_successrate(cycle, techniquedata, funcstr, funcdesc):
public.cls_progressbar()
reset_statistics_var()
cycle = cycle.lower()
d = db.DB.getInstance()
basics = d.get_basics()
pool = mp.Pool(config.SUCC_CPU_COUNT)
progress = 0
totalCount = len(basics.index)
for code in basics.index:
progress += 1
pool.apply_async(succ_handle, (cycle, techniquedata, code, progress, totalCount, funcstr), callback=succ_result)
pool.close()
pool.join()
succ_output(cycle, techniquedata, funcdesc)
#计算成功率
def succ_handle(cycle, techniquedata, code, progress, totalCount, funcstr):
ret = progress/totalCount*100
d = db.DB.getInstance()
tbname = code+'_'+cycle+config.TABLENAME_STR_ALL+config.DATA_SOURCE
df = d.get_df(tbname)
if df is None or df.shape[0] == 0:
return None, None, ret, code, techniquedata
func = getattr(eval(techniquedata), funcstr)
if func is None:
return None, None, ret, code, techniquedata
meettotalCount, meettotal = func(df)
return meettotalCount, meettotal, ret, code, techniquedata
def succ_result(ret):
print(ret)
global g_meettotalCount, g_meettotal
if ret[0] != None and ret[1] != None:
g_meettotalCount += ret[0]
meet_total = ret[1]
for day in config.ZF_DAY:
g_meettotal[day]['totalrate'] += meet_total[day]['totalrate']
g_meettotal[day]['successcount'] += meet_total[day]['successcount']
progress = ret[2]
code = ret[3]
techniquedata = ret[4]
print(techniquedata+'_successrate_progress===============:%s, %d%%'%(code, progress))
public.setprogressbar(progress)
def succ_output(cycle, techniquedata, funcdesc):
global g_meettotalCount, g_meettotal
if g_meettotalCount == 0:
return
result = {}
for day in config.ZF_DAY:
result[funcdesc+u'平均涨幅day'+str(day)] = pd.Series(g_meettotal[day]['totalrate']/g_meettotalCount)
result[funcdesc+u'成功率day'+str(day)] = pd.Series(float(g_meettotal[day]['successcount'])/float(g_meettotalCount)*100)
result[u'总次数'] = pd.Series(g_meettotalCount)
df = pd.DataFrame(result)
df = df.T
if cycle == 'd':
df.to_csv(u'./output/成功率/'+techniquedata+'/'+funcdesc+'d.csv', encoding='gbk')
else:
df.to_csv(u'./output/成功率/'+techniquedata+'/'+funcdesc+'w.csv', encoding='gbk')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/timeskid/traderStock-gui.git
[email protected]:timeskid/traderStock-gui.git
timeskid
traderStock-gui
traderStock-gui
master

搜索帮助