2016-06-21 2 views
2

R에서 전략을 백 테스팅하기 위해 SIT (Systematic Investor Toolbox)를 사용하고 있습니다. 현재이 기능을 사용하여 역 테스팅시 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 

입니다.

답변

1

이 예제를 이미 보았습니까? 그 시작 가격에서 10 %로 고정 TP를 사용하고, 현재 가격 2 %로 이동 SL

R: Backtest Forex Strategies Instantly

(코드 페이지 하단의 GitHub의의 REPO이다). 그것은 당신이 찾고있는 것을하는 방법에 대한 힌트를 줄 것입니다.

EDIT : 다른 사람의 구현을 조사하는 것보다 손실 방지를위한 SIT의 자체 접근법을 살펴보십시오. https://systematicinvestor.wordpress.com/2013/07/30/stop-loss/

관련 문제