Quantcast

Cant get this Quantstrat going,

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Cant get this Quantstrat going,

Sven D
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cant get this Quantstrat going,

braverock
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.
>
> _______________________________________________
> [hidden email] 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

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cant get this Quantstrat going,

Sven D
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cant get this Quantstrat going,

Sven D
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cant get this Quantstrat going,

braverock
On Sat, 2012-05-05 at 03:37 -0700, gussinsky wrote:
> I also would like to point out, that the calculation of the CCI is
> wrong,all through the mktdata it is either -66.66 or 66.66. Having
> performed a manual calculation of the CCI with the underlying data
> from tblox, worked just fine.

Well then, your CCI function is broken.  

Fix that *first* and apply it to your market data before trying to
insert the indicator it into a strategy.

All that applyIndicators (as called by applyStrategy) does is call your
indicator function and pass it your market data.  You can and should
test your indicator function outside of quantstrat to make sur ethat you
can apply it to market data before trying to incorporate it  into a
strategy.

--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cant get this Quantstrat going,

Sven D
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Cant get this Quantstrat going,

braverock
On Sat, 2012-05-05 at 03:55 -0700, gussinsky wrote:
> Not sure I understand, CCI is a function in TTR, I have tested it on the
> mktdata and it works:
>
> x = CCI(HLC(mktdata))
>
> works fine.

CCI does put NA's at the beginning of the data series.  If that is a
problem for the rest of your logic, then you'll need to fix that.  As I
said already, all that applyIndicators does is call your indicator
function.  

This works:

require(quantstrat)
getSymbols('IBM')
CCI(HLC(IBM))
nrow(IBM) == nrow(CCI(HLC(IBM)))
#TRUE
strategy('test', store=TRUE)
add.indicator(strategy = 'test', name = "CCI", arguments = list(HLC =
quote(HLC(mktdata))), label="CCI")
applyIndicators('test',mktdata=IBM)
applyIndicators('test',mktdata=IBM)$CCI == CCI(HLC(IBM))
# TRUE for every row

I'm not going to debug your strategy for you.


--
Brian

_______________________________________________
[hidden email] 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.
Loading...