做大盘研究就想出这么个方法,这次研究不够完善,所以见谅,仅作讨论。
600 指数里有很多不同种类的指数,只是希望找出与大盘指数偏离大的指数在进行分析,看是否可以找出超跌的指数并选出指数里的股票提前建仓。
from jqdata import *
##计算聚宽上各个指数与两大指数近五十日涨跌幅的bias
F=get_all_securities(types=['index'], date=None)
total = 0
#装筛选出来的结果
trade_date_length = 100
SHE_better=[]
SHE_worse=[]
SHG_better=[]
SHG_worse=[]
for i in F.index:
#当前指数的近五十日收盘价
data = history(50, '1d', 'close', [i], df=True)
#取涨跌幅
first_of_50_price = data[i][0]
last_of_50_price = data[i][-1]
fluctuation_ratio= (last_of_50_price - first_of_50_price)/first_of_50_price*100
#小数保留两位
fluctuation_ratio = round(fluctuation_ratio,2)
print("000")
print(fluctuation_ratio)
print(i)
#与大盘比较
if "SHG" in i:
print("与上证指数比较")
SHG="000001.XSHG"
first_of_50_price_in_SHG = history(50, '1d', 'close', [SHG], df=True)[SHG][0]
last_of_50_price_in_SHG = history(50, '1d', 'close', [SHG], df=True)[SHG][-1]
fluctuation_ratio_SHG= (last_of_50_price_in_SHG - first_of_50_price_in_SHG)/first_of_50_price_in_SHG*100
fluctuation_ratio_SHG = round(fluctuation_ratio_SHG,2)
if fluctuation_ratio-fluctuation_ratio_SHG > 3:
print(fluctuation_ratio_SHG)
print(fluctuation_ratio)
o = i+str(fluctuation_ratio)
SHG_better.append(o)
if fluctuation_ratio-fluctuation_ratio_SHG < -3:
print(i+"bad")
print(fluctuation_ratio)
o = i+str(fluctuation_ratio)
SHG_worse.append(o)
elif "SHE" in i:
print("与深证指数比较")
SHE="399001.XSHE"
first_of_50_price_in_SHE = history(50, '1d', 'close', [SHE], df=True)[SHE][0]
last_of_50_price_in_SHE = history(50, '1d', 'close', [SHE], df=True)[SHE][-1]
fluctuation_ratio_SHE= (last_of_50_price_in_SHE - first_of_50_price_in_SHE)/first_of_50_price_in_SHE*100
fluctuation_ratio_SHE = round(fluctuation_ratio_SHE,2)
if fluctuation_ratio-fluctuation_ratio_SHE > 3:
o = i+str(fluctuation_ratio)
SHE_better.append(o)
if fluctuation_ratio-fluctuation_ratio_SHE <-3:
o = i+str(fluctuation_ratio)
SHE_worse.append(o)
else:
print("与大盘比较时出错")
##个例取值观察
# total +=1
SHG_better