1 Star 0 Fork 16

kaka2436/traderStock-gui

forked from macroan/traderStock-gui 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
macdkdjrsi.py 3.51 KB
一键复制 编辑 原始数据 按行查看 历史
macroan 提交于 2017-05-11 19:05 . A股数据与美股数据统一格式
#coding=utf-8
import pandas as pd
import time,datetime
import macd
import kdj
import rsi
import stock
class MacdKdjRsi:
__instance = None
@classmethod
def getInstance(cls):
if(cls.__instance == None):
cls.__instance = MacdKdjRsi()
return cls.__instance
def __init__(self):
self.Macd = macd.Macd.getInstance()
self.Kdj = kdj.Kdj.getInstance()
self.Rsi = rsi.Rsi.getInstance()
#修改了的函数,按照多个指标进行分析
#按照MACD,KDJ等进行分析
def get_TA_All(self):
operate_array1=[]
operate_array2=[]
operate_array3=[]
operate1 = 0
operate2 = 0
operate3 = 0
count = 0
#获取股票列表
#code,代码 name,名称 industry,所属行业 area,地区 pe,
#市盈率 outstanding,流通股本 totals,总股本(万) totalAssets,总资产(万)liquidAssets,流动资产
# fixedAssets,固定资产 reserved,公积金 reservedPerShare,
#每股公积金 eps,每股收益 bvps,每股净资 pb,市净率 timeToMarket,上市日期
s = stock.Stock.getInstance()
df_Code = s.get_Stock_List()
delIndex = []
for code in df_Code.index:
count = count + 1
if df_Code.loc[code]['name'][:2].lower() == "st" or df_Code.loc[code]['name'][1:3].lower() == "st":
delIndex.append(code)
continue
#过滤大盘股
if df_Code.loc[code]['outstanding']*10000 > 100000000:
delIndex.append(code)
continue
#市盈率为负数或过大
#if df_Code.loc[code]['pe'] < 0 or df_Code.loc[code]['pe'] > 500:
#delIndex.append(code)
#continue
#每股收益
#if df_Code.loc[code]['bvps'] <= 0:
#delIndex.append(code)
#continue
# index,0 - 6 date:日期 open:开盘价 high:最高价 close:收盘价
#low:最低价 volume:成交量 price_change:价格变动 p_change:涨跌幅
# 7-12 ma5:5日均价 ma10:10日均价 ma20:20日均价 v_ma5:5日均量v_ma10:10日均量 v_ma20:20日均量
operate1, operate2, operate3 = self.get_TA_One(code, start='2014-12-20')
if operate1 <=0 or operate2 <=0 or operate3 <=0:
delIndex.append(code)
continue
operate_array1.append(operate1)
operate_array2.append(operate2)
operate_array3.append(operate3)
if count == 0:
write_Blog(str(count))
time.sleep(0.1)
for code in delIndex:
df_Code = df_Code.drop(code)
df_Code['macd_score']=pd.Series(operate_array1,index=df_Code.index)
df_Code['kdj_score']=pd.Series(operate_array2,index=df_Code.index)
df_Code['rsi_score']=pd.Series(operate_array3,index=df_Code.index)
return df_Code
def get_TA_One(self, code, start):
s = stock.Stock.getInstance()
df = s.get_Hist_Data(code, start)
if df is None:
return (0, 0, 0)
#停牌的股
date = time.strftime('%Y-%m-%d',time.localtime(time.time()))
if df.iloc[0]['date'] != date and df.iloc[0]['date'] != date:
return (0, 0, 0)
dflen = df.shape[0]
operate1 = 0
operate2 = 0
operate3 = 0
print(df)
if dflen > 35:
try:
operate1, df = self.Macd.get_MACD(df)
operate2, df = self.Kdj.get_KDJ(df)
operate3, df = self.Rsi.get_RSI(df)
except Exception, e:
write_Blog(e)
return operate1, operate2, operate3
#日志记录
def write_Blog(strinput):
TODAY = datetime.date.today()
CURRENTDAY=TODAY.strftime('%Y-%m-%d')
TIME = time.strftime("%H:%M:%S")
#写入本地文件
fp = open('./output/'+'blog.txt','a')
fp.write('------------------------------\n'+CURRENTDAY +" "+TIME+" "+ str(strinput)+' \n')
fp.close()
time.sleep(1)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/kaka2436/traderStock-gui.git
git@gitee.com:kaka2436/traderStock-gui.git
kaka2436
traderStock-gui
traderStock-gui
master

搜索帮助