Commit dfc2079f authored by wenwen.tang's avatar wenwen.tang 😕

增加导出Excel逻辑

parent 7db266e0
......@@ -6,21 +6,28 @@ from py_jftech import autowired, parse_date, prev_workday, format_date
from ai.dao.robo_datas import get_base_info, get_index_list, get_fund_list
from ai.data_access import DataAccess
from ai.model_trainer import ModelTrainer
from ai.noticer import send
from ai.training_data_builder import TrainingDataBuilder
from api import DataSync
# 截止日期
# max_date = None
max_date = '2024-02-23'
max_date = '2024-03-01'
# max_date = '2024-01-11'
toForecast = True # False means test, True means forecast
syncData = False # 开启会同步数据库指数及基金数据
uploadData = False # 开启会上传预测结果
doReport = True # 开启会生成Excel报告
# 待预测指数
# PREDICT_LIST = [67, 121, 122, 123]
PREDICT_LIST = [67, 121, 122, 123, 155, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 174,
175, 177, 178]
PREDICT_LIST = [67, 121, 122, 123, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
174, 175, 177, 178]
eco = [65, 66, 74, 134]
index = [67, 68, 69, 70, 71, 72, 73, 75, 76, 77, 105, 106, 116, 117, 138, 139, 142, 143, 140, 141, 144, 145, 146]
fund = [121, 122, 123, 155, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 174, 175, 177,
fund = [121, 122, 123, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 174, 175,
177,
178]
......@@ -39,10 +46,15 @@ def predictionFromMoel(the_model, scaledX_forecast, predict_item, indexDict: dic
content = f"""\n On day {forecastDay.strftime("%m/%d/%Y")}, the model predicts {predict_item} to be {predictionStr} in {str(numForecastDays)} business days. \n"""
print(content)
# 上传预测结果
# key = [k for k, v in indexDict.items() if v == predict_item]
# index_info = get_base_info(key)[0]
# upload_predict(index_info['ticker'], forecastDay, predictionStr)
# send(content)
key = [k for k, v in indexDict.items() if v == predict_item]
index_info = get_base_info(key)[0]
if uploadData:
from ai.noticer import upload_predict
upload_predict(index_info['ticker'], forecastDay, predictionStr)
if doReport:
from ai.reporter import do_reporter
do_reporter()
send(content)
return prediction
......@@ -78,8 +90,8 @@ def judgement(id, type, predict):
########################################
if __name__ == '__main__':
sync()
toForecast = True # False means test, True means forecast
if syncData:
sync()
# define some parameters
win1W = 5 # 1 week
win1M = 21 # 1 Month
......
......@@ -44,6 +44,6 @@ def get_fund_list(fund_ids=None, min_date=None, max_date=None, limit=None):
def get_base_info(ids=None):
sqls = []
return f"""
SELECT rbd_id id,v_rbd_bloomberg_ticker ticker,v_rbd_type type FROM `robo_base_datum`
SELECT rbd_id id,v_rbd_bloomberg_ticker ticker,v_rbd_type type, rbd_datas datas FROM `robo_base_datum`
{where(*sqls,rbd_id=to_tuple(ids))}
"""
\ No newline at end of file
import datetime
import json
import pandas as pd
import requests
symbols = ['ACWI', 'EWJ', 'MCHI', 'EEM', 'BKF', 'INDA', 'AAXJ', 'VGK', 'QQQ', 'SPY', 'SPX', 'IWN',
'IUSG', 'IWD', 'DON', 'GDX', 'TOLZ', 'XLU', 'XBI', 'ESGD', 'IGE', 'EMLC', 'IGAA',
'LQD', 'HYG', 'SHY', 'IEI', 'IEF', 'GLD', 'IYR', 'UUP', 'CEW', 'TLT']
def do_reporter(start='2023-10-01', end=datetime.date.today()):
url = f"https://jrp.jfquant.com/api/v1.0/ai/predict?startTime={start}&endTime={end.strftime('%Y-%m-%d')}"
resp = requests.get(url)
datas = []
symbol_index_dict = {symbol: index for index, symbol in enumerate(symbols)}
for value in resp.json()['body'].values():
for item in value:
data = {
'Forcast On Date': item['aiPredict']['predictDate'],
'Ticker': item['bloombergTicker'].replace(' Index', '').replace(' Equity', ''),
'In 21 business days': 'UP' if item['aiPredict']['predict'] == 1 else 'DOWN',
'Ticker Name': item['indexName'],
}
datas.append(data)
sorted_data = sorted(datas, key=lambda x: symbol_index_dict[x['Ticker'].split(' ')[0]])
print(json.dumps(sorted_data, ensure_ascii=False))
pf = pd.DataFrame(sorted_data)
pf.to_excel("Forcast_Report.xlsx", index=False)
if __name__ == '__main__':
do_reporter()
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