[R-SIG-Finance] Cant get this Quantstrat going,
gussinsky
sduve at hotmail.com
Fri May 4 20:33:26 CEST 2012
Hello All,
#simple Long only Strategie basierend auf CCI Threshhold Entry und Exit
###
###
###
suppressWarnings(rm("order_book.RSI", pos=.strategy))
suppressWarnings(rm("account.RSI", "portfolio.RSI", pos=.blotter))
suppressWarnings(rm("account.st", "portfolio.st", "stock.str", "initDate",
"initEq", 'start_t', 'end_t'))
require(quantstrat)
#Define Instrument
x = "HO"
symbol = getSymbols(x, src='tblox')
names(HO) = c("Open", "High", "Low", "Close", "Volume", "OpenInterest",
"Month", "Else")
#Define Start Date
initDate = '2004-01-01'
#Define equity
initEq = 100000
#Strategy
stratCCI = strategy("CCI")
#Portfolio
port.st = 'CCI'
initPortf(port.st, symbols=symbol, initDate=initDate)
#Account
initAcct(port.st, portfolios=port.st, initDate=initDate)
#Orders
initOrders(portfolio=port.st, initDate=initDate)
#Indicator
stratCCI = add.indicator(strategy = stratCCI, name = "CCI", arguments =
list(price = quote(getPrice(mktdata))), label="CCI")
#s
# CCI > -100, relation gt= greater than,
stratCCI = add.signal(strategy=stratCCI, name="sigCCI", arguments =
list(threshold=-100, column="CCI", relationship="gt", cross=TRUE),
label="CCI.gt.-100")
#CCI < 100, relation lt= lower than,
stratCCI = add.signal(strategy=stratCCI, name="sigCCI", arguments =
list(threshold=100, solumn="CCI", relationship="lt", cross=TRUE),
label="CCI.lt.100")
#RTrading Rules
stratCCI = add.rule(strategy=stratCCI, name='ruleSignal', arguments =
list(sigcol="CCI.gt.-100", sigval=TRUE, orderqty=1000, ordertype='market',
orderside='long', pricemethod='market', replace=FALSE), type='enter',
path.dep=TRUE)
stratCCI = add.rule(strategy=stratCCI, name='ruleSignal', arguments =
list(sigcol="CCI.lt.100", sigval=TRUE, orderqty=-1000, ordertype='market',
orderside='short', pricemethod='market', replace=FALSE), type='exit',
path.dep=TRUE)
currency("USD")
start_t = Sys.time()
out = try(applyStrategy(strategy=stratCCI, portfolios=port.st,
parameters=list(n=2)))
end_t = Sys.time()
print(end_t-start_t)
chart.Posn(Portfolio=port.st, Symbol=symbol)
this is the error i get:
out = try(applyStrategy(strategy=stratCCI, portfolios=port.st,
parameters=list(n=2)))
Error in inherits(x, "xts") : argument "HLC" is missing, with no default
In addition: Warning message:
In applyIndicators(strategy = strategy, mktdata = mktdata, parameters =
parameters, :
some arguments stored for CCI do not match
What could the problem be here?
Best
Sven
--
View this message in context: http://r.789695.n4.nabble.com/Cant-get-this-Quantstrat-going-tp4609350.html
Sent from the Rmetrics mailing list archive at Nabble.com.
More information about the R-SIG-Finance
mailing list