[R-SIG-Finance] Quantstrat problem

OpenTrades jan at opentrades.nl
Sat Mar 9 16:08:00 CET 2013


Hi Robert,

When running your code, I get a different error, getSymbols() .... 
didn't look further into it :-)

Please be aware that the sheets of Guy Yollin, although excellent 
tutorials, are quite dated, as the quantstrat package has been and still 
is under heavy development.

So I would suggest that you takea look at some of the demos in the demo 
directory. eg:
> > require(quantstrat)
> Loading required package: quantstrat
> Loading required package: foreach
> foreach: simple, scalable parallel programming from Revolution Analytics
> Use Revolution R for scalability, fault tolerance and more.
> http://www.revolutionanalytics.com
> > demo(package='quantstrat')
> > demo(package='quantstrat', topic='luxor.1')

etc etc

Source code for the demos comes with the quantstrat package in 
blotter/pkg/quantstrat/demo directory.

HTH,

Jan Humme.



On 03/08/2013 08:21 PM, Robert Schien wrote:
> Hello,
>
> I am trying to get familiar with the quantstrat package. Therefore
> I am following the documentation file quantstrat_I.pdf available at
> r-programming.org.
>
> I am trying the following code:
>
>
> library(blotter)
> library(quantstrat)
> currency("USD")
> stock("AMZN",currency="USD",multiplier=1)
> getSymbols('AMZN', from='2005-01-01', to='2012-08-31', adjust=T)
> qs.strategy <- "qsAMZN"
> initPortf(qs.strategy,'AMZN', initDate='2004-12-31')
> initAcct(qs.strategy,portfolios=qs.strategy, initDate='2004-12-31', initEq=1e6)
> initOrders(portfolio=qs.strategy,initDate='2004-12-31')
> strat<- strategy(qs.strategy)
> strat <- add.indicator(strategy = strat, name = "SMA",
> arguments = list(x = quote(Cl(mktdata)), n=7), label="SMA7")
> strat <- add.indicator(strategy = strat, name = "SMA",
> arguments = list(x = quote(Cl(mktdata)), n=30), label="SMA30")
> strat <- add.signal(strat,name="sigCrossover",
> arguments = list(columns=c("SMA7","SMA30"),relationship="gt"),
> label="SMA7.gt.SMA30")
> strat <- add.signal(strat,name="sigCrossover",
> arguments = list(columns=c("Close","SMA7"),relationship="gt"),
> label="cl.gt.SMA7")
> strat <- add.signal(strat,name="sigCrossover",
> arguments = list(columns=c("Close","SMA7"),relationship="lt"),
> label="Cl.lt.SMA7")
> strat <- add.rule(strat, name='sigFormula',
> arguments = list(formula=" (SMA7 > SMA30) & (AMZN.Close > SMA30) ", orderqty=1000,
> ordertype='market', orderside='long', pricemethod='market'),
> type='enter', path.dep=TRUE)
> out <- applyStrategy(strategy=strat , portfolios=qs.strategy)
> updatePortf(Portfolio=qs.strategy,Dates=paste('::',as.Date(Sys.time()),sep=''))
> updateAcct(name=qs.strategy,Dates=index(AMZN))
> dummy <- sapply(X=index(AMZN),FUN=updateEndEq,Account=qs.strategy)
>
> The last command produces an error:
>
> Error in if (!all(i <= 0)) stop("only zeros may be mixed with negative subscripts") :
>    missing value where TRUE/FALSE needed
>
>
> Did I overlook something?
>
> Thanks in advance.
>
> Robert
>
> _______________________________________________
> 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.
>


-- 
Jan Humme - OpenTrades

WWW:     http://www.opentrades.nl
Email:   jan at opentrades.nl
Twitter: @opentrades



More information about the R-SIG-Finance mailing list