Skip to content
All library documents

Configuring a CTA Trading Engine and Portfolio Risk Monitor

Code WonderTrader

Summary

This configuration example sets up a CTA environment for a trading engine, including references to commodity, contract, holiday, session, fee, filter, execution, parser, and trader configuration files. It selects a trading session template and configures data storage and message publication. The example is useful as an overview of the components needed to assemble a futures trading environment.

It also enables a simple portfolio risk monitor with a base capital setting, periodic calculations, an intraday trailing drawdown threshold, and a risk scale that reduces the target position passed to execution. Multi-day trailing risk is disabled in this example. These are illustrative settings rather than recommended defaults: the document provides no explanation of calibration, testing, asset coverage, or observed results, and the risk behavior depends on the associated platform modules and referenced files.

Key ideas

  • The configuration connects market reference files, storage, fees, filters, execution, and trading channels.
  • The environment is set to run a CTA engine using a broad trading-session template.
  • The enabled risk monitor uses intraday trailing drawdown controls and scales target positions.
  • Multi-day trailing risk is disabled in the sample, and no evidence supports the example settings as general recommendations.

Tags

Full text
# config.yaml


```yaml
#基础配置文件
basefiles:
    commodity: ../common/commodities.json   #品种列表
    contract: ../common/contracts.json      #合约列表
    holiday: ../common/holidays.json        #节假日列表
    hot: ../common/hots.json                #主力合约映射表
    session: ../common/sessions.json        #交易时间模板
    uft-8: true                             #基础文件是否是UFT8编码,这个一定要和文件编码统一!!!
#数据存储
data:
    store:
        module: WtDataStorage   #模块名
        path: ../storage/      #数据存储根目录
        #his_path: ''           #历史数据存储目录,如果历史数据存储目录是单独的,则可以通过该配置项进行设置
#环境配置
env:
    name: cta               #引擎名称:cta/hft/sel
    fees: ../common/fees.json   #佣金配置文件
    filters: filters.yaml       #过滤器配置文件,这个主要是用于盘中不停机干预的
    product:
        session: TRADING    #驱动交易时间模板,TRADING是一个覆盖国内全部交易品种的最大的交易时间模板,从夜盘21点到凌晨1点,再到第二天15:15,详见sessions.json
    riskmon:                #组合风控设置
        active: true            #是否开启
        module: WtRiskMonFact   #风控模块名,会根据平台自动补齐模块前缀和后缀
        name: SimpleRiskMon     #风控策略名,会自动创建对应的风控策略
        #以下为风控指标参数,该风控策略的主要逻辑就是日内和多日的跟踪止损风控,如果回撤超过阈值,则降低仓位
        base_amount: 5000000    #组合基础资金,WonderTrader只记录资金的增量,基础资金是用来模拟组合的基本资金用的,和增量相加得到动态权益
        basic_ratio: 101        #日内高点百分比,即当日最高动态权益是上一次的101%才会触发跟踪侄止损
        calc_span: 5            #计算时间间隔,单位s
        inner_day_active: true  #日内跟踪止损是否启用
        inner_day_fd: 20.0      #日内跟踪止损阈值,即如果收益率从高点回撤20%,则触发风控
        multi_day_active: false #多日跟踪止损是否启用
        multi_day_fd: 60.0      #多日跟踪止损阈值
        risk_scale: 0.3         #风控系数,即组合给执行器的目标仓位,是组合理论仓位的0.3倍,即真实仓位是三成仓
        risk_span: 30           #风控触发时间间隔,单位s。因为风控计算很频繁,如果已经触发风控,不需要每次重算都输出风控日志,加一个时间间隔,友好一些
    
executers: executers.yaml   #执行器配置文件
parsers: tdparsers.yaml     #行情通达配置文件
traders: tdtraders.yaml     #交易通道配置文件
bspolicy: actpolicy.yaml    #开平策略配置文件

notifier:
    active: true                    #是否向外发布消息
    url: ipc:///wtpy/wt_cat_fut.ipc #MQ发布地址,可以根据需要改成自己的地址

```

Shown in full with attribution under the source's licence. Licence: MIT

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.