本文介绍了R-Quantstrat-反向测试不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用了盖伊·尤林演讲中的以下代码.我得到的结果不正确.结果将发布在代码下方.
I used the following code from Guy Yollin's lecture. The result I got was not correct. The result is posted below the code.
library(blotter)
library(quantstrat)
currency("USD")
stock("SPY", currency = "USD", multiplier = 1)
initDate = "1997-12-31"
startDate = "1998-01-01"
endDate = "2014-06-30"
initEQ = 1e6
Sys.setenv(TZ = "UTC")
getSymbols('SPY', from = startDate, to = endDate, index.class = "POSIXct", adjust = T)
SPY = to.monthly(SPY, indexAt = "endof", drop.time = FALSE)
SPY$SMA10m <- SMA(Cl(SPY),10)
qs.strategy <- "qsFaber"
initPortf(qs.strategy, "SPY", initDate = initDate)
initAcct(qs.strategy, portfolios = qs.strategy, initDate = initDate, initEq = initEQ)
initOrders(portfolio = qs.strategy, initDate = initDate)
strategy(qs.strategy, store = TRUE)
strat <- getStrategy(qs.strategy)
add.indicator(
strategy = qs.strategy,
name = "SMA",
arguments = list(
x = quote(Cl(mktdata)),
n = 10),
label = "SMA10"
)
add.signal(
qs.strategy,
name = "sigCrossover",
arguments = list (
columns = c("Close", "SMA10"),
relationship = "gt"),
label = "Cl.gt.SMA"
)
add.signal (
qs.strategy,
name = "sigCrossover",
arguments = list(
columns = c("Close", "SMA10"),
relationship = "lt"),
label = "Cl.lt.SMA"
)
add.rule(
qs.strategy,
name = "ruleSignal",
arguments = list(
sicol = "Cl.gt.SMA",
sigval = TRUE,
orderqty = 900,
ordertype = "market",
orderside = "long"),
type = "enter"
)
add.rule(
qs.strategy,
name = "ruleSignal",
arguments = list(
sicol = "Cl.lt.SMA",
sigval = TRUE,
orderqty = "all",
ordertype = "market",
orderside = "long"),
type = "exit"
)
applyStrategy(strategy = qs.strategy, portfolios = qs.strategy)
getTxns(Portfolio = qs.strategy, "SPY")
Txn.Qty Txn.Price Txn.Fees Txn.Value Txn.Avg.Cost Net.Txn.Realized.PL 1997-12-31
Txn.Qty Txn.Price Txn.Fees Txn.Value Txn.Avg.Cost Net.Txn.Realized.PL 1997-12-31
0 0 0 0 0 0
我将不胜感激任何反馈或回复!预先感谢!
I would appreciate any feedbacks or replies! Thanks in advance!
推荐答案
检查像70.它应该读为sigcol而不是sicol.
Check like 70. it should read sigcol not sicol.
这篇关于R-Quantstrat-反向测试不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!