import pandas as pd
def KDJ_K(df,n=9):
df['highest'] = df['high'].rolling(n).max()
df['lowest'] = df['low'].rolling(n).min()
df['RSV'] = (df['close']-df['lowest'])/(df['highest']-df['lowest'])*100
df['signal'] = SMA_REC(df['RSV'],n=3,m=1, start=50)
return df['signal']
def SMA_REC(vals, n, m , start) :
sma=[ ]
numb = 0
for x in vals:
if np.isnan(x):
sma.append(x)
else:
if numb == 0:
ret = start
else:
ret = (x * m + ret * (n - m)) / n
sma.append(ret)
numb += 1
result = array(sma)
return result
# #传入df的index是日期,cloumn是['high','low','close'],需要的数据列名。
def KDJ_J(df,n=9):
df['highest'] = df['high'].rolling(n).max()
df['lowest'] = df['low'].rolling(n).min()
df['RSV'] = (df['close']-df['lowest'])/(df['highest']-df['lowest'])*100
df['KDJ_K'] = SMA_REC(df['RSV'],n=3,m=1, start=50)
df['signal'] = 3*df['KDJ_K']-2*SMA_REC(df['KDJ_K'],n=3,m=1, start=50)
return df['signal']
def KDJ_D(df,n=9):
df['highest'] = df['high'].rolling(n).max()
df['lowest'] = df['low'].rolling(n).min()
df['RSV'] = (df['close']-df['lowest'])/(df['highest']-df['lowest'])*100
df['KDJ_K'] = SMA_REC(df['RSV'],n=3,m=1, start=50)
df['signal'] = SMA_REC(df['KDJ_K'],n=3,m=1, start=50)
return df['signal']
def JK_KDJ_D(security_list,end_date,count = None,start_date = None,n=9):
if type(security_list)==str:
security_list=[security_list]
datalist = get_price(security=security_list,start_date=start_date,end_date=end_date,
frequency='daily', fields=['high','low','close'],fq='pre',count=count)
json = {}
d='KDJ_D'
j='KDJ_J'
k='KDJ_K'
for security_code in security_list:
df = datalist.minor_xs(security_code)
df[d] = KDJ_D(df,n)
df[j] = KDJ_J(df,n)
df[k] = KDJ_K(df,n)
json[security_code] = pd.DataFrame(data=df,index=df.index)
result = pd.Panel(data=json)
return result
print(JK_KDJ_D('000002.XSHG','2019-01-01')['000002.XSHG'])
相关文章
- 12-21POJ 3304 Segments(计算几何)
- 12-21【计算几何】【极角排序】【二分】Petrozavodsk Summer Training Camp 2016 Day 6: Warsaw U Contest, XVI Open Cup Onsite, Sunday, August 28, 2016 Problem J. Triangles
- 12-21本地计算机无法复制文件到远程计算机
- 12-21RDO(Remote Desktop Organizer)远程连接服务器提示“远程计算机需要网络级别身份验证,而您的计算机不支持该验证。请联系您的系统管理”
- 12-21查看GPU计算能力
- 12-21Azure-900学习 云计算入门笔记整理-1
- 12-21计算机网络安全实验002
- 12-21【重学计算机】操作系统D5章:文件系统
- 12-21【重学计算机】机组D4章:存储系统
- 12-21C语言数据结构静态栈——计算器的实现