[R-SIG-Finance] quantstrat

Brian G. Peterson brian at braverock.com
Tue Jan 11 13:40:05 CET 2011


On 01/10/2011 11:19 PM, Stephen Choularton wrote:
> OK, I have found this in the manual:

Thanks for reading the manual.

> 'For the purposes of backtesting, and compatibility with the trade
> accounting in blotter, this function will not allow a transaction to
> cross your current position through zero. The accounting rules for
> realizing gains in such cases are more complicated than we wish to
> support. Also, many brokers will break, revise, or split such
> transactions for the same reason. If you wish to do a "stop and reverse"
> system, first stop (flatten), and then reverse (initiate a new position).'
>
> So now I know why I couldn't model short positions.  is this correct?
> Being able to go short is a pretty common sort of action.

Yes, being able to go short is a pretty 'common sort of action'.  I do 
it every day across multiple instrument classes, currencies, and 
millions of dollars of net portfolio position (after converting back to 
USD).

Note that the bbands demo *as written* initiates short positions without 
any problem.  See attached pdf. That would likely suggest to anyone 
writing code that modified the working demo that the problem was likely 
in their code, not the package...

Do you not understand the documentation?

First flatten your position (get to zero) then initiate a short 
position.  stop. then reverse.

So, in the bbands demo, you would set up:

- a long entry entry at the lower band
- a long exit at the mid or upper band
- a short entry at the upper band
- a short exit at the mid or the lower band

The demo does that with three rules and using the orderside=NULL 
convenience, but I could easily have left only the mid-cross rule as 
orderside NULL and the other appropriate rules as 'long' and 'short'.

In a non-toy strategy, you'd probably also want to do something like 
addPosLimit to set how many signals you'll respond to.  Try one long and 
one short to start.

> I had a look at the bbands demo and it appeared to go long and short and
> specified NULL as the ordertype rather than long or short.  That got rid
> of my warning that I was going short, but it didn't produce any short
> trades.
>
> Any help most welcome.

See above.

   - Brian

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bbands.pdf
Type: application/pdf
Size: 213670 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110111/82621f61/attachment.pdf>


More information about the R-SIG-Finance mailing list