[R-SIG-Finance] quantstrat - problems with ordersize function

Brian G. Peterson brian at braverock.com
Wed Apr 4 17:33:07 CEST 2012


On Wed, 2012-04-04 at 08:16 -0700, Andreas Mikkelsen wrote:
> Hi everyone, 
> 
> I am currently writing my master thesis in finance . The scope of the thesis
> is to backtest on historical data whether the pairs trading strategy is
> profitable or not. 
> 
> I have a couple of questions regarding the pairs trading demo script in the
> quantstrat package.  I managed to run it without any mishap, but as far as I
> can see, there are at no time a long / short leg in the transactions.  I.e.
> [1] "2009-03-03 SPY 1e+06 @ 67.1509470105226"
> [1] "2009-03-09 SPY 1e+06 @ 65.2725988423961"
> [1] "2009-03-03 DIA 1e+06 @ 63.717805901226"
> [1] "2009-03-09 DIA 1e+06 @ 62.0397741136174"
> 
> >From what I can understand it goes long at the same time on both stocks?
> Which would not equal a pairs trading strategy. In the summary page of
> blotter I could not find a single date with entries on both the long and
> short.  Has any one else experienced this? 

Some recent changes in other parts of quantstrat (within the last week)
broke the pairs_trading example in quantstrat.

I haven't yet found where, specifically, the prolem was created, since
other code seems to have been improved by the same changes.  Please feel
free to either 1> roll back to svn r980, which didn't display this
problem in the pair trade example (but has other problems with specific
order types that may or may not impact what you are doing) or 2> contact
me off-list to help work through it and see if we can find precisely
where the error lies.  I currently suspect a missing as.numeric()
somewhere in the demo script, though I'm by no means certain of that.

I typically recommend trading a pairs strategy as a spread and using
entry and exit signals on a single spread synthetic instrument.  Legging
them in quantstrat seems like an awful lot of unnecessary trouble, since
when actually trading such a strategy, you would almost certainly use a
commercial spreader anyway for execution.

> Further on I have tried to adjust the script from the package to our needs
> with a fellow student and our prof. What we can’t seem to figure out is how
> to adjust the orderqty with osFUN. 
> What we are trying to do is to make every order a fixed amount with equal
> dollar amount on either leg whenever the trade signal is activated. 
> Attached is our efforts so far. 
> http://r.789695.n4.nabble.com/file/n4532216/Quantstrat_PairTrade11.R
> Quantstrat_PairTrade11.R 

Guy Yollin's slides here:
http://www.r-programming.org/papers

have a relatively large section in the second quatstrat presentation on
position sizing.  Hopefully those will help you until I have more time
to look at your code.

Regards,

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



More information about the R-SIG-Finance mailing list