當前位置: 首頁>>代碼示例>>Python>>正文


Python PairRunner.run方法代碼示例

本文整理匯總了Python中mewp.simulate.runner.PairRunner.run方法的典型用法代碼示例。如果您正苦於以下問題:Python PairRunner.run方法的具體用法?Python PairRunner.run怎麽用?Python PairRunner.run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mewp.simulate.runner.PairRunner的用法示例。


在下文中一共展示了PairRunner.run方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: back_test

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
def back_test(pair, date, param):
    algo = { 'class': StopWinAlgo }
    algo['param'] = {'x': pair[0],
                     'y': pair[1],
                     'a': 1,
                     'b': 0,
                     'rolling': param[0],
                     'alpha': -1,
                     'bollinger': param[1],
                     'stop_win': param[2],
                     'block': 100,

                     'if_stop_win': True,
                     'if_ema': False,
                     'if_consider_spread': True,
                     }
    settings = { 'date': date,
                 'path': DATA_PATH,
                 'tickset': 'top',
                 'algo': algo}
    runner = PairRunner(settings)
    runner.run()
    account = runner.account
    history = account.history.to_dataframe(account.items)
    score = float(history[['pnl']].iloc[-1])
    return score
開發者ID:Coderx7,項目名稱:CNN,代碼行數:28,代碼來源:day_return.py

示例2: back_test

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
def back_test(pair, date, param):
    tracker = TradeAnalysis(Contract(pair[0]))
    algo = { 'class': ConstantAlgo }
    algo['param'] = {'x': pair[0],
                     'y': pair[1],
                     'a': 1,
                     'b': 0,
                     'rolling': param[0],
                     'bollinger': param[1],
                     'const': param[2],
                     'block': 100,
                     'tracker': tracker
                     }
    settings = { 'date': date,
                 'path': DATA_PATH,
                 'tickset': 'top',
                 'algo': algo,
                 'singletick': True}
    runner = PairRunner(settings)
    runner.run()
    account = runner.account
    history = account.history.to_dataframe(account.items)
    score = float(history[['pnl']].iloc[-1])
    order_win = tracker.order_winning_ratio()
    order_profit = tracker.analyze_all_profit()[0]
    num_rounds = tracker.analyze_all_profit()[2]
    return score, order_win, order_profit, num_rounds, runner
開發者ID:Coderx7,項目名稱:CNN,代碼行數:29,代碼來源:pb.py

示例3: run_simulation

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
def run_simulation(param, date_list):
    algo = { 'class': ConstStopWinGuardAlgo }
    algo['param'] = {'x': 'ni1609',
                     'y': 'ni1701',
                     'a': 1,
                     'b': 0,
                     'rolling': param[0],
                     'bollinger': 2,
                     'const': param[1],
                     'stop_win':param[2],
                     'block': 100,
                     'tracker': None
                    }
    settings = { 'date': date_list,
                 'path': DATA_PATH,
                 'tickset': 'top',
                 'algo': algo,
                 'singletick': False}
    settings['exe'] = PairExePlusTick(2)
    runner = PairRunner(settings)
    runner.run()
    report = Report(runner)
    temp = report.get_daily_pnl()
    pnl_list = list(temp.daily_pnl)
    return pnl_list
開發者ID:volpato30,項目名稱:Backtest,代碼行數:27,代碼來源:stopwin_slipery.py

示例4: back_test

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
def back_test(pair, date, param, tracker):
    algo = {"class": StopWinSpreadGuardAlgo}
    algo["param"] = {
        "x": pair[0],
        "y": pair[1],
        "a": 1,
        "b": 0,
        "rolling": param[0],
        "bollinger": param[1],
        "stop_win": param[2],
        "block": 100,
        "tracker": tracker,
    }
    settings = {"date": date, "path": DATA_PATH, "tickset": "top", "algo": algo, "singletick": True}
    runner = PairRunner(settings)
    runner.run()
    return runner, algo
開發者ID:Coderx7,項目名稱:CNN,代碼行數:19,代碼來源:au.py

示例5: back_test

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
def back_test(pair, date):
    algo = { 'class': TestAlgo }
    algo['param'] = {'x': pair[0],
                     'y': pair[1],
                     'a': 1,
                     'b': 0,
                     'rolling': 4000,
                     'sd_coef': 3,
                     'block': 100,
                     }
    settings = { 'date': date,
                 'path': DATA_PATH,
                 'tickset': 'top',
                 'algo': algo}
    runner = PairRunner(settings)
    runner.run()
    return runner
開發者ID:Coderx7,項目名稱:CNN,代碼行數:19,代碼來源:cu_shfe.py

示例6: back_test

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
def back_test(pair, date, param, tracker):
    algo = { 'class': SpreadGuardAlgo }
    algo['param'] = {'x': pair[0],
                     'y': pair[1],
                     'a': 1,
                     'b': 0,
                     'rolling': param[0],
                     'bollinger': param[1],
                     'block': 100,
                     'tracker': tracker,
                     }
    settings = { 'date': date,
                 'path': DATA_PATH,
                 'tickset': 'top',
                 'algo': algo,
                 'singletick': True}
    runner = PairRunner(settings)
    runner.run()
    return runner, algo
開發者ID:Coderx7,項目名稱:CNN,代碼行數:21,代碼來源:al.py

示例7: run_based_on_pre

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
def run_based_on_pre(date_list):
    temp = best_param(date_list[:-1])
    algo = { 'class': TestAlgo }
    algo['param'] = {'x': pair[0],
                    'y': pair[1],
                    'a': 1,
                    'b': 0,
                    'rolling': float(temp.rolling),
                    'sd_coef': float(temp.sd_coef),
                    'block': 100}
    settings = { 'date': date_list[-1],
                'path': DATA_PATH,
                'tickset': 'top',
                'algo': algo}
    runner = PairRunner(settings)
    runner.run()
    account = runner.account
    orders = account.orders.to_dataframe()
    history = account.history.to_dataframe(account.items)
    return float(history.pnl.tail(1)), len(orders)
開發者ID:Coderx7,項目名稱:CNN,代碼行數:22,代碼來源:rolling_parameters.py

示例8: back_test

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
def back_test(pair, date, param):
    algo = {"class": StopWinAlgo}
    algo["param"] = {
        "x": pair[0],
        "y": pair[1],
        "a": 1,
        "b": 0,
        "rolling": param[0],
        "alpha": -1,
        "bollinger": param[1],
        "stop_win": param[2],
        "block": 100,
        "if_stop_win": True,
        "if_ema": False,
        "if_consider_spread": True,
    }
    settings = {"date": date, "path": DATA_PATH, "tickset": "top", "algo": algo}
    runner = PairRunner(settings)
    runner.run()
    return runner
開發者ID:Coderx7,項目名稱:CNN,代碼行數:22,代碼來源:shfe.py

示例9: back_test

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
def back_test(pair, date, param):
    algo = { 'class': TestAlgo }
    algo['param'] = {'x': pair[0],
                     'y': pair[1],
                     'a': 1,
                     'b': 0,
                     'rolling': param[0],
                     'sd_coef': param[1],
                     'block': 100,
                     }
    settings = { 'date': date,
                 'path': DATA_PATH,
                 'tickset': 'top',
                 'algo': algo}
    runner = PairRunner(settings)
    runner.run()
    account = runner.account
    history = account.history.to_dataframe(account.items)
    orders = account.orders.to_dataframe()
    pnl = np.asarray(history.pnl)[-1]
    return pnl, len(orders)
開發者ID:Coderx7,項目名稱:CNN,代碼行數:23,代碼來源:Parallel.py

示例10: back_test

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
def back_test(pair, date, param, if_param):
    algo = { 'class': StopWinAlgo }
    algo['param'] = {'x': pair[0],
                     'y': pair[1],
                     'a': 1,
                     'b': 0,
                     'rolling': param[0],
                     'alpha': param[1],
                     'bollinger': param[2],
                     'stop_win': param[3],
                     'block': 100,

                     'if_stop_win': if_param[0],
                     'if_ema': if_param[1],
                     'if_consider_spread': if_param[2],
                     }
    settings = { 'date': date,
                 'path': DATA_PATH,
                 'tickset': 'top',
                 'algo': algo}
    runner = PairRunner(settings)
    runner.run()
    return runner
開發者ID:Coderx7,項目名稱:CNN,代碼行數:25,代碼來源:al.py

示例11: back_test

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
def back_test(pair, date, param):
    tracker = TradeAnalysis(Contract(pair[0]))
    algo = {"class": OUAlgo}
    algo["param"] = {
        "x": pair[0],
        "y": pair[1],
        "a": 1,
        "b": 0,
        "rolling": param[0],
        "bollinger": param[1],
        "block": 100,
        "tracker": tracker,
    }
    settings = {"date": date, "path": DATA_PATH, "tickset": "top", "algo": algo, "singletick": True}
    runner = PairRunner(settings)
    runner.run()
    account = runner.account
    history = account.history.to_dataframe(account.items)
    score = float(history[["pnl"]].iloc[-1])
    order_win = tracker.order_winning_ratio()
    order_profit = tracker.analyze_all_profit()[0]
    num_rounds = tracker.analyze_all_profit()[2]
    return score, order_win, order_profit, num_rounds
開發者ID:Coderx7,項目名稱:CNN,代碼行數:25,代碼來源:au_OU.py

示例12: PairRunner

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
                 'rolling': 1000,
                 'rolling_sigma': 1000,
                 'sd_coef': 3,
                 'block': 100,
                 }
settings = { 'date': date_list,
             'path': DATA_PATH,
             'tickset': 'top',
             'algo': algo}
runner = PairRunner(settings)
rolling_list = range(500,5000,500)
rolling_sigma_list = range(500,5000,500)
sd_coef_list = np.arange(1, 5, 0.5)
final_profit = []
for r in rolling_list :
    for rs in rolling_sigma_list:
        for sd in sd_coef_list :
            start_time = time.time()
            runner.run(algo_param={'rolling': r,'rolling_sigma': rs, 'sd_coef': sd})
            account = runner.account
            history = account.history.to_dataframe(account.items)
            score = float(history[['pnl']].iloc[-1])
            final_profit.append(score)
            print("rolling {}, rolling sigma {}, sd_coef {}, backtest took {:.3f}s, score is {:.3f}".format(r, rs, sd, time.time() - start_time, score))
pars = list(itertools.product(rolling_list, rolling_sigma_list, sd_coef_list))
result = pd.DataFrame({"rolling": [p[0] for p in pars],
                       "rolling_sigma": [p[1] for p in pars],
                       "sd_coef": [p[2] for p in pars],
                       "PNL": [float(f) for f in final_profit]})
pickle.dump(result, open( "if_16Mar.p", "wb" ))
開發者ID:Coderx7,項目名稱:CNN,代碼行數:32,代碼來源:if_16Mar.py

示例13: PairRunner

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
                 'stop_win': 200,
                 }
settings = { 'date': date_list,
             'path': DATA_PATH,
             'tickset': 'top',
             'algo': algo}

runner = PairRunner(settings)
price_diff = get_price_diff(pair)
price_diff_std = np.nanstd(price_diff)
rolling_list = range(1000,10000,2000)
sd_coef_list = np.arange(2,8)
stop_win_list = price_diff_std * np.arange(0.5, 3.5, 0.5)
final_profit = []
for r in rolling_list :
    for sd in sd_coef_list :
        for sw in stop_win_list:
            start_time = time.time()
            runner.run(algo_param={'rolling': r,  'sd_coef': sd, 'stop_win': sw })
            account = runner.account
            history = account.history.to_dataframe(account.items)
            score = float(history[['pnl']].iloc[-1])
            final_profit.append(score)
            print("rolling {}, sd_coef {}, stop_win {}, backtest took {:.3f}s, score is {:.3f}".format(r, sd, sw, time.time() - start_time, score))
pars = list(itertools.product(rolling_list, sd_coef_list, stop_win_list))
result = pd.DataFrame({"rolling": [p[0] for p in pars],
                       "sd_coef": [p[1] for p in pars],
                       "stop_win": [p[2] for p in pars],
                       "PNL": [float(f) for f in final_profit]})
pickle.dump(result, open( "grid_search_one_roll_cs.p", "wb" ) )
開發者ID:Coderx7,項目名稱:CNN,代碼行數:32,代碼來源:grid_search_one_roll_cs.py

示例14: PairRunner

# 需要導入模塊: from mewp.simulate.runner import PairRunner [as 別名]
# 或者: from mewp.simulate.runner.PairRunner import run [as 別名]
}
settings = {"date": date_list, "path": DATA_PATH, "tickset": "top", "algo": algo}
runner = PairRunner(settings)
price_diff = get_price_diff(pair)
price_diff_std = np.nanstd(price_diff)
rolling_list = range(1000, 10000, 2000)
rolling_sigma_list = range(1000, 10000, 2000)
sd_coef_list = np.arange(2, 8)
stop_win_list = price_diff_std * np.arange(0.3, 3, 0.3)
final_profit = []
for r in rolling_list:
    for rs in rolling_sigma_list:
        for sd in sd_coef_list:
            for sw in stop_win_list:
                start_time = time.time()
                runner.run(algo_param={"rolling": r, "rolling_sigma": rs, "sd_coef": sd, "stop_win": sw})
                account = runner.account
                history = account.history.to_dataframe(account.items)
                score = float(history[["pnl"]].iloc[-1])
                final_profit.append(score)
                print(
                    "rolling {}, rolling_sigma {}, sd_coef {}, stop_win {}, backtest took {:.3f}s, score is {:.3f}".format(
                        r, rs, sd, sw, time.time() - start_time, score
                    )
                )
pars = list(itertools.product(rolling_list, rolling_sigma_list, sd_coef_list, stop_win_list))
result = pd.DataFrame(
    {
        "rolling": [p[0] for p in pars],
        "rolling_sigma": [p[1] for p in pars],
        "sd_coef": [p[2] for p in pars],
開發者ID:Coderx7,項目名稱:CNN,代碼行數:33,代碼來源:grid_search_two_roll_m.py


注:本文中的mewp.simulate.runner.PairRunner.run方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。