[R-SIG-Finance] GetOrders with Quantstrat
Ryan Crawford
suchislife27 at gmail.com
Tue Apr 5 11:26:13 CEST 2016
Hello
I have been trying to view "open" orders from the orderbook in Quantstrat
and keep running into the same error.
It seems a reasonably simple process however the error I get is:
oB <- getOrders(portfolio.st, symbols, status="open")
Error in orderbook[[portfolio]][[symbol]] :
recursive indexing failed at level 2
I've searched extensively and I can't seem to pinpoint the issue.
Below is a reproducible example that generates the error.
Thank you in advance for any help.
require(quantstrat)
require(IKTrading)
# Set the currency and the timezone
currency('USD')
Sys.setenv(TZ = "UTC")
# Define symbols of interest
symbols <- c("AMP.AX", "BHP.AX", "ANZ.AX",
"CBA.AX", "BXB.AX", "CSL.AX", "IAG.AX",
"MQG.AX", "NAB.AX", "ORG.AX", "QBE.AX",
"RIO.AX", "SCG.AX", "SUN.AX", "TLS.AX",
"WBC.AX", "WES.AX", "WOW.AX", "WPL.AX",
"TCL.AX", "WFD.AX", "AMC.AX")
#Get Symbols
getSymbols(Symbols=symbols, from="2010-01-01", to="2016-04-04")
# Define the instrument type
stock(symbols, currency = "USD", multiplier = 1)
#Boilerplate
from = "2010-01-01"
to = "2016-04-04"
#trade sizing and initial equity settings
tradeSize <- 2500
initEq <- 100000
strategy.st <- portfolio.st <- account.st <- "GetOrderBook"
rm.strat(portfolio.st)
rm.strat(strategy.st)
initAcct(account.st, portfolio.st, currency='USD', initEq=initEq)
initPortf(portfolio.st, symbols, currency='USD')
initOrders(portfolio.st)
strategy(strategy.st, store=TRUE)
#Add Indicators
add.indicator(strategy.st, name="SMA",
arguments=list(x=quote(Cl(mktdata)), n=20),
label="sma")
#Add Entry and Exit Signals
add.signal(strategy.st, name="sigComparison",
arguments=list(columns=c("Close", "SMA.20.sma"),
relationship="gt"),
label="longentry")
#enter signal rule
add.rule(strategy.st, name="ruleSignal",
arguments=list(sigcol="longentry",
sigval=TRUE,
ordertype="limit",
orderside="long",
replace=TRUE,
prefer="Close",
tmult = TRUE,
threshold = 0.05,
time.in.force=172800,
orderqty=tradeSize,
osFUN=osMaxDollar,
tradeSize=tradeSize,
maxSize=tradeSize),
type="enter",
path.dep=TRUE,
label="enterlong")
#stop loss.
add.rule(strategy.st, name="ruleSignal",
arguments=list(sigcol="longentry",
sigval=TRUE,
ordertype="stoptrailing",
orderside="long",
replace=FALSE,
orderqty="all",
threshold=0.05,
tmult=TRUE,
orderset="ocolong"),
type="chain",
parent="enterlong",
label="stopLossLong",
path.dep=TRUE,
enable=TRUE)
#apply strategy
out2 <- applyStrategy(strategy=strategy.st,portfolios=portfolio.st )
#get open orders
oB <- getOrders(portfolio.st, symbols, status="open")
[[alternative HTML version deleted]]
More information about the R-SIG-Finance
mailing list