2017-07-18 4 views
0

私は新しいユーザーがquantstratをバックテストしようとしています。誰でも私にそれを解決するのを助けることができますか? try.xtsでapplyIndi​​cators(戦略= strategy.st、mktdata = OHLC(SPY)) エラー(価格、エラー= -quantstratの問題:引数 "price"が不足しています。既定値はありません

library(quantmod) 
initdate = "1999-01-01" 
from = "2003-01-01" 
to = "2015-06-30" 
remove(srs) 
symbols("spy") 
src = "yahoo" 
getSymbols("SPY", from = from, to = to, src = src, adjust = TRUE) 
plot(Cl(SPY)) 
getSymbols("GBP", from = from, to = to, src = src, adjust = TRUE) 
lines(SMA(Cl(SPY),n = 200, col = "red")) 
Sys.setenv(TZ = "UTC") 
library(quantstrat) 
currency("USD") 
library(quantmod) 
getSymbols("GDX", from = from, to = to, src = src, adjust = TRUE) 
stock("GDX", currency = "USD") 
stock("SPY", currency = "USD") 
tradesize <- 100000 
initeq <- 100000 
strategy.st <-"firststrat" 
portfolio.st <- "firststrat" 
account.st <- "firststrat" 
rm.strat(strategy.st) 
initPortf(portfolio.st, symbols = "SPY", initdate = initdate, currency = "USD") 
initAcct(account.st, portfolio = portfolio.st, initDate = initdate, currency = "USD",initEq = initeq) 
initOrders(portfolio.st, initDate = initdate) 
strategy(strategy.st, store = TRUE) 
spy_sma <- SMA(x=Cl(SPY), n = 200) 
spy_rsi <- RSI(price=Cl(SPY), n=3) 
plot(Cl(SPY)) 
lines(SMA(Cl(SPY), n=200, col = "red")) 
"trend" 
plot(Cl(SPY)) 
plot(RSI(Cl(SPY), n = 2)) 
"reversion" 
add.indicator(strategy = strategy.st, 
       name = "SMA", 
       arguments = list(x=quote(Cl(mktdata)), n = 200), 
       label = "SMA200") 
add.indicator(strategy = strategy.st, 
       name = "SMA", 
       arguments = list(x=quote(Cl(mktdata)), n = 50), 
       label = "SMA50") 
add.indicator(strategy = strategy.st, 
       name = "RSI", 
       arguments = list(x=quote(Cl(maktdata)), n = 3), 
       label = "RSI_3") 
RSI_avg <- function(price, n1, n2) { 
    rsi_1 <- RSI(price = price, n = 1) 
    rsi_2 <- RSI(price = price, n = 2) 
    RSI_avg <- (rsi_1/rsi_2)/2 
    colnames(RSI_avg) <- "RSI_avg" 
    return (RSI_avg) 
} 
add.indicator(strategy.st, name = "RSI_avg", arguments = list(price = quote(Cl(mktdata)), n1 = 3, n2 = 4), label = "RSI_3_4") 
DVO <-function(HLC, navg = 2, percentlookback = 126){ 
    ratio <- Cl(HLC/(Hi(HLC) + Lo(HLC))/2) 
    avgratio <- SMA(ratio, n = navg) 
    out <- runPercentRank(avgratio, n = percentlookback, exact.multiplier = 1)*100 
    colnames(out) <- "DVO" 
    return(out) 
} 
add.indicator(strategy.st, name = "DVO", arguments = list (HLC=quote(HLC(mktdata)),navg = 2, percentlookback = 126), label = "DVO_2_126") 
test <- applyIndicators(strategy = strategy.st, mktdata = OHLC(SPY)) 

は私のコンソール

テスト<に次のメッセージが表示されます.matrix):デフォルト

答えて

2

RSIがパラメータprice、ないxをとらないと、 "価格" 引数が、不足しています。また、比率をどのように構築するかは、DVOに注意してください。 mktdataの場合は、RSI_3に入力ミスがあります。なぜこのコードで "GBP"を要求しているのか、またsymbols("spy")もなぜ呼び出されたのかは明らかではありませんが、あなたの問題の一部ではありません。

これらの変更は、あなたのコードの作業を行う必要があります

library(quantmod) 
initdate = "1999-01-01" 
from = "2003-01-01" 
to = "2015-06-30" 
#remove(srs) 
#symbols("spy") 
src = "yahoo" 
getSymbols("SPY", from = from, to = to, src = src, adjust = TRUE) 
plot(Cl(SPY)) 
getSymbols("GBP", from = from, to = to, src = src, adjust = TRUE) 
lines(SMA(Cl(SPY),n = 200, col = "red")) 
Sys.setenv(TZ = "UTC") 
library(quantstrat) 
currency("USD") 
library(quantmod) 
getSymbols("GDX", from = from, to = to, src = src, adjust = TRUE) 
stock("GDX", currency = "USD") 
stock("SPY", currency = "USD") 
tradesize <- 100000 
initeq <- 100000 
strategy.st <-"firststrat" 
portfolio.st <- "firststrat" 
account.st <- "firststrat" 
rm.strat(strategy.st) 
initPortf(portfolio.st, symbols = "SPY", initdate = initdate, currency = "USD") 
initAcct(account.st, portfolio = portfolio.st, initDate = initdate, currency = "USD",initEq = initeq) 
initOrders(portfolio.st, initDate = initdate) 
strategy(strategy.st, store = TRUE) 
spy_sma <- SMA(x=Cl(SPY), n = 200) 
spy_rsi <- RSI(price=Cl(SPY), n=3) 
plot(Cl(SPY)) 
lines(SMA(Cl(SPY), n=200, col = "red")) 
"trend" 
plot(Cl(SPY)) 
plot(RSI(Cl(SPY), n = 2)) 
"reversion" 
add.indicator(strategy = strategy.st, 
       name = "SMA", 
       arguments = list(x=quote(Cl(mktdata)), n = 200), 
       label = "SMA200") 
add.indicator(strategy = strategy.st, 
       name = "SMA", 
       arguments = list(x=quote(Cl(mktdata)), n = 50), 
       label = "SMA50") 
add.indicator(strategy = strategy.st, 
       name = "RSI", 
       arguments = list(price=quote(Cl(mktdata)), n = 3), 
       label = "RSI_3") 
RSI_avg <- function(price, n1, n2) { 
    rsi_1 <- RSI(price = price, n = 1) 
    rsi_2 <- RSI(price = price, n = 2) 
    RSI_avg <- (rsi_1/rsi_2)/2 
    colnames(RSI_avg) <- "RSI_avg" 
    return (RSI_avg) 
} 
add.indicator(strategy.st, name = "RSI_avg", arguments = list(price = quote(Cl(mktdata)), n1 = 3, n2 = 4), label = "RSI_3_4") 
DVO <-function(HLC, navg = 2, percentlookback = 126){ 
    ratio <- Cl(HLC)/(Hi(HLC) + Lo(HLC))/2 
    avgratio <- SMA(ratio, n = navg) 
    out <- runPercentRank(avgratio, n = percentlookback, exact.multiplier = 1)*100 
    colnames(out) <- "DVO" 
    return(out) 
} 
add.indicator(strategy.st, name = "DVO", arguments = list (HLC=quote(HLC(mktdata)),navg = 2, percentlookback = 126), label = "DVO_2_126") 
test <- applyIndicators(strategy = strategy.st, mktdata = OHLC(SPY)) 
関連する問題