Commit b8ea5c3f authored by 吕先亚's avatar 吕先亚

可以指定任意天数的预测

parent da189405
...@@ -20,9 +20,10 @@ toForecast = True # False means test, True means forecast ...@@ -20,9 +20,10 @@ toForecast = True # False means test, True means forecast
syncData = True # 开启会同步数据库指数及基金数据 syncData = True # 开启会同步数据库指数及基金数据
uploadData = True # 开启会上传预测结果 uploadData = True # 开启会上传预测结果
doReport = True # 开启会生成Excel报告 doReport = True # 开启会生成Excel报告
numForecastDays = 21 # business days, 21 business days means one month
# 待预测指数 # 待预测指数
# PREDICT_LIST = [67, 121, 122, 123] # PREDICT_LIST = [156]
PREDICT_LIST = [67, 121, 122, 123, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, PREDICT_LIST = [67, 121, 122, 123, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163,
164, 165, 166, 167, 168, 169, 170, 171, 174, 175, 177, 178] 164, 165, 166, 167, 168, 169, 170, 171, 174, 175, 177, 178]
eco = [65, 66, 74, 134] eco = [65, 66, 74, 134]
...@@ -48,7 +49,7 @@ def report_prediction(label, predict_item, indexDict: dict): ...@@ -48,7 +49,7 @@ def report_prediction(label, predict_item, indexDict: dict):
index_info = get_base_info(key)[0] index_info = get_base_info(key)[0]
if uploadData: if uploadData:
if len(LABEL_RANGE) > 2: if len(LABEL_RANGE) > 2:
data = {"rbd_id": key, "date": forecastDay, "predict": prediction} data = {"rbd_id": key, "date": forecastDay, "predict": prediction, "remark": {"period": numForecastDays}}
robo_predict.insert(data) robo_predict.insert(data)
else: else:
from ai.noticer import upload_predict from ai.noticer import upload_predict
...@@ -59,16 +60,15 @@ def report_prediction(label, predict_item, indexDict: dict): ...@@ -59,16 +60,15 @@ def report_prediction(label, predict_item, indexDict: dict):
def judgement(id, type, predict): def judgement(id, type, predict):
from datetime import datetime from datetime import datetime
predict_term = 21
start = parse_date(max_date) if max_date else prev_workday(datetime.today()) start = parse_date(max_date) if max_date else prev_workday(datetime.today())
navs = [] navs = []
if type == 'INDEX': if type == 'INDEX':
navs = get_index_list(index_ids=id, min_date=start, limit=predict_term + 1) navs = get_index_list(index_ids=id, min_date=start, limit=numForecastDays + 1)
navs = [nav['rid_close'] for nav in navs] navs = [nav['rid_close'] for nav in navs]
elif type == 'FUND': elif type == 'FUND':
navs = get_fund_list(fund_ids=id, min_date=start, limit=predict_term + 1) navs = get_fund_list(fund_ids=id, min_date=start, limit=numForecastDays + 1)
navs = [nav['rfn_nav_cal'] for nav in navs] navs = [nav['rfn_nav_cal'] for nav in navs]
if len(navs) == predict_term + 1: if len(navs) == numForecastDays + 1:
upper = True if navs[-1] >= navs[0] else False upper = True if navs[-1] >= navs[0] else False
result = {} result = {}
for k, v, in predict.items(): for k, v, in predict.items():
...@@ -95,7 +95,6 @@ if __name__ == '__main__': ...@@ -95,7 +95,6 @@ if __name__ == '__main__':
win1W = 5 # 1 week win1W = 5 # 1 week
win1M = 21 # 1 Month win1M = 21 # 1 Month
win1Q = 63 # 1 Quarter win1Q = 63 # 1 Quarter
numForecastDays = 21 # business days, 21 business days means one month
theThreshold = 0.0 theThreshold = 0.0
ids = set(PREDICT_LIST) | set(eco) | set(index) | set(fund) ids = set(PREDICT_LIST) | set(eco) | set(index) | set(fund)
infos = get_base_info(ids) infos = get_base_info(ids)
......
...@@ -41,18 +41,20 @@ def do_reporter2(records=None, excel_name=None): ...@@ -41,18 +41,20 @@ def do_reporter2(records=None, excel_name=None):
if not records: if not records:
records = robo_predict.get_list() records = robo_predict.get_list()
for item in records: for item in records:
predict_term = json.loads(item['remark'])['period']
result, rtn, real = is_right(item['rbd_id'], info.get(item['rbd_id'])['type'], item['date'], result, rtn, real = is_right(item['rbd_id'], info.get(item['rbd_id'])['type'], item['date'],
item['predict']) item['predict'], predict_term)
labels = list(LABEL_RANGE.keys())[::-1] labels = list(LABEL_RANGE.keys())[::-1]
data = { data = {
'Forcast On Date': item['date'], 'Forcast On Date': item['date'],
'Ticker': info.get(item['rbd_id'])['ticker'].replace(' Index', '').replace(' Equity', ''), 'Ticker': info.get(item['rbd_id'])['ticker'].replace(' Index', '').replace(' Equity', ''),
'In 21 business days': LABEL_TAG.get(item['predict']), 'Forecast Business Days After': predict_term,
'In business days': LABEL_TAG.get(item['predict']),
'real outcome label': LABEL_TAG.get(real), 'real outcome label': LABEL_TAG.get(real),
'random variable label': LABEL_TAG.get(random.randint(labels[0], labels[-1])), 'random variable label': LABEL_TAG.get(random.randint(labels[0], labels[-1])),
'Ticker Name': json.loads(info.get(item['rbd_id'])['datas'])['chineseName'], 'Ticker Name': json.loads(info.get(item['rbd_id'])['datas'])['chineseName'],
'Run On Time': item['create_time'].replace(minute=0, second=0), 'Run On Time': item['create_time'].replace(minute=0, second=0),
'return in 21 business days': rtn, 'return in business days': rtn,
'result': result 'result': result
} }
datas.append(data) datas.append(data)
...@@ -83,7 +85,7 @@ def get_RMSE(datas): ...@@ -83,7 +85,7 @@ def get_RMSE(datas):
return 0 return 0
tags = {v: k for k, v in LABEL_TAG.items()} tags = {v: k for k, v in LABEL_TAG.items()}
return (sum( return (sum(
[(tags.get(data['real outcome label']) - tags.get(data['In 21 business days'])) ** 2 for data in datas]) / len( [(tags.get(data['real outcome label']) - tags.get(data['In business days'])) ** 2 for data in datas]) / len(
datas)) ** 0.5 datas)) ** 0.5
...@@ -102,8 +104,7 @@ def get_RefRMSE(datas): ...@@ -102,8 +104,7 @@ def get_RefRMSE(datas):
datas]) / len(datas)) ** 0.5 datas]) / len(datas)) ** 0.5
def is_right(id, type, start, predict): def is_right(id, type, start, predict, predict_term):
predict_term = 21
navs = [] navs = []
if type == 'INDEX': if type == 'INDEX':
navs = get_index_list(index_ids=id, min_date=start, limit=predict_term + 1) navs = get_index_list(index_ids=id, min_date=start, limit=predict_term + 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment