私のカスタムインジケータ関数内の現在のシンボル文字列、たとえば「GOOG」にアクセスしたいとします。ここに私が作ることができる最も基本的な例があります。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)
ありがとうございました!はい、実際には私はapplyStrategy()関数を実行しています。カスタムインジケータは、シンボルを使用してデータフレームのルックアップを行います。そのため、シンボルコードが必要でした。 –
謝罪私はちょうど答えたとマークしました、ありがとう –