[R-SIG-Finance] Cant get this Quantstrat going,
Brian G. Peterson
brian at braverock.com
Fri May 4 20:57:30 CEST 2012
The 'name' of a indicator, signal, or rule is the name of a function,
and will be found via match.fun.
Since there is no function called 'sigCCI', I can't imagine it would
work.
You probably want name='sigThreshold' and column='Close' or something
similar. From what I see, you probably don't need an indicator at
all... the price is the indicator.
Also, please don't cross-post. You posted ten minutes ago to the
blotter forum.
On Fri, 2012-05-04 at 11:33 -0700, gussinsky wrote:
> 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.
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock
More information about the R-SIG-Finance
mailing list