2024-11-01 16:38:21 +08:00
|
|
|
|
import logging
|
|
|
|
|
import os
|
|
|
|
|
import logging.handlers
|
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# eta 接口token
|
|
|
|
|
APPID = "XNLDvxZHHugj7wJ7"
|
|
|
|
|
SECRET = "iSeU4s6cKKBVbt94htVY1p0sqUMqb2xa"
|
|
|
|
|
|
|
|
|
|
# eta 接口url
|
|
|
|
|
sourcelisturl = 'http://10.189.2.78:8108/v1/edb/source/list'
|
|
|
|
|
classifylisturl = 'http://10.189.2.78:8108/v1/edb/classify/list?ClassifyType='
|
|
|
|
|
uniquecodedataurl = 'http://10.189.2.78:8108/v1/edb/data?UniqueCode=4991c37becba464609b409909fe4d992&StartDate=2024-02-01'
|
|
|
|
|
classifyidlisturl = 'http://10.189.2.78:8108/v1/edb/list?ClassifyId='
|
|
|
|
|
edbcodedataurl = 'http://10.189.2.78:8108/v1/edb/data?EdbCode='
|
|
|
|
|
edbdatapushurl = 'http://10.189.2.78:8108/v1/edb/push'
|
|
|
|
|
edbdeleteurl = 'http://10.189.2.78:8108/v1/edb/business/edb/del'
|
|
|
|
|
edbbusinessurl = 'http://10.189.2.78:8108/v1/edb/business/data/del'
|
|
|
|
|
edbcodelist = ['ID01385938','lmcads03 lme comdty',
|
|
|
|
|
'GC1 COMB Comdty',
|
|
|
|
|
'C2404171822',
|
|
|
|
|
'dxy curncy',
|
|
|
|
|
'S5443199 ',
|
|
|
|
|
'S5479800',
|
|
|
|
|
'S5443108',
|
|
|
|
|
'H7358586',
|
|
|
|
|
'LC3FM1 INDEX',
|
|
|
|
|
'CNY REGN Curncy',
|
|
|
|
|
's0105897',
|
|
|
|
|
'M0067419',
|
|
|
|
|
'M0066351',
|
|
|
|
|
'S0266372',
|
|
|
|
|
'S0266438',
|
|
|
|
|
'S0266506']
|
|
|
|
|
|
|
|
|
|
# 临时写死用指定的列,与上面的edbcode对应,后面更改
|
|
|
|
|
edbnamelist = [
|
|
|
|
|
'ds','y',
|
|
|
|
|
'LME铜价',
|
|
|
|
|
'黄金连1合约',
|
|
|
|
|
'Brent-WTI',
|
|
|
|
|
'美元指数',
|
|
|
|
|
'甲醇鲁南价格',
|
|
|
|
|
'甲醇太仓港口价格',
|
|
|
|
|
'山东丙烯主流价',
|
|
|
|
|
'丙烷(山东)',
|
|
|
|
|
'FEI丙烷 M1',
|
|
|
|
|
'在岸人民币汇率',
|
|
|
|
|
'南华工业品指数',
|
|
|
|
|
'PVC期货主力',
|
|
|
|
|
'PE期货收盘价',
|
|
|
|
|
'PP连续-1月',
|
|
|
|
|
'PP连续-5月',
|
|
|
|
|
'PP连续-9月',
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
edbcodenamedict = {
|
|
|
|
|
'ID01385938':'PP:拉丝:1102K:市场价:青州:国家能源宁煤(日)',
|
|
|
|
|
'lmcads03 lme comdty':'LME铜价',
|
|
|
|
|
'GC1 COMB Comdty':'黄金连1合约',
|
|
|
|
|
'C2404171822':'Brent-WTI',
|
|
|
|
|
'dxy curncy':'美元指数',
|
|
|
|
|
'S5443199 ':'甲醇鲁南价格',
|
|
|
|
|
'S5479800':'甲醇太仓港口价格',
|
|
|
|
|
'S5443108':'山东丙烯主流价',
|
|
|
|
|
'H7358586':'丙烷(山东)',
|
|
|
|
|
'LC3FM1 INDEX':'FEI丙烷 M1',
|
|
|
|
|
'CNY REGN Curncy':'在岸人民币汇率',
|
|
|
|
|
's0105897':'南华工业品指数',
|
|
|
|
|
'M0067419':'PVC期货主力',
|
|
|
|
|
'M0066351':'PE期货收盘价',
|
|
|
|
|
'S0266372':'PP连续-1月',
|
|
|
|
|
'S0266438':'PP连续-5月',
|
|
|
|
|
'S0266506':'PP连续-9月',
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# eta自有数据指标编码
|
|
|
|
|
modelsindex = {
|
|
|
|
|
'NHITS': 'SELF0000001',
|
|
|
|
|
'Informer':'SELF0000057',
|
|
|
|
|
'LSTM':'SELF0000058',
|
|
|
|
|
'iTransformer':'SELF0000059',
|
|
|
|
|
'TSMixer':'SELF0000060',
|
|
|
|
|
'TSMixerx':'SELF0000061',
|
|
|
|
|
'PatchTST':'SELF0000062',
|
|
|
|
|
'RNN':'SELF0000063',
|
|
|
|
|
'GRU':'SELF0000064',
|
|
|
|
|
'TCN':'SELF0000065',
|
|
|
|
|
'BiTCN':'SELF0000066',
|
|
|
|
|
'DilatedRNN':'SELF0000067',
|
|
|
|
|
'MLP':'SELF0000068',
|
|
|
|
|
'DLinear':'SELF0000069',
|
|
|
|
|
'NLinear':'SELF0000070',
|
|
|
|
|
'TFT':'SELF0000071',
|
|
|
|
|
'FEDformer':'SELF0000072',
|
|
|
|
|
'StemGNN':'SELF0000073',
|
|
|
|
|
'MLPMultivariate':'SELF0000074',
|
|
|
|
|
'TiDE':'SELF0000075',
|
|
|
|
|
'DeepNPTS':'SELF0000076'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# eta 上传预测结果的请求体,后面发起请求的时候更改 model datalist 数据
|
|
|
|
|
data = {
|
|
|
|
|
"IndexCode": "",
|
|
|
|
|
"IndexName": "价格预测模型",
|
|
|
|
|
"Unit": "无",
|
|
|
|
|
"Frequency": "日度",
|
|
|
|
|
"SourceName": f"价格预测",
|
|
|
|
|
"Remark": 'ddd',
|
|
|
|
|
"DataList": [
|
|
|
|
|
{
|
|
|
|
|
"Date": "2024-05-02",
|
|
|
|
|
"Value": 333444
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# eta 分类
|
|
|
|
|
# level:3才可以获取到数据,所以需要人工把能源化工下所有的level3级都找到
|
|
|
|
|
# url = 'http://10.189.2.78:8108/v1/edb/list?ClassifyId=1214'
|
|
|
|
|
#ParentId ":1160, 能源化工
|
|
|
|
|
# ClassifyId ":1214,原油 ,1161 PP
|
|
|
|
|
#ParentId ":1214,",就是原油下所有的数据。
|
|
|
|
|
ClassifyId = 1161
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 报告上传配置
|
|
|
|
|
# 变量定义--线上环境
|
|
|
|
|
login_pushreport_url = "http://10.200.32.39/jingbo-api/api/server/login"
|
|
|
|
|
upload_url = "http://10.200.32.39/jingbo-api/api/dw/dataValue/pushDataValueList"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
login_data = {
|
|
|
|
|
"data": {
|
|
|
|
|
"account": "api_dev",
|
|
|
|
|
"password": "ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=",
|
|
|
|
|
"tenantHashCode": "8a4577dbd919675758d57999a1e891fe",
|
|
|
|
|
"terminal": "API"
|
|
|
|
|
},
|
|
|
|
|
"funcModule": "API",
|
|
|
|
|
"funcOperation": "获取token"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
upload_data = {
|
|
|
|
|
"funcModule":'研究报告信息',
|
|
|
|
|
"funcOperation":'上传原油价格预测报告',
|
|
|
|
|
"data":{
|
|
|
|
|
"ownerAccount":'27663', #报告所属用户账号 27663 - 刘小朋
|
|
|
|
|
"reportType":'OIL_PRICE_FORECAST', # 报告类型,固定为OIL_PRICE_FORECAST
|
|
|
|
|
"fileName": '', #文件名称
|
|
|
|
|
"fileBase64": '' ,#文件内容base64
|
|
|
|
|
"categoryNo":'yyjgycbg', # 研究报告分类编码
|
|
|
|
|
"smartBusinessClassCode":'YCJGYCBG', #分析报告分类编码
|
|
|
|
|
"reportEmployeeCode":"E40482" ,# 报告人 E40482 - 管理员 0000027663 - 刘小朋
|
|
|
|
|
"reportDeptCode" :"002000621000", # 报告部门 - 002000621000 SH期货研究部
|
|
|
|
|
"productGroupCode":"RAW_MATERIAL" # 商品分类
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 变量定义--测试环境
|
|
|
|
|
# login_pushreport_url = "http://192.168.100.53:8080/jingbo-dev/api/server/login"
|
|
|
|
|
# upload_url = "http://192.168.100.53:8080/jingbo-dev/api/analysis/reportInfo/researchUploadReportSave"
|
|
|
|
|
# # upload_url = "http://192.168.100.109:8080/jingbo/api/analysis/reportInfo/researchUploadReportSave" # zhaoqiwei
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# login_data = {
|
|
|
|
|
# "data": {
|
|
|
|
|
# "account": "api_test",
|
|
|
|
|
# "password": "MmVmNzNlOWI0MmY0ZDdjZGUwNzE3ZjFiMDJiZDZjZWU=",
|
|
|
|
|
# "tenantHashCode": "8a4577dbd919675758d57999a1e891fe",
|
|
|
|
|
# "terminal": "API"
|
|
|
|
|
# },
|
|
|
|
|
# "funcModule": "API",
|
|
|
|
|
# "funcOperation": "获取token"
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
# upload_data = {
|
|
|
|
|
# "funcModule":'研究报告信息',
|
|
|
|
|
# "funcOperation":'上传原油价格预测报告',
|
|
|
|
|
# "data":{
|
|
|
|
|
# "ownerAccount":'arui', #报告所属用户账号
|
|
|
|
|
# "reportType":'OIL_PRICE_FORECAST', # 报告类型,固定为OIL_PRICE_FORECAST
|
|
|
|
|
# "fileName": '2000-40-5-50--100-原油指标数据.xlsx-Brent活跃合约--2024-09-06-15-01-29-预测报告.pdf', #文件名称
|
|
|
|
|
# "fileBase64": '' ,#文件内容base64
|
|
|
|
|
# "categoryNo":'yyjgycbg', # 研究报告分类编码
|
|
|
|
|
# "smartBusinessClassCode":'YCJGYCBG', #分析报告分类编码
|
|
|
|
|
# "reportEmployeeCode":"E40116", # 报告人
|
|
|
|
|
# "reportDeptCode" :"D0044" ,# 报告部门
|
|
|
|
|
# "productGroupCode":"RAW_MATERIAL" # 商品分类
|
|
|
|
|
# }
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 线上开关
|
|
|
|
|
# is_train = True # 是否训练
|
|
|
|
|
# is_debug = False # 是否调试
|
|
|
|
|
# is_eta = True # 是否使用eta接口
|
|
|
|
|
# is_timefurture = True # 是否使用时间特征
|
|
|
|
|
# is_fivemodels = False # 是否使用之前保存的最佳的5个模型
|
|
|
|
|
# is_edbcode = False # 特征使用edbcoding列表中的
|
|
|
|
|
# is_edbnamelist = False # 自定义特征,对应上面的edbnamelist
|
|
|
|
|
# is_update_report = True # 是否上传报告
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 开关
|
|
|
|
|
is_train = True # 是否训练
|
2024-11-07 10:10:37 +08:00
|
|
|
|
is_debug = False # 是否调试
|
2024-11-20 18:40:58 +08:00
|
|
|
|
is_eta = False # 是否使用eta接口
|
2024-11-01 16:38:21 +08:00
|
|
|
|
is_timefurture = True # 是否使用时间特征
|
|
|
|
|
is_fivemodels = False # 是否使用之前保存的最佳的5个模型
|
|
|
|
|
is_edbcode = False # 特征使用edbcoding列表中的
|
|
|
|
|
is_edbnamelist = False # 自定义特征,对应上面的edbnamelist
|
|
|
|
|
is_update_eta = False # 预测结果上传到eta
|
|
|
|
|
is_update_report = False # 是否上传报告
|
|
|
|
|
|
|
|
|
|
# 数据截取日期
|
2024-11-20 14:14:27 +08:00
|
|
|
|
end_time = '' # 数据截取日期
|
2024-11-25 22:33:52 +08:00
|
|
|
|
freq = 'B' # 时间频率,"D": 天 "W": 周"M": 月"Q": 季度"A": 年 "H": 小时 "T": 分钟 "S": 秒 "B": 工作日
|
2024-11-01 16:38:21 +08:00
|
|
|
|
delweekenday = True
|
|
|
|
|
is_corr = False # 特征是否参与滞后领先提升相关系数
|
|
|
|
|
add_kdj = False # 是否添加kdj指标
|
|
|
|
|
if add_kdj and is_edbnamelist:
|
|
|
|
|
edbnamelist = edbnamelist+['K','D','J']
|
|
|
|
|
### 模型参数
|
2024-11-13 10:24:58 +08:00
|
|
|
|
# y = 'PP:拉丝:1102K:市场价:青州:国家能源宁煤(日)' # 原油指标数据的目标变量
|
2024-11-13 11:41:38 +08:00
|
|
|
|
y = 'AVG-金能大唐久泰青州' # 原油指标数据的目标变量
|
2024-11-13 10:24:58 +08:00
|
|
|
|
avg_cols = [
|
|
|
|
|
'PP:拉丝:1102K:出厂价:青州:国家能源宁煤(日)',
|
|
|
|
|
'PP:拉丝:L5E89:出厂价:华北(第二区域):内蒙古久泰新材料(日)',
|
|
|
|
|
'PP:拉丝:L5E89:出厂价:河北、鲁北:大唐内蒙多伦(日)',
|
|
|
|
|
'PP:拉丝:HP550J:市场价:青岛:金能化学(日)'
|
|
|
|
|
]
|
2024-11-14 17:26:17 +08:00
|
|
|
|
offsite = 80
|
2024-11-13 10:24:58 +08:00
|
|
|
|
offsite_col = ['PP:拉丝:HP550J:市场价:青岛:金能化学(日)']
|
2024-11-01 16:38:21 +08:00
|
|
|
|
horizon =5 # 预测的步长
|
|
|
|
|
input_size = 40 # 输入序列长度
|
|
|
|
|
train_steps = 50 if is_debug else 1000 # 训练步数,用来限定epoch次数
|
|
|
|
|
val_check_steps = 30 # 评估频率
|
|
|
|
|
early_stop_patience_steps = 5 # 早停的耐心步数
|
|
|
|
|
# --- 交叉验证用的参数
|
|
|
|
|
test_size = 200 # 测试集大小,定义100,后面使用的时候重新赋值
|
|
|
|
|
val_size = test_size # 验证集大小,同测试集大小
|
|
|
|
|
|
|
|
|
|
### 特征筛选用到的参数
|
|
|
|
|
k = 100 # 特征筛选数量,如果是0或者值比特征数量大,代表全部特征
|
|
|
|
|
|
2024-11-21 13:33:07 +08:00
|
|
|
|
# 绘图预测图上下边界使用的阈值,可以根据实际情况调整
|
|
|
|
|
rote = 0.04
|
2024-11-01 16:38:21 +08:00
|
|
|
|
|
|
|
|
|
### 文件
|
|
|
|
|
data_set = 'PP指标数据.xlsx' # 数据集文件
|
|
|
|
|
# data_set = 'INE_OIL(1).csv'
|
|
|
|
|
### 文件夹
|
2024-11-19 15:51:58 +08:00
|
|
|
|
dataset = 'juxitingdataset' # 数据集文件夹
|
2024-11-01 16:38:21 +08:00
|
|
|
|
|
|
|
|
|
# 数据库名称
|
|
|
|
|
db_name = os.path.join(dataset,'jbsh_juxiting.db')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
settings = f'{input_size}-{horizon}-{train_steps}--{k}-{data_set}-{y}'
|
|
|
|
|
# 获取日期时间
|
|
|
|
|
now = datetime.datetime.now().strftime('%Y%m%d%H%M%S') # 获取当前日期时间
|
|
|
|
|
reportname = f'PP--{now}-预测报告.pdf' # 报告文件名
|
|
|
|
|
reportname = reportname.replace(':', '-') # 替换冒号
|
|
|
|
|
|
|
|
|
|
### 邮件配置
|
|
|
|
|
username='1321340118@qq.com'
|
|
|
|
|
passwd='wgczgyhtyyyyjghi'
|
|
|
|
|
# recv=['liurui_test@163.com','52585119@qq.com']
|
|
|
|
|
recv=['liurui_test@163.com']
|
|
|
|
|
title=reportname
|
|
|
|
|
content=y+'预测报告请看附件'
|
|
|
|
|
file=os.path.join(dataset,reportname)
|
|
|
|
|
# file=os.path.join(dataset,'14-7-50--100-原油指标数据.xlsx-Brent连1合约价格--20240731175936-预测报告.pdf')
|
|
|
|
|
ssl=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 日志配置
|
|
|
|
|
|
|
|
|
|
# 创建日志目录(如果不存在)
|
|
|
|
|
log_dir = 'logs'
|
|
|
|
|
if not os.path.exists(log_dir):
|
|
|
|
|
os.makedirs(log_dir)
|
|
|
|
|
|
|
|
|
|
# 配置日志记录器
|
|
|
|
|
logger = logging.getLogger('my_logger')
|
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
|
|
|
|
|
# 配置文件处理器,将日志记录到文件
|
|
|
|
|
file_handler = logging.handlers.RotatingFileHandler(os.path.join(log_dir, 'pricepredict.log'), maxBytes=1024 * 1024, backupCount=5)
|
|
|
|
|
file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
|
|
|
|
|
|
|
|
|
|
# 配置控制台处理器,将日志打印到控制台
|
|
|
|
|
console_handler = logging.StreamHandler()
|
|
|
|
|
console_handler.setFormatter(logging.Formatter('%(message)s'))
|
|
|
|
|
|
|
|
|
|
# 将处理器添加到日志记录器
|
|
|
|
|
logger.addHandler(file_handler)
|
|
|
|
|
logger.addHandler(console_handler)
|
|
|
|
|
|
|
|
|
|
# logger.info('当前配置:'+settings)
|