# Print final result print("___MEMORY USAGE AFTER COMPLETION:___") mem_usg = props.memory_usage().sum() / 1024 ** 2 print("Memory usage is: {0} MB".format(mem_usg)) print("This is {0}% of the initial size".format(100 * mem_usg / start_mem_usg)) return props, NAlist if __name__ == "__main__": args = set_main_args() if args.nrows == -1: args.nrows = None logger_file = os.path.join(args.log_dir, args.model + "log.txt") logger = create_logger(logger_file, 1) print = logger.info # old feature (wrong) # sparse_features = ['C126', 'C121', 'C110', 'C106', 'C101', 'C139', 'C133', 'C109', 'C130', 'C141', 'C108', 'C120', # 'C132', 'C131', # 'C105', 'C137', 'C112', 'C115', 'C129', 'C119', 'C113', 'C136', 'C107', 'C138', 'C103', 'C123', # 'C111', 'C124', # 'C128', 'C140', 'C134', 'C116', 'C125', 'C122', 'C102', 'C135', 'C117', 'C118', 'C127'] # multivalue_cols = ['C104', 'C114'] all_sparse_features = ['C39', 'C35', 'C34', 'C37', 'C36', 'C31', 'C30', 'C33', 'C32', 'C153', 'C152', 'C151', 'C150', 'C157', 'C156', 'C155', 'C154', 'C159', 'C158', 'C22', 'C23', 'C21', 'C27', 'C24', 'C25', 'C28', 'C168', 'C169', 'C166', 'C167', 'C164', 'C165', 'C162', 'C163', 'C160', 'C161', 'C184', 'C56', 'C55', 'C54', 'C53', 'C52', 'C51', 'C50', 'C188', 'C189', 'C59', 'C58', 'C179', 'C178', 'C141', 'C186', 'C171', 'C170', 'C173', 'C172', 'C175',
""" unittest class to test email_notify.py. """ import unittest from src import email_notify from src.log import create_logger logger = create_logger(__name__) class TestEmail(unittest.TestCase): def testSendEmail(self) -> None: """ Test the email sending functionality. -> Assert the log message and status. """ with self.assertLogs('email_notify', 'INFO') as cm: notify = email_notify.Email('test.py ran (unittest)') notify.send() self.assertEqual(cm.output, ['INFO:email_notify:Successfully sent email.'], 'Email notification not sent.') def testSMTPPort(self) -> None: """ Test the correct SMTP port is used. -> Assert the port value. """ port = email_notify.PORT
def init(context): data_path = conf.data_path context.wx_key = conf.wx_token context.share_id = conf.share_account_id # 股票账户ID context.future_id = conf.future_account_id # 期货账户ID cache_path = os.path.join(data_path, "cache") if not os.path.exists(data_path): os.makedirs(cache_path) context.logger = create_logger(os.path.join(data_path, "backtest.log"), cmd=True, name="gm") context.data_path = data_path context.cache_path = cache_path context.file_orders = os.path.join(data_path, "orders.txt") # 交易因子定义 long_open_factors = [ '日线笔因子@C6C5C3L1A0~次级别三买', '日线笔因子@C6C5C3L1A1~次级别三买&次级别近五笔高点等于近九笔高点', '日线笔因子@C6C5C3L1A2~次级别三买&次级别近五笔低点等于近九笔低点', '日线笔因子@C6C4C2L1A0~次级别三买', '日线笔因子@C6C4C2L1A1~次级别三买&次级别近五笔高点等于近九笔高点', '日线笔因子@C6C4C2L1A2~次级别三买&次级别近五笔低点等于近九笔低点', '日线笔因子@C6C3C1L1A0~次级别三买', '日线笔因子@C6C3C1L1A1~次级别三买&次级别近五笔高点等于近九笔高点', '日线笔因子@C6C3C1L1A2~次级别三买&次级别近五笔低点等于近九笔低点', '日线笔因子@C6C5C3L1B0~本级别第N笔强底分&小级别近七笔为BaA式右侧底', '日线笔因子@C6C5C3L1B1~本级别第N笔强底分&小级别近七笔为BaA式右侧底&小级别近五笔为上颈线突破', '日线笔因子@C6C4C2L1B0~本级别第N笔强底分&小级别近七笔为BaA式右侧底', '日线笔因子@C6C4C2L1B1~本级别第N笔强底分&小级别近七笔为BaA式右侧底&小级别近五笔为上颈线突破', '日线笔因子@C6C3C1L1B0~本级别第N笔强底分&小级别近七笔为BaA式右侧底', '日线笔因子@C6C3C1L1B1~本级别第N笔强底分&小级别近七笔为BaA式右侧底&小级别近五笔为上颈线突破', '日线笔因子@C6C5C3L1C0~本级别第N笔强底分&次级别近五笔为上颈线突破', '日线笔因子@C6C4C2L1C0~本级别第N笔强底分&次级别近五笔为上颈线突破', '日线笔因子@C6C3C1L1C0~本级别第N笔强底分&次级别近五笔为上颈线突破', '日线笔因子@C6C5C3L2A1~次级别近五笔为底背弛&小级别近五笔为上颈线突破', '日线笔因子@C6C4C2L2A1~次级别近五笔为底背弛&小级别近五笔为上颈线突破', '日线笔因子@C6C3C1L2A1~次级别近五笔为底背弛&小级别近五笔为上颈线突破', '日线笔因子@C6C5C3L2B1~次级别近七笔为底背弛&小级别近五笔为上颈线突破', '日线笔因子@C6C4C2L2B1~次级别近七笔为底背弛&小级别近五笔为上颈线突破', '日线笔因子@C6C3C1L2B1~次级别近七笔为底背弛&小级别近五笔为上颈线突破', '日线笔因子@C6C5C3L2C2~次级别近九笔为底背弛&小级别近五笔为上颈线突破', '日线笔因子@C6C5C3L2C3~次级别近九笔为aAbBc式底背弛&小级别近五笔为上颈线突破', '日线笔因子@C6C4C2L2C2~次级别近九笔为底背弛&小级别近五笔为上颈线突破', '日线笔因子@C6C4C2L2C3~次级别近九笔为aAbBc式底背弛&小级别近五笔为上颈线突破', '日线笔因子@C6C3C1L2C2~次级别近九笔为底背弛&小级别近五笔为上颈线突破', '日线笔因子@C6C3C1L2C3~次级别近九笔为aAbBc式底背弛&小级别近五笔为上颈线突破', '日线笔因子@C6C5C3L3A0~60分钟近七笔为BaA式右侧底', '日线笔因子@C6C4C2L3A0~30分钟近七笔为BaA式右侧底', '日线笔因子@C6C3C1L3A0~15分钟近七笔为BaA式右侧底', '日线笔因子@C6C5C3L3B0~60分钟近五笔为上颈线突破', '日线笔因子@C6C4C2L3B0~30分钟近五笔为上颈线突破', '日线笔因子@C6C3C1L3B0~15分钟近五笔为上颈线突破' ] long_close_factors = [ '日线笔因子@C6C5C3S1A1~次级别三卖&小级别下颈线跌破', '日线笔因子@C6C4C2S1A1~次级别三卖&小级别下颈线跌破', '日线笔因子@C6C3C1S1A1~次级别三卖&小级别下颈线跌破', '日线笔因子@C6C5C3S1B1~次级别和小级别近五笔都为下颈线跌破', '日线笔因子@C6C4C2S1B1~次级别和小级别近五笔都为下颈线跌破', '日线笔因子@C6C3C1S1B1~次级别和小级别近五笔都为下颈线跌破', '日线笔因子@C6C5C3S2A1~次级别顶背弛&小级别下颈线跌破', '日线笔因子@C6C4C2S2A1~次级别顶背弛&小级别下颈线跌破', '日线笔因子@C6C3C1S2A1~次级别顶背弛&小级别下颈线跌破', '日线笔因子@C6C5C3S3A1~次级别下颈线跌破&小级别下颈线跌破', '日线笔因子@C6C4C2S3A1~次级别下颈线跌破&小级别下颈线跌破', '日线笔因子@C6C3C1S3A1~次级别下颈线跌破&小级别下颈线跌破', '日线笔因子@C6C5C3S4A0~小级别顶背驰', '日线笔因子@C6C4C2S4A0~小级别顶背驰', '日线笔因子@C6C3C1S4A0~小级别顶背驰' ] if context.mode == MODE_BACKTEST: # mp 小于1,按百分比下单 symbols_map = { # "SHSE.603027": {"mp": 0.8, "factors": {"long_open_factors": long_open_factors, # "long_close_factors": long_close_factors, # "version": "603027@2021-02-17"}}, # "SZSE.002739": {"mp": 0.8, "factors": {"long_open_factors": long_open_factors, # "long_close_factors": long_close_factors, # "version": "603027@2021-02-17"}}, "SZSE.002588": { "mp": 0.8, "factors": { "long_open_factors": long_open_factors, "long_close_factors": long_close_factors, "version": "002588@2021-02-17" } }, } subscribe(",".join(symbols_map.keys()), frequency='60s', count=300, wait_group=False) if context.mode == MODE_BACKTEST: context.logger.info("回测配置:") context.logger.info("backtest_start_time = " + str(context.backtest_start_time)) context.logger.info("backtest_end_time = " + str(context.backtest_end_time)) else: context.logger.info("\n\n") context.logger.info("=" * 88) context.logger.info("实盘开始 ...") for symbol in symbols_map.keys(): kg = get_init_kg(context, symbol, generator=KlineGeneratorBy1Min, max_count=1000) trader = GmTrader(kg, factors=symbols_map[symbol]["factors"]) symbols_map[symbol]['trader'] = trader context.logger.info("{} 初始化完成,当前时间:{}".format(symbol, trader.end_dt)) context.logger.info(f"交易配置:{symbols_map}") context.symbols_map = symbols_map