2
我使用系統投資者工具箱(SIT)在R中測試我的策略。目前,我正在使用此功能在回溯測試中將其用作fixed stop loss。如何在SIT R中編寫自定義止損功能?
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
這不是一個尾隨止損,因爲我不想止損落後的價格,但只能移動一次。