import pandas as pd
def JK_Boll(security_list,end_date,count = None,start_date = None,n=20):
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=['close'], fq='pre',count=count)
json = {}
for security_code in security_list:
df = datalist.minor_xs(security_code)
df['boll_up'],df['boll_down'] =Boll(df,n)
json[security_code] = pd.DataFrame(data=df,index=df.index)
result = pd.Panel(data=json)
return result
#传入df的index是日期,cloumn是['close'],需要的数据列名。
def Boll(df,n=20):
df['mid'] = df['close'].rolling(n).mean()
df['boll_up'] = df['mid'] + 2*df['close'].rolling(n).std()
df['boll_down'] = df['mid'] - 2*df['close'].rolling(n).std()
return df['boll_up'],df['boll_down']
JK_Boll('000002.XSHE','2019-01-01')['000002.XSHE']