1 Star 0 Fork 16

zonquan/traderStock-gui

forked from macroan/traderStock-gui 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
kline.py 3.45 KB
一键复制 编辑 原始数据 按行查看 历史
macroan 提交于 2017-12-18 15:35 . no commit message
#coding=utf-8
import public
import talib
import pandas as pd
class Kline:
instance = None
def __init__(self):
pass
@classmethod
def getInstance(cls):
if(cls.__instance == None):
cls.__instance = Kline()
return cls.__instance
def shape(func_name, df):
df = df[['date', 'open', 'high', 'low', 'close', 'code']]
df = df.sort_values('date', ascending=True)
open_p = df['open'].values
high_p = df['high'].values
low_p = df['low'].values
close_p = df['close'].values
if func_name == 'CDL2CROWS':
ret = talib.CDL2CROWS(open_p, high_p, low_p, close_p)
df['CDL2CROWS'] = pd.Series(ret)
df = df.sort_values('date', ascending=False)
return df
def CDL2CROWS(df):
meettotalCount, meettotal = public.init_succ_var()
df = shape(CDL2CROWS.func_name, df)
dflen = df.shape[0]
for i in xrange(dflen):
if int(df.iloc[i]['CDL2CROWS']) == -100:
meettotalCount = public.compute_succ_zf(df, i, meettotalCount, meettotal)
df.to_csv(df.iloc[0]['code']+'.csv', encoding='gbk')
return meettotalCount, meettotal
#(df.iloc[i]['high']-df.iloc[i]['open'])/(df.iloc[i]['open']-df.iloc[i]['close']) > 3.0) and \
def ZADF(df):
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(1, dflen):
#if i+2<dflen \
#and df.iloc[i]['MA_60'] > df.iloc[i+1]['MA_60'] and df.iloc[i+1]['MA_60'] > df.iloc[i+2]['MA_60'] \
#and df.iloc[i]['close'] > df.iloc[i]['MA_60']:
if df.iloc[i]['open'] > df.iloc[i]['close']:
if (df.iloc[i]['open'] > df.iloc[i]['close']*1.04 \
or (df.iloc[i]['close']==df.iloc[i]['open'] and df.iloc[i]['change']<=-0.099) \
or ((df.iloc[i]['high']-df.iloc[i]['low'] > 3*(df.iloc[i]['open']-df.iloc[i]['low'])) and (df.iloc[i]['high']/df.iloc[i]['low']>=1.035) and (df.iloc[i]['close']/df.iloc[i]['low']<=1.02))) \
and df.iloc[i-1]['change'] >= 0.099:
meettotalCount = public.compute_succ_zf(df, i-1, meettotalCount, meettotal)
return meettotalCount, meettotal
def ZADF2(df):
meettotalCount, meettotal = public.init_succ_var()
dflen = df.shape[0]
for i in xrange(1, dflen):
if df.iloc[i]['open'] > df.iloc[i]['close']:
if (df.iloc[i]['open'] > df.iloc[i]['close']*1.04 \
or (df.iloc[i]['close']==df.iloc[i]['open'] and df.iloc[i]['change']<=-0.099) \
or ((df.iloc[i]['high']-df.iloc[i]['low'] > 3*(df.iloc[i]['open']-df.iloc[i]['low'])) and (df.iloc[i]['high']/df.iloc[i]['low']>=1.035) and (df.iloc[i]['close']/df.iloc[i]['low']<=1.02))) \
and df.iloc[i-1]['change'] >= 0.099 and i-2 > -1:
if df.iloc[i-2]['close'] > df.iloc[i-2]['open']:
meettotalCount = public.compute_succ_zf(df, i-2, meettotalCount, meettotal)
return meettotalCount, meettotal
#============================选股==============================
def ZADF_XG(df, code):
retcode = 0
#dflen = df.shape[0]
#if 2<dflen \
#and df.iloc[0]['MA_60'] > df.iloc[1]['MA_60'] and df.iloc[1]['MA_60'] > df.iloc[2]['MA_60'] \
#and df.iloc[0]['close'] > df.iloc[0]['MA_60']:
#or (df.iloc[0]['close'] == df.iloc[0]['open'] and df.iloc[0]['change']<=-0.099) \
if df.iloc[0]['open'] > df.iloc[0]['close']:
if df.iloc[0]['open'] > df.iloc[0]['close']*1.04 \
or (df.iloc[0]['close']==df.iloc[0]['open'] and df.iloc[0]['change']<=-0.099) \
or ((df.iloc[0]['high']-df.iloc[0]['low'] > 3*(df.iloc[0]['open']-df.iloc[0]['low'])) and (df.iloc[0]['high']/df.iloc[0]['low']>=1.035) and (df.iloc[0]['close']/df.iloc[0]['low']<=1.02)):
retcode = code
return retcode
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zonquan/traderStock-gui.git
[email protected]:zonquan/traderStock-gui.git
zonquan
traderStock-gui
traderStock-gui
master

搜索帮助