我正在使用系统投资者工具箱(SIT)在R中回测我的策略。目前,我正在使用此函数在回测中使用它作为fixed stop loss。
stop.loss <- function(weight, price, tstart, tend, pstop) {
index = tstart : tend
if(weight > 0)
price[ index ] < (1 - pstop) * price[ tstart ]
else
price[ index ] > (1 + pstop) * price[ tstart ]
}
#The stop loss function
Stoploss = .25/100
#Set our maximum loss at a .25% move in price against our trade
data$weight[] = NA
data$weight[] = custom.stop.fn(coredata(long.short.strategy), coredata(prices), stop.loss,pstop = Stoploss)
models$stoploss = bt.run.share(data, clean.signal=T, trade.summary = TRUE)
#Our long short model with a .25% stop loss我想在SIT中创建自己的自定义停止函数,但不知道在SIT中应该如何使用,以及应该使用哪些参数来实现此目的。
我的习惯止损点子是
1) Initially fixed stop loss should be 10% of entry price
2) when price move more than 20% of entry price a new fixed stop loss be made at 10% of new entry price这不是拖尾止损,因为我不想让止损拖累价格,而是只移动一次。
发布于 2016-06-27 04:21:52
你已经看过这个例子了吗?(代码在页面底部的github代码库中)
R: Backtest Forex Strategies Instantly
他使用起始价10%的固定TP和当前价格2%的移动SL。它可能会给你一个提示,告诉你如何做你想做的事情。
编辑:比看别人的实现更好,看看SIT自己的止损方法:https://systematicinvestor.wordpress.com/2013/07/30/stop-loss/
https://stackoverflow.com/questions/37940191
复制相似问题