# 基于Ricequant的一个量化分析公式实现

```import time
def average(order, prieod, M):
now_date = time.strftime('%Y-%m-%d',time.localtime(time.time()))
if prieod == '1d':
begin_date = time.strftime('%Y-%m-%d',time.localtime(time.time()-5*7*24*3600))
try:
time_list = get_price(order, start_date = begin_date, end_date = now_date, frequency = prieod, adjust_type = 'pre', skip_suspended = False, country = 'cn')
#print(time_list)
return average_merge(time_list, M)
except:
#print("无法获取到数据")
pass
elif prieod == '60m' or  prieod == '30m':
begin_date = time.strftime('%Y-%m-%d',time.localtime(time.time()-7*24*3600))
try:
time_list = get_price(order, start_date = begin_date, end_date = now_date, frequency = prieod, adjust_type = 'pre', skip_suspended = False, country = 'cn')
#print(time_list)
return average_merge(time_list, M)
except:
#print("无法获取到数据")
pass
def average_merge(time_list, M):
sum = 0
item = len(time_list.index)
for delay in range(1, M+1):
sum += time_list['close'][item-delay]
average = sum / M
return average
def Fliter(fac):
share_list = concept( fac )
target_list = []
for share in share_list:
try:
if average(share, '1d', 5) >= average(share, '1d', 10) and average(share, '1d', 10) >= average(share, '1d', 20):
print("已通过一轮筛选:", share)
if average(share, '60m', 5) >= average(share, '60m', 10) and average(share, '60m', 10) >= average(share, '60m', 20):
print("已通过二轮筛选:", share)
if average(share, '30m', 5) >= average(share, '30m', 10) and average(share, '30m', 10) >= average(share, '30m', 20):
print("已通过三轮筛选:", share)
target_list.append(share)
except:
#print("无法比较")
pass
print("\n",fac,"命中个股：")
for item in target_list:
print(item)```