def test_cu_close(): env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='cu')) env.introduction = "" env.price = CLOSE data = REF(env, CLOSE, 10, CON_CONTRACT_1) print("data: %s", data) data = REFD(env, CLOSE, 10) print("data_d: %s", data)
def test_con2_con3_rate(): env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='cu')) env.introduction = "沪%s连2-连3合约高于预警指数%s元" # env.varieties = Cu # env.contract = CON_CONTRACT_2 # env.exchange = SHFE env.price = CON1_CON3_DIFF_RATE data = REFD(env, CON2_CON3_DIFF_RATE, n=10) print("连2-连3差价:", data)
def test_warrant_monthly_rate(): """ 仓单比 :return: """ env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='cu')) env.introduction = "沪%s交割月%s合约持仓:仓单环比连续上涨%s天" # env.varieties = Cu # env.source = SHFE env.price = WARRANT_MONTH_RATE data = REFD(env, WARRANT_MONTH_RATE, n=5) print("仓单环比data: ", data)
def test_doji_star_threshold(): env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='cu')) env.introduction = "SMM升贴水连续下跌3天" # env.contract = MAIN_CONTRACT # env.varieties = Cu # env.exchange = SHFE # env.price = FUTURE_LME data = REF(env, DOJI_STAR_THRESHOLD, 10) print("data: %s", data) data = REFD(env, DOJI_STAR_THRESHOLD, 10) print("带日期data: %s", data)
def test_spot_zn(): env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='zn')) # env.introduction = "沪%s交割月%s合约持仓:仓单环比连续上涨%s天" env.varieties = Zn # env.exchange = SHFE # env.source = SHMET # env.contract = CON_CONTRACT_1 env.price = SPOT data = REFD(env, SPOT, 3) print("现货价格data: ", data)
def test_lem_future(): env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='cu')) env.introduction = "SMM升贴水连续下跌3天" # env.contract = MAIN_CONTRACT # env.varieties = Cu # env.exchange = SHFE env.price = FUTURE_LME data = REF(env, FUTURE_LME, 10) print("data: %s", data) data = REFD(env, FUTURE_LME, 10) print("带日期data: %s", data)
def test_opi_monthly_rate(): """ 持仓比 :return: """ env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='cu')) env.introduction = "沪%s交割月%s合约持仓:仓单环比连续上涨%s天" # env.varieties = Cu # env.exchange = SHFE # env.contract = CON_CONTRACT_1 env.price = OPI_MONTH_RATE data = REFD(env, OPI_MONTH_RATE, n=2) print("持仓data: ", data)
def test_shfe_lme_rate(): """ 持仓比 :return: """ e = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='cu')) main_con = REF(e, MAIN_CONTRACT) e.result = REF(e, SHFE_LME_DIFF) if e.result and e.result[0] >= -300: e.alert = True e_variety = e.content_varieties_ch e.chart = SHFE_LME_DIFF print("持仓比主力合约: ", main_con) print("e.result: ", e.result)
def test_stock(): env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='cu')) # env.introduction = "SMM升贴水连续下跌3天" data = REF(env, STOCK, 10) # d1, d2, gd, rate = data_gap(data) print("铜总库存data: %s", data) # print("差值:", d1, d2, gd, rate) data = REFD(env, STOCK, 10) print("铜总库存带日期data: %s", data)
def test_nanchu_out(): env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='cu')) # env.introduction = "SMM升贴水连续下跌3天" data = REF(env, NANCHU_OUT, 10) # d1, d2, gd, rate = data_gap(data) print("南储仓电解铜出库data: %s", data) # print("差值:", d1, d2, gd, rate) data = REFD(env, NANCHU_OUT, 10) print("南储仓电解铜出库带日期data: %s", data)
def test_lme_warrant(): env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='cu')) # env.introduction = "SMM升贴水连续下跌3天" data = REF(env, LME_WARRANT, 10) # d1, d2, gd, rate = data_gap(data) print("LME仓单data: %s", data) # print("差值:", d1, d2, gd, rate) data = REFD(env, LME_WARRANT, 10) print("LME仓单带日期data: %s", data)
def test_con1_con3_rate(): env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='zn')) env.introduction = "沪%s连1-连3合约高于预警指数%s元" env.varieties = Zn env.contract = CON_CONTRACT_1 env.exchange = SHFE env.price = CON1_CON3_DIFF_RATE data = REFD(env, CON1_CON3_DIFF_RATE, n=3) print("连1-连3差价:", data)
def test_open_price(): env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='cu')) env.introduction = "沪铜开盘价连续下跌3天" env.contract = CON_CONTRACT_1 env.varieties = Cu env.exchange = SHFE env.price = OPEN data = REFD(env, OPEN, 10) # d1, d2, gd, rate = data_gap(data) print("data: %s", data)
def do_handle(self, pre_data): for f, db_id, unit in self.formulas(pre_data.get_variety()): env = FormulaEnv(db_id, unit, pre_data) share_formula = ShareFormula(db_id, f) executor = WorkerFormulaExecutor(share_formula, env, out_logger=logger) try: executor.run() self._pub_alert_msg(env) except Exception as e: logger.error("公式%s出现了异常%s, 上下文是%s", db_id, traceback.format_exc(), env) continue
def test_exchange_rate(): """ 持仓比 :return: """ env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='cu')) env.introduction = "汇率" env.varieties = Cu env.exchange = SHFE env.contract = CON_CONTRACT_1 env.price = EXCHANGE data = REFD(env, EXCHANGE, n=10) print("汇率data: ", data)
def test_cross_star(): """ 十字星 :return: """ env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='cu')) env.introduction = "沪铜十字星" env.contract = MAIN_CONTRACT env.varieties = Cu env.exchange = SHFE env.price = CROSS_STAR data = REFD(env, CROSS_STAR, n=10) print("十字星data: ", data)
def test_DAYSTOEXPIRED(): env = FormulaEnv(id=2, unit="", pre_data=DBPreProcess(id=1, varieties='zn')) DAYSTOEXPIRED(env,CON_CONTRACT_1)