From 484217c8640699ce9ac10c6147d16b3a62fc7c78 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:56:07 +0800 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#325) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/psf/black: 23.12.1 → 24.1.1](https://github.com/psf/black/compare/23.12.1...24.1.1) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- agents/elegantrl_models.py | 1 + .../liquidation/ddpg_agent.py | 1 + .../liquidation/env_execution_optimizing.py | 1 + .../liquidation/model.py | 1 + .../liquidation/utils.py | 1 + .../order_execution_qlib/run_all_model.py | 1 + .../order_execution_qlib/workflow_by_code.py | 1 + .../env_future_trading_wt.py | 1 + .../wt4elegantrl/assessments.py | 4 ++- .../demo_future_trading_elegantrl.py | 5 ++- .../wt4elegantrl/elegantrl/agent.py | 12 +++---- .../wt4elegantrl/elegantrl/replay.py | 6 ++-- .../wt4elegantrl/elegantrl/run.py | 24 ++++++++----- .../wt4elegantrl/wtpy/CtaContext.py | 4 ++- .../wt4elegantrl/wtpy/HftContext.py | 4 ++- .../wt4elegantrl/wtpy/SelContext.py | 4 ++- .../wt4elegantrl/wtpy/apps/WtBtAnalyst.py | 14 ++++++-- .../wt4elegantrl/wtpy/apps/WtHotPicker.py | 36 +++++++++++-------- .../wt4elegantrl/wtpy/monitor/WatchDog.py | 11 ++++-- .../wt4elegantrl/wtpy/monitor/WtBtMon.py | 1 + .../wt4elegantrl/wtpy/monitor/WtMonSvr.py | 9 +++-- .../wt4elegantrl/wtpy/monitor/__init__.py | 1 + .../wtpy/wrapper/ContractLoader.py | 1 + .../wtpy/wrapper/PlatformHelper.py | 1 + .../wt4elegantrl/wtpy/wrapper/WtBtWrapper.py | 4 ++- .../wt4elegantrl/wtpy/wrapper/WtDtServoApi.py | 1 + .../wt4elegantrl/wtpy/wrapper/WtDtWrapper.py | 5 ++- .../wt4elegantrl/wtpy/wrapper/WtExecApi.py | 1 + .../wt4elegantrl/wtpy/wrapper/WtMQWrapper.py | 1 + .../wt4elegantrl/wtpy/wrapper/WtWrapper.py | 13 ++++--- .../env_portfolio_yahoofinance.py | 1 + .../env_portfolio_optimization.py | 1 + meta/factors/factors.py | 4 ++- 34 files changed, 125 insertions(+), 53 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e3b86e5c..85f77499 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,6 +12,6 @@ repos: - id: reorder-python-imports args: [--py37-plus] - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.1.1 hooks: - id: black diff --git a/agents/elegantrl_models.py b/agents/elegantrl_models.py index 5e6cd56d..e0b45cb5 100644 --- a/agents/elegantrl_models.py +++ b/agents/elegantrl_models.py @@ -1,6 +1,7 @@ """ DRL models from ElegantRL: https://github.com/AI4Finance-Foundation/ElegantRL """ + from __future__ import annotations import torch diff --git a/meta/env_execution_optimizing/liquidation/ddpg_agent.py b/meta/env_execution_optimizing/liquidation/ddpg_agent.py index 78b65460..827c8979 100644 --- a/meta/env_execution_optimizing/liquidation/ddpg_agent.py +++ b/meta/env_execution_optimizing/liquidation/ddpg_agent.py @@ -1,4 +1,5 @@ """Source: https://github.com/AI4Finance-Foundation/Liquidation-Analysis-using-Multi-Agent-Reinforcement-Learning-ICML-2019/blob/master/syntheticChrissAlmgren.py""" + """Paper: Multi-agent reinforcement learning for liquidation strategy analysis accepted by ICML 2019 AI in Finance: Applications and Infrastructure for Multi-Agent Learning. (https://arxiv.org/abs/1906.11046)""" import copy import random diff --git a/meta/env_execution_optimizing/liquidation/env_execution_optimizing.py b/meta/env_execution_optimizing/liquidation/env_execution_optimizing.py index 126ac7b5..4a412b23 100644 --- a/meta/env_execution_optimizing/liquidation/env_execution_optimizing.py +++ b/meta/env_execution_optimizing/liquidation/env_execution_optimizing.py @@ -1,4 +1,5 @@ """Source: https://github.com/AI4Finance-Foundation/Liquidation-Analysis-using-Multi-Agent-Reinforcement-Learning-ICML-2019/blob/master/syntheticChrissAlmgren.py""" + """Paper: Multi-agent reinforcement learning for liquidation strategy analysis accepted by ICML 2019 AI in Finance: Applications and Infrastructure for Multi-Agent Learning. (https://arxiv.org/abs/1906.11046)""" import collections import random diff --git a/meta/env_execution_optimizing/liquidation/model.py b/meta/env_execution_optimizing/liquidation/model.py index 2f451e76..3fc33533 100644 --- a/meta/env_execution_optimizing/liquidation/model.py +++ b/meta/env_execution_optimizing/liquidation/model.py @@ -1,4 +1,5 @@ """Source: https://github.com/AI4Finance-Foundation/Liquidation-Analysis-using-Multi-Agent-Reinforcement-Learning-ICML-2019/blob/master/syntheticChrissAlmgren.py""" + """Paper: Multi-agent reinforcement learning for liquidation strategy analysis accepted by ICML 2019 AI in Finance: Applications and Infrastructure for Multi-Agent Learning. (https://arxiv.org/abs/1906.11046)""" import numpy as np import torch diff --git a/meta/env_execution_optimizing/liquidation/utils.py b/meta/env_execution_optimizing/liquidation/utils.py index a82202d9..1e04c668 100644 --- a/meta/env_execution_optimizing/liquidation/utils.py +++ b/meta/env_execution_optimizing/liquidation/utils.py @@ -1,4 +1,5 @@ """Source: https://github.com/AI4Finance-Foundation/Liquidation-Analysis-using-Multi-Agent-Reinforcement-Learning-ICML-2019/blob/master/syntheticChrissAlmgren.py""" + """Paper: Multi-agent reinforcement learning for liquidation strategy analysis accepted by ICML 2019 AI in Finance: Applications and Infrastructure for Multi-Agent Learning. (https://arxiv.org/abs/1906.11046)""" import matplotlib.pyplot as plt import matplotlib.ticker as mticker diff --git a/meta/env_execution_optimizing/order_execution_qlib/run_all_model.py b/meta/env_execution_optimizing/order_execution_qlib/run_all_model.py index bdba495e..45407491 100644 --- a/meta/env_execution_optimizing/order_execution_qlib/run_all_model.py +++ b/meta/env_execution_optimizing/order_execution_qlib/run_all_model.py @@ -1,4 +1,5 @@ """Source: https://github.com/microsoft/qlib/tree/high-freq-execution/examples/trade/""" + # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import functools diff --git a/meta/env_execution_optimizing/order_execution_qlib/workflow_by_code.py b/meta/env_execution_optimizing/order_execution_qlib/workflow_by_code.py index df997bbb..00d7397d 100644 --- a/meta/env_execution_optimizing/order_execution_qlib/workflow_by_code.py +++ b/meta/env_execution_optimizing/order_execution_qlib/workflow_by_code.py @@ -1,4 +1,5 @@ """Source: https://github.com/microsoft/qlib/tree/high-freq-execution/examples/trade/""" + # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. import sys diff --git a/meta/env_future_trading/env_future_trading_wt.py b/meta/env_future_trading/env_future_trading_wt.py index 3747ddaa..5996c452 100644 --- a/meta/env_future_trading/env_future_trading_wt.py +++ b/meta/env_future_trading/env_future_trading_wt.py @@ -1,4 +1,5 @@ """Use WonderTrader Simulator""" + """https://github.com/drlgistics/Wt4ElegantRL""" from meta.env_future_trading.wt4elegantrl.envs_simple_cta import SimpleCTAEnv from meta.env_future_trading.wt4elegantrl.envs_simple_cta import ( diff --git a/meta/env_future_trading/wt4elegantrl/assessments.py b/meta/env_future_trading/wt4elegantrl/assessments.py index b88b64c9..79b87120 100644 --- a/meta/env_future_trading/wt4elegantrl/assessments.py +++ b/meta/env_future_trading/wt4elegantrl/assessments.py @@ -185,7 +185,9 @@ def finish(self): # gamma = np.round(np.nanprod(np.array(self.__reward__)+1, axis=0)-1, 5) # gamma = self.__assets__[-1]/max(self.__assets__)-1 # gamma = self.__assets__[-1]/self.init_assets-1 - self.__reward__.append(gamma) # 在结束的时候把过程奖励做处理,作为整个训练的奖励 + self.__reward__.append( + gamma + ) # 在结束的时候把过程奖励做处理,作为整个训练的奖励 self.__done__ = True @property diff --git a/meta/env_future_trading/wt4elegantrl/demo_future_trading_elegantrl.py b/meta/env_future_trading/wt4elegantrl/demo_future_trading_elegantrl.py index 8edfa6af..54532149 100644 --- a/meta/env_future_trading/wt4elegantrl/demo_future_trading_elegantrl.py +++ b/meta/env_future_trading/wt4elegantrl/demo_future_trading_elegantrl.py @@ -193,7 +193,10 @@ def debug(count): obs, reward, done, info = env.step(action) n += 1 # print('action:', action, 'obs:', obs, 'reward:', reward, 'done:', done) - print("第%s次训练完成,执行%s步, 奖励%s, 盈亏%s。" % (i, n, reward, env.assets)) + print( + "第%s次训练完成,执行%s步, 奖励%s, 盈亏%s。" + % (i, n, reward, env.assets) + ) env.close() @command() diff --git a/meta/env_future_trading/wt4elegantrl/elegantrl/agent.py b/meta/env_future_trading/wt4elegantrl/elegantrl/agent.py index c5edee94..4fe74233 100644 --- a/meta/env_future_trading/wt4elegantrl/elegantrl/agent.py +++ b/meta/env_future_trading/wt4elegantrl/elegantrl/agent.py @@ -74,12 +74,12 @@ def __init__( self.get_obj_critic = None self.criterion = torch.nn.SmoothL1Loss() - self.cri = ( - self.cri_target - ) = self.if_use_cri_target = self.cri_optim = self.ClassCri = None - self.act = ( - self.act_target - ) = self.if_use_act_target = self.act_optim = self.ClassAct = None + self.cri = self.cri_target = self.if_use_cri_target = self.cri_optim = ( + self.ClassCri + ) = None + self.act = self.act_target = self.if_use_act_target = self.act_optim = ( + self.ClassAct + ) = None assert isinstance(gpu_id, int) assert isinstance(env_num, int) diff --git a/meta/env_future_trading/wt4elegantrl/elegantrl/replay.py b/meta/env_future_trading/wt4elegantrl/elegantrl/replay.py index 7bce9b23..14d9cc21 100644 --- a/meta/env_future_trading/wt4elegantrl/elegantrl/replay.py +++ b/meta/env_future_trading/wt4elegantrl/elegantrl/replay.py @@ -380,9 +380,9 @@ def update_ids(self, data_ids, prob=10): # 10 is max_prob self.now_len += (ids >= self.now_len).sum() upper_step = self.depth - 1 - self.prob_ary[ - ids - ] = prob # here, ids means the indices of given children (maybe the right ones or left ones) + self.prob_ary[ids] = ( + prob # here, ids means the indices of given children (maybe the right ones or left ones) + ) p_ids = (ids - 1) // 2 while upper_step: # propagate the change through tree diff --git a/meta/env_future_trading/wt4elegantrl/elegantrl/run.py b/meta/env_future_trading/wt4elegantrl/elegantrl/run.py index 2b1bfee2..69f60330 100644 --- a/meta/env_future_trading/wt4elegantrl/elegantrl/run.py +++ b/meta/env_future_trading/wt4elegantrl/elegantrl/run.py @@ -282,9 +282,11 @@ def update_buffer(_traj_list): if if_save and not if_overwrite: agent.save_or_load_agent("%s/best/" % (cwd), if_save=True) - buffer.save_or_load_history( - "%s/best/" % (cwd), if_save=True - ) if agent.if_off_policy else None + ( + buffer.save_or_load_history("%s/best/" % (cwd), if_save=True) + if agent.if_off_policy + else None + ) if_train = not ( (if_allow_break and if_reach_goal) @@ -508,12 +510,16 @@ def comm_network_optim(self, agent, learner_id): avg_update_net(agent.cri, data[2], device) if data[2] else None avg_update_optim(agent.cri_optim, data[3], device) - avg_update_net( - agent.act_target, data[4], device - ) if agent.if_use_act_target else None - avg_update_net( - agent.cri_target, data[5], device - ) if agent.if_use_cri_target else None + ( + avg_update_net(agent.act_target, data[4], device) + if agent.if_use_act_target + else None + ) + ( + avg_update_net(agent.cri_target, data[5], device) + if agent.if_use_cri_target + else None + ) def run0(self, args, comm_eva, comm_exp, learner_id=0): # print(f'| os.getpid()={os.getpid()} PipeLearn.run, {learner_id}') diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/CtaContext.py b/meta/env_future_trading/wt4elegantrl/wtpy/CtaContext.py index 983f44f0..c2f18f3a 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/CtaContext.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/CtaContext.py @@ -23,7 +23,9 @@ def __init__(self, id: int, stra, wrapper: WtWrapper, engine): self.__wrapper__ = wrapper # 底层接口转换器 self.__id__ = id # 策略ID self.__bar_cache__ = dict() # K线缓存 - self.__tick_cache__ = dict() # tTick缓存,每次都重新去拉取,这个只做中转用,不在python里维护副本 + self.__tick_cache__ = ( + dict() + ) # tTick缓存,每次都重新去拉取,这个只做中转用,不在python里维护副本 self.__sname__ = stra.name() self.__engine__ = engine # 交易环境 self.__pos_cache__ = None diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/HftContext.py b/meta/env_future_trading/wt4elegantrl/wtpy/HftContext.py index 1ebec533..75a94fa5 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/HftContext.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/HftContext.py @@ -23,7 +23,9 @@ def __init__(self, id: int, stra, wrapper: WtWrapper, engine): self.__wrapper__ = wrapper # 底层接口转换器 self.__id__ = id # 策略ID self.__bar_cache__ = dict() # K线缓存 - self.__tick_cache__ = dict() # Tick缓存,每次都重新去拉取,这个只做中转用,不在python里维护副本 + self.__tick_cache__ = ( + dict() + ) # Tick缓存,每次都重新去拉取,这个只做中转用,不在python里维护副本 self.__ordque_cache__ = dict() # 委托队列缓存,用法同__tick_cache__ self.__orddtl_cache__ = dict() # 逐笔委托缓存,用法同__tick_cache__ self.__trans_cache__ = dict() # 逐笔成交缓存,用法同__tick_cache__ diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/SelContext.py b/meta/env_future_trading/wt4elegantrl/wtpy/SelContext.py index ebc912c1..73a994ee 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/SelContext.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/SelContext.py @@ -23,7 +23,9 @@ def __init__(self, id: int, stra, wrapper: WtWrapper, engine): self.__wrapper__ = wrapper # 底层接口转换器 self.__id__ = id # 策略ID self.__bar_cache__ = dict() # K线缓存 - self.__tick_cache__ = dict() # tTick缓存,每次都重新去拉取,这个只做中转用,不在python里维护副本 + self.__tick_cache__ = ( + dict() + ) # tTick缓存,每次都重新去拉取,这个只做中转用,不在python里维护副本 self.__sname__ = stra.name() self.__engine__ = engine # 交易环境 self.__pos_cache__ = None diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/apps/WtBtAnalyst.py b/meta/env_future_trading/wt4elegantrl/wtpy/apps/WtBtAnalyst.py index 947f6b0f..f6623736 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/apps/WtBtAnalyst.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/apps/WtBtAnalyst.py @@ -796,17 +796,25 @@ def trading_analyze(workbook: Workbook, df_closes, df_funds, capital=500000): worksheet.write_column("B40", s.values(), value_format) worksheet.write_row("A49", ["连续交易系列统计"], title_format) - worksheet.write_row("A51", ["连续盈利次数", "出现次数", "每个序列的平均收益"], index_format) + worksheet.write_row( + "A51", ["连续盈利次数", "出现次数", "每个序列的平均收益"], index_format + ) worksheet.write_column("A52", f_result["连续次数"], value_format) worksheet.write_column("B52", f_result["出现次数"], value_format) worksheet.write_column("C52", f_result["每个序列平均收益"], value_format) win_cnt = len(f_result) next_row = win_cnt + 52 - worksheet.write_row("A%d" % next_row, ["连续亏损次数", "出现次数", "每个序列的平均亏损"], index_format) + worksheet.write_row( + "A%d" % next_row, + ["连续亏损次数", "出现次数", "每个序列的平均亏损"], + index_format, + ) worksheet.write_column("A%d" % (next_row + 1), f_2_result["连续次数"], value_format) worksheet.write_column("B%d" % (next_row + 1), f_2_result["出现次数"], value_format) - worksheet.write_column("C%d" % (next_row + 1), f_2_result["每个序列平均亏损"], value_format) + worksheet.write_column( + "C%d" % (next_row + 1), f_2_result["每个序列平均亏损"], value_format + ) # 这里开始画图 next_row += len(f_2_result) + 3 diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/apps/WtHotPicker.py b/meta/env_future_trading/wt4elegantrl/wtpy/apps/WtHotPicker.py index 9a350459..564a123d 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/apps/WtHotPicker.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/apps/WtHotPicker.py @@ -576,24 +576,30 @@ def notify( for exchg in hot_changes: for pid in hot_changes[exchg]: item = hot_changes[exchg][pid][-1] - content += "品种%s.%s的主力合约已切换,下个交易日(%s)生效, %s -> %s\n" % ( - exchg, - pid, - dtStr, - item["from"], - item["to"], + content += ( + "品种%s.%s的主力合约已切换,下个交易日(%s)生效, %s -> %s\n" + % ( + exchg, + pid, + dtStr, + item["from"], + item["to"], + ) ) content += "\n" for exchg in sec_changes: for pid in sec_changes[exchg]: item = sec_changes[exchg][pid][-1] - content += "品种%s.%s的次主力合约已切换,下个交易日(%s)生效, %s -> %s\n" % ( - exchg, - pid, - dtStr, - item["from"], - item["to"], + content += ( + "品种%s.%s的次主力合约已切换,下个交易日(%s)生效, %s -> %s\n" + % ( + exchg, + pid, + dtStr, + item["from"], + item["to"], + ) ) msg_mp = MIMEMultipart() @@ -910,7 +916,8 @@ def merge_switch_list(self, total, exchg, switch_list): else: total[exchg][pid].extend(switch_list[pid]) logging.info( - "[%s]品种%s主力切换规则追加%d条" % (exchg, pid, len(switch_list[pid])) + "[%s]品种%s主力切换规则追加%d条" + % (exchg, pid, len(switch_list[pid])) ) bChanged = True return bChanged, total @@ -1060,7 +1067,8 @@ def execute_increment( lastDate = str(marker["date"]) if lastDate >= endDate.strftime("%Y%m%d"): logging.info( - "上次更新日期%s大于结束日期%s,退出更新" % (lastDate, endDate.strftime("%Y%m%d")) + "上次更新日期%s大于结束日期%s,退出更新" + % (lastDate, endDate.strftime("%Y%m%d")) ) exit() elif lastDate != "0": diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/monitor/WatchDog.py b/meta/env_future_trading/wt4elegantrl/wtpy/monitor/WatchDog.py index ecd9eb40..1ab2d0d7 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/monitor/WatchDog.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/monitor/WatchDog.py @@ -120,7 +120,9 @@ def applyConf(self, appConf: dict): url=self._mq_url, logger=self.__logger__ ) self._evt_receiver.run() - self.__logger__.info("应用%s开始接收%s的通知信息" % (self._id, self._mq_url)) + self.__logger__.info( + "应用%s开始接收%s的通知信息" % (self._id, self._mq_url) + ) def getConf(self): self._lock.acquire() @@ -168,7 +170,8 @@ def is_running(self, pids) -> bool: ) self._evt_receiver.run() self.__logger__.info( - "应用%s开始接收%s的通知信息" % (self._id, self._mq_url) + "应用%s开始接收%s的通知信息" + % (self._id, self._mq_url) ) except: pass @@ -188,7 +191,9 @@ def run(self): url=self._mq_url, logger=self.__logger__, sink=self ) self._evt_receiver.run() - self.__logger__.info("应用%s开始接收%s的通知信息" % (self._id, self._mq_url)) + self.__logger__.info( + "应用%s开始接收%s的通知信息" % (self._id, self._mq_url) + ) try: fullPath = os.path.join(self.__info__["folder"], self.__info__["param"]) diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/monitor/WtBtMon.py b/meta/env_future_trading/wt4elegantrl/wtpy/monitor/WtBtMon.py index cffb51df..e8e1fa5f 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/monitor/WtBtMon.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/monitor/WtBtMon.py @@ -6,6 +6,7 @@ LastEditors: Wesley LastEditTime: 2021-09-02 14:18:50 """ + import datetime import hashlib import json diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/monitor/WtMonSvr.py b/meta/env_future_trading/wt4elegantrl/wtpy/monitor/WtMonSvr.py index 68066c6f..91b9bc68 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/monitor/WtMonSvr.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/monitor/WtMonSvr.py @@ -782,7 +782,9 @@ def cmd_login(): usrInf["loginip"] = request.remote_addr usrInf["logintime"] = now.strftime("%Y/%m/%d %H:%M:%S") - exptime = now + datetime.timedelta(minutes=360) # 360分钟令牌超时 + exptime = now + datetime.timedelta( + minutes=360 + ) # 360分钟令牌超时 session["userinfo"] = usrInf session["expiretime"] = exptime.replace( tzinfo=pytz.timezone("UTC") @@ -1704,7 +1706,10 @@ def cmd_del_app(): if len(id) == 0: ret = {"result": -1, "message": "组合ID不能为空"} elif self.__data_mgr__.has_group(id): - ret = {"result": -2, "message": "该调度任务是策略组合,请从组合管理删除"} + ret = { + "result": -2, + "message": "该调度任务是策略组合,请从组合管理删除", + } elif not self._dog.has_app(id): ret = {"result": -3, "message": "该调度任务不存在"} elif self._dog.isRunning(id): diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/monitor/__init__.py b/meta/env_future_trading/wt4elegantrl/wtpy/monitor/__init__.py index d7c01252..1fd118ac 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/monitor/__init__.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/monitor/__init__.py @@ -6,6 +6,7 @@ LastEditors: Wesley LastEditTime: 2021-08-16 17:29:42 """ + from .WtBtMon import WtBtMon from .WtLogger import WtLogger from .WtMonSvr import WtMonSvr diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/ContractLoader.py b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/ContractLoader.py index 02cc44ff..39c121e0 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/ContractLoader.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/ContractLoader.py @@ -6,6 +6,7 @@ LastEditors: Wesley LastEditTime: 2021-08-13 15:35:59 """ + import os from ctypes import c_char_p from ctypes import cdll diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/PlatformHelper.py b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/PlatformHelper.py index 91686886..9358b12b 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/PlatformHelper.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/PlatformHelper.py @@ -6,6 +6,7 @@ LastEditors: Wesley LastEditTime: 2021-08-13 15:32:23 """ + import platform diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtBtWrapper.py b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtBtWrapper.py index 9a2e3c24..8051e27d 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtBtWrapper.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtBtWrapper.py @@ -337,7 +337,9 @@ def on_stra_get_tick( addr = addressof(curTick.contents) # 获取内存地址 ticks = [None] * count # 预先分配list的长度 for idx in range(count): - realTick = WTSTickStruct.from_address(addr) # 从内存中直接解析成WTSTickStruct + realTick = WTSTickStruct.from_address( + addr + ) # 从内存中直接解析成WTSTickStruct tick = dict() tick["time"] = realTick.action_date * 1000000000 + realTick.action_time tick["open"] = realTick.open diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtDtServoApi.py b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtDtServoApi.py index f7fb8180..08515c0b 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtDtServoApi.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtDtServoApi.py @@ -6,6 +6,7 @@ LastEditors: Wesley LastEditTime: 2021-08-13 15:34:36 """ + import os from ctypes import c_bool from ctypes import c_char_p diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtDtWrapper.py b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtDtWrapper.py index 8fd10f35..efd14c40 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtDtWrapper.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtDtWrapper.py @@ -6,6 +6,7 @@ LastEditors: Wesley LastEditTime: 2021-08-13 15:26:16 """ + import os from ctypes import c_bool from ctypes import c_char_p @@ -78,7 +79,9 @@ def initialize( except OSError as oe: print(oe) - self.write_log(102, "WonderTrader datakit initialzied,version:%s" % (self.ver)) + self.write_log( + 102, "WonderTrader datakit initialzied,version:%s" % (self.ver) + ) def create_extended_parser(self, id: str) -> bool: return self.api.create_ext_parser(bytes(id, encoding="utf8")) diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtExecApi.py b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtExecApi.py index 9fdb984d..b4ea9a7b 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtExecApi.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtExecApi.py @@ -6,6 +6,7 @@ LastEditors: Wesley LastEditTime: 2021-08-13 15:35:25 """ + import os from ctypes import c_char_p from ctypes import cdll diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtMQWrapper.py b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtMQWrapper.py index 58b8a1ad..cdd8634f 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtMQWrapper.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtMQWrapper.py @@ -6,6 +6,7 @@ LastEditors: Wesley LastEditTime: 2021-08-13 15:35:07 """ + import os from ctypes import c_bool from ctypes import c_char diff --git a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtWrapper.py b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtWrapper.py index d9977f2d..b7deff4b 100644 --- a/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtWrapper.py +++ b/meta/env_future_trading/wt4elegantrl/wtpy/wrapper/WtWrapper.py @@ -336,7 +336,9 @@ def on_stra_get_tick( addr = addressof(curTick.contents) # 获取内存地址 ticks = [None] * count # 预先分配list的长度 for idx in range(count): - realTick = WTSTickStruct.from_address(addr) # 从内存中直接解析成WTSTickStruct + realTick = WTSTickStruct.from_address( + addr + ) # 从内存中直接解析成WTSTickStruct tick = dict() tick["time"] = realTick.action_date * 1000000000 + realTick.action_time tick["open"] = realTick.open @@ -729,7 +731,8 @@ def initialize_cta( self.write_log( 102, - "WonderTrader CTA production framework initialzied,version:%s" % (self.ver), + "WonderTrader CTA production framework initialzied,version:%s" + % (self.ver), ) def initialize_hft( @@ -780,7 +783,8 @@ def initialize_hft( self.write_log( 102, - "WonderTrader HFT production framework initialzied,version:%s" % (self.ver), + "WonderTrader HFT production framework initialzied,version:%s" + % (self.ver), ) def initialize_sel( @@ -820,7 +824,8 @@ def initialize_sel( self.write_log( 102, - "WonderTrader SEL production framework initialzied,version:%s" % (self.ver), + "WonderTrader SEL production framework initialzied,version:%s" + % (self.ver), ) def cta_enter_long( diff --git a/meta/env_portfolio_allocation/env_portfolio_yahoofinance.py b/meta/env_portfolio_allocation/env_portfolio_yahoofinance.py index d01c1177..f1f59077 100644 --- a/meta/env_portfolio_allocation/env_portfolio_yahoofinance.py +++ b/meta/env_portfolio_allocation/env_portfolio_yahoofinance.py @@ -1,4 +1,5 @@ """From FinRL https://github.com/AI4Finance-LLC/FinRL/tree/master/finrl/env""" + import gym import matplotlib import numpy as np diff --git a/meta/env_portfolio_optimization/env_portfolio_optimization.py b/meta/env_portfolio_optimization/env_portfolio_optimization.py index 64e2268d..31a85fd7 100644 --- a/meta/env_portfolio_optimization/env_portfolio_optimization.py +++ b/meta/env_portfolio_optimization/env_portfolio_optimization.py @@ -1,4 +1,5 @@ """From FinRL https://github.com/AI4Finance-LLC/FinRL/tree/master/finrl/env""" + import math import gym diff --git a/meta/factors/factors.py b/meta/factors/factors.py index 004964f9..0d40167f 100644 --- a/meta/factors/factors.py +++ b/meta/factors/factors.py @@ -104,7 +104,9 @@ def hhv(S, N): # hhv(C, 5) 最近5天收盘最高价 return pd.Series(S).rolling(N).max().values -def sma(S, N, M=1): # 中国式的SMA,至少需要120周期才精确 (雪球180周期) alpha=1/(1+com) +def sma( + S, N, M=1 +): # 中国式的SMA,至少需要120周期才精确 (雪球180周期) alpha=1/(1+com) return pd.Series(S).ewm(alpha=M / N, adjust=False).mean().values # com=N-M/M