如果Quantstrat在几天之内通过几个信号生成订单,我对它的确切位置感到有些困惑。我正在尝试实施一个简单的配对交易策略(零既是进入和退出阈值),所以当z-score翻转其符号时,应为每个符号生成两个信号(卖出很长 - >卖出卖空或封面短 - >购买长)。问题是QS总是忽略退出顺序(使其被后续的输入顺序“替换”)。我该怎么做才能防止信号被替换或取消?是否可以在一个条上执行多个订单?
这是我的设置。信号:
add.signal( strategy = strategy_st,
name = 'sigFormula',
arguments = list( columns = c('score', 'entry_threshold'),
formula = 'score > entry_threshold',
cross = TRUE
),
label = 'sigEnterUpper')
add.signal( strategy = strategy_st,
name = 'sigFormula',
arguments = list( columns = c('score', 'entry_threshold'),
formula = 'score <= -entry_threshold',
cross = TRUE
),
label = 'sigEnterLower')
#exit
add.signal( strategy = strategy_st,
name = 'sigFormula',
arguments = list( columns = c('score', 'exit_threshold'),
formula = 'score <= exit_threshold',
cross = TRUE
),
label = 'sigExitUpper')
add.signal( strategy = strategy_st,
name = 'sigFormula',
arguments = list( columns = c('score', 'exit_threshold'),
formula = 'score >= -exit_threshold',
cross = TRUE
),
label = 'sigExitLower')
规则:
#entries
#longs
add.rule( strategy = strategy_st,
name = 'ruleSignal',
label = 'increase_long_up',
arguments = list( sigcol = 'sigEnterUpper',
sigval = TRUE,
orderqty = default_order_quantity,
ordertype = 'market',
orderside = 'long',
osFUN = orderSizeIncrease),
type = 'enter',
path.dep = TRUE
)
add.rule( strategy = strategy_st,
name = 'ruleSignal',
label = 'increase_long_low',
arguments = list( sigcol = 'sigEnterLower', #sigcol = 'sigFlipper', #sigcol = 'sigStartTrading',
sigval = TRUE,
orderqty = default_order_quantity,
ordertype = 'market',
orderside = 'long',
osFUN = orderSizeIncrease),
type = 'enter',
path.dep = TRUE)
#shorts
add.rule( strategy = strategy_st,
name = 'ruleSignal',
label = 'increase_short_up',
arguments = list( sigcol = 'sigEnterUpper', #sigcol = 'sigFlipper', #sigcol = 'sigStartTrading',
sigval = TRUE,
orderqty = default_order_quantity,
ordertype = 'market',
orderside = 'short',
osFUN = orderSizeIncrease),
type = 'enter',
path.dep = TRUE)
add.rule( strategy = strategy_st,
name = 'ruleSignal',
label = 'increase_short_low',
arguments = list( sigcol = 'sigEnterLower', #sigcol = 'sigFlipper', #sigcol = 'sigStartTrading',
sigval = TRUE,
orderqty = default_order_quantity,
ordertype = 'market',
orderside = 'short',
osFUN = orderSizeIncrease),
type = 'enter',
path.dep = TRUE)
#exits
add.rule( strategy = strategy_st,
name = 'ruleSignal',
label = 'close_position_up',
arguments = list( sigcol = 'sigExitUpper',
sigval = TRUE,
orderqty = 'all',
ordertype = 'market',
orderside = NULL),
type = 'exit')
add.rule( strategy = strategy_st,
name = 'ruleSignal',
label = 'close_position_low',
arguments = list( sigcol = 'sigExitLower',
sigval = TRUE,
orderqty = 'all',
ordertype = 'market',
orderside = NULL),
type = 'exit')
生成的信号:
EWA.Close score entry_threshold exit_threshold sigEnterUpper sigEnterLower sigExitUpper sigExitLower
2006-04-04 22.95 0.00000000 0 0 NA NA NA NA
2006-04-05 22.78 0.00000000 0 0 NA NA NA NA
2006-04-06 22.94 0.00000000 0 0 NA NA NA NA
2006-04-07 23.05 0.00000000 0 0 NA NA NA NA
2006-04-08 23.32 0.00000000 0 0 NA NA NA NA
2006-04-09 23.12 0.00000000 0 0 NA NA NA NA
2006-04-10 23.01 0.00000000 0 0 NA NA NA NA
2006-04-11 23.33 0.00000000 0 0 NA NA NA NA
2006-04-12 23.23 0.00000000 0 0 NA NA NA NA
2006-04-13 23.54 0.00000000 0 0 NA NA NA NA
2006-04-14 23.56 0.00000000 0 0 NA NA NA NA
2006-04-15 23.17 0.00000000 0 0 NA NA NA NA
2006-04-16 22.76 0.00000000 0 0 NA NA NA NA
2006-04-17 22.20 0.00000000 0 0 NA NA NA NA
2006-04-18 22.29 0.00000000 0 0 NA NA NA NA
2006-04-19 21.79 0.00000000 0 0 NA NA NA NA
2006-04-20 21.47 0.00000000 0 0 NA NA NA NA
2006-04-21 21.55 0.00000000 0 0 NA NA NA NA
2006-04-22 21.35 0.00000000 0 0 NA NA NA NA
2006-04-23 21.37 0.00000000 0 0 NA NA NA NA
2006-04-24 21.15 0.00000000 0 0 NA NA NA NA
2006-04-25 21.99 0.00000000 0 0 NA NA NA NA
2006-04-26 22.20 1.89349767 0 0 NA 1 NA 1
2006-04-27 22.10 2.05270575 0 0 NA NA NA NA
2006-04-28 22.38 2.68490142 0 0 NA NA NA NA
2006-04-29 22.38 2.40434146 0 0 NA NA NA NA
2006-04-30 22.60 1.87012946 0 0 NA NA NA NA
2006-05-01 22.09 1.42771737 0 0 NA NA NA NA
2006-05-02 21.86 1.49838977 0 0 NA NA NA NA
2006-05-03 21.44 1.18071344 0 0 NA NA NA NA
2006-05-04 21.04 0.59868857 0 0 NA NA NA NA
2006-05-05 21.32 0.85730960 0 0 NA NA NA NA
2006-05-06 21.02 0.77078417 0 0 NA NA NA NA
2006-05-07 20.23 0.74856764 0 0 NA NA NA NA
2006-05-08 20.41 -0.01843937 0 0 1 NA 1 NA #I expect to cover short and buy long here
2006-05-09 21.00 -0.26363152 0 0 NA NA NA NA
2006-05-10 20.78 -0.44662726 0 0 NA NA NA NA
2006-05-11 20.32 -0.71957534 0 0 NA NA NA NA
2006-05-12 20.29 -0.76088199 0 0 NA NA NA NA
生成的订单:
Order.Qty Order.Price Order.Type Order.Side Order.Threshold Order.Status Order.StatusTime Prefer Order.Set Txn.Fees Rule Time.In.Force
2006-04-26 "-1.046" "22.2" "market" "short" NA "closed" "2006-04-27 00:00:00" "" NA "0" "increase_short_low" ""
2006-05-08 "all" "20.41" "market" "short" NA "replaced" "2006-05-08" "" NA "0" "close_position_up" ""
2006-05-08 "1.046" "20.41" "market" "long" NA "closed" "2006-05-09 00:00:00" "" NA "0" "increase_long_up" ""
答案 0 :(得分:0)
是的,您必须将replace
中的ruleSignal
参数设置为FALSE
。否则,除了给定时间符号的最后处理顺序以外的所有顺序都将被替换为最后顺序。