예제 #1
0
from wtpy import WtBtEngine, EngineType
from wtpy.apps import WtBtAnalyst

from Strategies.DualThrust import StraDualThrust

# from Strategies.XIM import XIM

if __name__ == "__main__":
    #创建一个运行环境,并加入策略
    engine = WtBtEngine(EngineType.ET_CTA)
    engine.init('./common/', "configbt.json")
    engine.configBacktest(201909100930, 201912011500)
    engine.configBTStorage(mode="csv", path="./storage/")
    engine.commitBTConfig()

    straInfo = StraDualThrust(name='pydt_IF',
                              code="CFFEX.IF.HOT",
                              barCnt=50,
                              period="m5",
                              days=30,
                              k1=0.1,
                              k2=0.1,
                              isForStk=False)
    engine.set_cta_strategy(straInfo)

    engine.run_backtest()

    analyst = WtBtAnalyst()
    analyst.add_strategy("pydt_IF",
                         folder="./outputs_bt/pydt_IF/",
                         init_capital=500000,
예제 #2
0
파일: runBT.py 프로젝트: zhnlk/wtpy
from wtpy import WtBtEngine,EngineType
from Strategies.DualThrust import StraDualThrust
from wtpy import WtBtAnalyst

if __name__ == "__main__":
    #创建一个运行环境,并加入策略
    engine = WtBtEngine(EngineType.ET_CTA)
    engine.init(folder='./common/', cfgfile="configbt.json", commfile="stk_comms.json", contractfile="stocks.json")
    engine.configBacktest(201901010930,201912151500)
    engine.configBTStorage(mode="csv", path="./storage/")
    engine.commitBTConfig()
    
    straInfo = StraDualThrust(name='pydt_SH600000', code="SSE.600000", barCnt=50, period="d1", days=30, k1=0.1, k2=0.1, isForStk=True)
    engine.set_cta_strategy(straInfo)

    engine.run_backtest()

    #绩效分析
    analyst = WtBtAnalyst()
    analyst.add_strategy("pydt_SH600000", folder="./outputs_bt/pydt_SH600000/", init_capital=5000, rf=0.02, annual_trading_days=240)
    analyst.run()

    kw = input('press any key to exit\n')
    engine.release_backtest()
예제 #3
0
from wtpy import WtBtEngine
from wtpy.backtest import WtBtAnalyst

from Strategies.DualThrust import StraDualThrust

# from Strategies.XIM import XIM

if __name__ == "__main__":
    #创建一个运行环境,并加入策略
    engine = WtBtEngine()
    engine.init('.\\Common\\', "configbt.json")
    engine.configBacktest(201909100930, 201912011500)
    engine.configBTStorage(mode="csv", path=".\\storage\\")
    engine.commitBTConfig()

    straInfo = StraDualThrust(name='pydt_IF',
                              code="CFFEX.IF.HOT",
                              barCnt=50,
                              period="m5",
                              days=30,
                              k1=0.1,
                              k2=0.1,
                              isForStk=False)
    engine.set_strategy(straInfo)

    engine.run_backtest()

    analyst = WtBtAnalyst()
    analyst.add_strategy("pydt_IF",
                         folder="./outputs_bt/pydt_IF/",
                         init_capital=500000,
예제 #4
0
    def __execute_task__(self, params: dict):
        '''
        执行单个回测任务\n

        @params kv形式的参数
        '''
        name = params["name"]
        f = open("logcfg_tpl.json", "r")
        content = f.read()
        f.close()
        content = content.replace("$NAME$", name)
        engine = WtBtEngine(eType=EngineType.ET_CTA,
                            logCfg=content,
                            isFile=False)
        engine.init(self.env_params["deps_dir"], self.env_params["cfgfile"])
        engine.configBacktest(self.env_params["start_time"],
                              self.env_params["end_time"])
        engine.configBTStorage(mode=self.env_params["storage_type"],
                               path=self.env_params["storage_path"],
                               dbcfg=self.env_params["db_config"])
        engine.commitBTConfig()

        straInfo = self.strategy_type(**params)
        engine.set_cta_strategy(straInfo)

        engine.run_backtest()
        engine.release_backtest()

        self.__ayalyze_result__(name, params)
예제 #5
0
from wtpy import WtBtEngine, EngineType
from wtpy.apps import WtBtAnalyst

from Strategies.T1 import StraT1

if __name__ == "__main__":
    #创建一个运行环境,并加入策略
    engine = WtBtEngine(EngineType.ET_CTA)
    engine.init('.\\Common\\', "configbt.json")
    engine.configBacktest(201902010900, 202102101500)
    engine.configBTStorage(mode="csv", path=".\\storage\\")
    engine.commitBTConfig()

    straInfo = StraT1(name='t1_rb_i',
                      code1="SHFE.rb.HOT",
                      code2="DCE.i.HOT",
                      bar_cnt=400,
                      period="m1",
                      N=360,
                      threshold=0.9)
    engine.set_cta_strategy(straInfo)

    engine.run_backtest()

    analyst = WtBtAnalyst()
    analyst.add_strategy("t1_rb_i",
                         folder="./outputs_bt/t1_rb_i/",
                         init_capital=350000,
                         rf=0.02,
                         annual_trading_days=240)
    analyst.run_new()
예제 #6
0
from wtpy import WtBtEngine

if __name__ == "__main__":
    #创建一个运行环境,并加入策略
    env = WtBtEngine()
    '''
    WonderTrader需要的基础数据周期,只有1分钟、5分钟和日线
    其他周期都是在这基础上拼接出来的
    3分钟线,不能被5整除,所以用1分钟线拼接
    15分钟线,可以被5整除,所以用5分钟线拼接
    '''
    # 将从MC导出的CSV格式的5分钟线,放到./csv_m5/下,然后批量转换
    env.trans_mc_bars("./csv_m5/", "./bin_m5/", "m5")

    # 将从MC导出的CSV格式的日线线,放到./csv_d/下,然后批量转换
    env.trans_mc_bars("./csv_d/", "./bin_d/", "d")

    kw = input('press any key to exit\n')
예제 #7
0
파일: runBT.py 프로젝트: zhuzhenping/wtpy
from wtpy import WtBtEngine, EngineType

from Strategies.DualThrust_Sel import StraDualThrustSel

# from Strategies.XIM import XIM

if __name__ == "__main__":
    #创建一个运行环境,并加入策略
    engine = WtBtEngine(EngineType.ET_SEL)
    engine.init('.\\Common\\', "configbt.json")
    engine.configBacktest(201909100900, 202008071500)
    engine.configBTStorage(mode="csv", path=".\\storage\\")
    engine.commitBTConfig()

    straInfo = StraDualThrustSel(
        name='DT_COMM_SEL',
        codes=["CFFEX.IF.HOT", "SHFE.rb.HOT", "DCE.i.HOT"],
        barCnt=50,
        period="m5",
        days=30,
        k1=0.1,
        k2=0.1)
    engine.set_sel_strategy(straInfo, time=5, period="min")

    engine.run_backtest()

    kw = input('press any key to exit\n')
    engine.release_backtest()
예제 #8
0
파일: runBT.py 프로젝트: onestarshang/wtpy
from wtpy import WtBtEngine, EngineType
from strategies.HftStraDemo import HftStraDemo

if __name__ == "__main__":
    # 创建一个运行环境,并加入策略
    engine = WtBtEngine(EngineType.ET_HFT)
    engine.init('./common/', "configbt.json")
    engine.configBacktest(202101040900, 202101181500)
    engine.configBTStorage(mode="csv", path="./storage/")
    engine.commitBTConfig()

    straInfo = HftStraDemo(name='hft_IF',
                           code="CFFEX.IF.HOT",
                           expsecs=5,
                           offset=0,
                           freq=10)

    engine.set_hft_strategy(straInfo)

    engine.run_backtest()

    kw = input('press any key to exit\n')
    engine.release_backtest()