[R-SIG-Finance] !SPAM: Re: quantstrat: order sizing question
Brian G. Peterson
brian at braverock.com
Tue Jun 29 03:18:56 CEST 2010
On 06/28/2010 08:03 PM, km wrote:
> I'm using the package quantstrat and trying (unsuccessfully) to use my own
> function for order sizing. For example using
> the demo example (faber.R), the first rule is:
>
> s<- add.rule(s, name='ruleSignal', arguments = list(data=quote(mktdata),
> sigcol="Cl.gt.SMA", sigval=TRUE, orderqty=1000, ordertype='market',
> orderside='long', pricemethod='market'), type='enter', path.dep=TRUE)
>
>
> Now I try and incorporate my own order sizing function:
>
> myOS<- function(orderqty,...){
>
> orderqty<- orderqty[1]*orderqty[2]
> return(orderqty)
> }
>
> I modify the rule above:
>
> s<- add.rule(s, name='ruleSignal', arguments = list(data=quote(mktdata),
> sigcol="Cl.gt.SMA", sigval=TRUE, orderqty=c(1000,2), ordertype='market',
> orderside='long', pricemethod='market'), osFUN="myOS", type='enter',
> path.dep=TRUE)
>
> When, I run the code I get a bunch of warnings and no trades are generated.
> I suspect that I'm not passing the arguments the right way from the
> "add.rule" function to the "myOs" function. I've tried lots of different
> things with no success.
> Any help would be much appreciated.
You didn't tell us what warnings you received...
osNoOp (the default) has only the arguments in your example. You may want to
look at osMaxPos for a more involved example function.
Currently, 'ruleSignal' (which you could also replace if you wanted to ...)
uses 'match.fun' to match your oder sizing function into 'osFUN', and then passes:
osFUN(strategy=strategy, mktdata=mktdata, timestamp=timestamp,
orderqty=orderqty, ordertype=ordertype, orderside=orderside,
portfolio=portfolio, symbol=symbol)
note these are all named arguments.
We should probably update that to also pass dots, but that's all the variables
that ruleSignal knows about *for sure* at that point in time, and I suspect it
should be sufficient for most order sizing functions without adding dots. I'll
add dots to SVN now.
Notice also that orderqty, per the docs, is "numeric quantity of the desired
order, or 'all'" and ruleSignal has a number of different numeric comparisons
for trade direction. I suspect that may be the source of (some of) your warnings.
So, I hope this helps point you in the right direction, but you may also need
to give us an actually reproducible example, and tell us exactly the error or
warning messages you're seeing.
Regards,
- Brian
--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock
More information about the R-SIG-Finance
mailing list