[R] quantstrat questions
R. Michael Weylandt
michael.weylandt at gmail.com
Tue Jul 24 22:22:49 CEST 2012
Quantstrat is under active development so you should probably ask on
the R-SIG-Finance list where the developers hang out.
Michael
On Tue, Jul 24, 2012 at 3:17 PM, Bos, Roger <roger.bos at rothschild.com> wrote:
> Quantstrat useRs,
>
> I have a number of questions about how to use quantstrat that I have accumulated since I have begun playing with it. First, can the orderqty be dynamic? All of the examples I have seen are based on placing an order for 100 shares when a rule is triggered. Is it possible to set it up to buy the maximum number of shares given the starting or current equity? Similar to that question, I think most examples buy 100 shares each time a buy is triggered? Is it possible to make the rules only buy at the first buy trigger? So the fund is either long 100% equity or in cash for a fixed starting equity.
>
> Another idea I would like to try to implement is a slow trading strategy where you have to keep a position for at least x days after a buy. For example some small cap or international funds have a penalty for trading in and out too quickly. It would be nice to test how much such a restriction hurts you?
>
> My final question is how to create a rule that uses more than one signal. Here I have an code sample below. In the sample I add three moving averages, ma50, ma160, and ma200:
>
>
> #Adding indicators to a strategy
> stratName <- add.indicator(strategy = stratName, name = "SMA", arguments =
> list(x=quote(Cl(mktdata)), n=50),label= "ma50" )
> stratName <- add.indicator(strategy = stratName, name = "SMA", arguments =
> list(x=quote(Cl(mktdata)), n=160),label= "ma160")
> stratName <- add.indicator(strategy = stratName, name = "SMA", arguments =
> list(x=quote(Cl(mktdata)), n=200),label= "ma200")
>
> #Adding signals to a strategy
> stratName <- add.signal(strategy = stratName,name="sigCrossover",arguments =
> list(columns=c("ma50","ma160"), relationship="gte"),label="ma50.gt.ma160")
> stratName <- add.signal(strategy = stratName,name="sigCrossover",arguments =
> list(column=c("ma50","ma160"),relationship="lt"),label="ma50.lt.ma160")
>
> stratName <- add.signal(strategy = stratName,name="sigCrossover",arguments =
> list(columns=c("ma50","ma200"), relationship="gte"),label="ma50.gt.ma200")
> stratName <- add.signal(strategy = stratName,name="sigCrossover",arguments =
> list(column=c("ma50","ma200"),relationship="lt"),label="ma50.lt.ma200")
>
>
> How would I modify the rules below to enter when ma50 greater than both ma160 and ma200 and exit when ma50 is below both ma160 and ma200?
>
> #Add rules to a strategy
> stratName <- add.rule(strategy = stratName,name='ruleSignal', arguments =
> list(sigcol="maFast.gt.maSlow",sigval=TRUE, orderqty=100, ordertype='market', orderside='long'),type='enter')
> stratName <- add.rule(strategy = stratName,name='ruleSignal', arguments =
> list(sigcol="maFast.lt.maSlow",sigval=TRUE, orderqty='all', ordertype='market', orderside='long'),type='exit')
>
> Thanks to everyone who helped develop quantstrat and blotter,
>
> Roger
>
>
> ***************************************************************
>
> This message is for the named person's use only. It may\...{{dropped:15}}
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list