사용자 정의 표시기 함수 내에서 현재 기호 문자열 (예 : "GOOG")에 액세스하고 싶습니다. 여기에 내가 할 수있는 가장 기본적인 예제가 있습니다.사용자 정의 함수 내에서 현재 기호를 얻는 방법 quantstrat에서 applyIndicators 또는 applyStrategy를 적용하는 방법
require(quantstrat)
Sys.setenv(TZ="UTC")
symbols <- c("GOOG", "AAPL")
getSymbols(symbols, src="yahoo")
strategy.st <- "test"
strategy(strategy.st, store=TRUE)
test_fun <- function(x){
print(symbol) ##### i want to access the current symbol eg "GOOG"
return(x)
}
add.indicator(strategy = strategy.st,
name = "test_fun",
arguments = list(x = quote(Cl(mktdata))),
label = "test_ind")
mktdata <- applyIndicators(strategy = strategy.st, GOOG)
Error in print(symbol) : object 'symbol' not found
Called from: print(symbol)
감사합니다 (더 쉬운 방법은 단순히 열 이름은 기호 레이블을 포함합니다.,
testfun
내부의x
개체에 존재할 수있는의 OHLC 열 이름에서 심볼 이름을 추출 할 수도있다)! 네, 사실 applyStrategy() 함수를 실행하고 있습니다. 사용자 정의 인디케이터는 심볼을 사용하여 데이터 프레임에서 조회를 수행하므로 심볼 코드가 필요합니다. –사과 죄송합니다 답변을 드렸습니다. 다시 한 번 감사드립니다. –