SplitPosition Misleading?
Author: llhk
Creation Date: 12/22/2011 8:11 PM
profile picture

llhk

#1
I have written a code that selling half of the position once the target X% reaches, and leave another half sell under trailing stop, but I found that the trades generated are correct in the testing of individual symbol but incorrect in a whole dataset. Under testing of a group of symbols, usually only the first half trade with X% profit is found in "Trades" records, but another half only occasionally appears in the records.

is my code logically incorrect? or SplitPosition itself has some problems?

Here is my code for the logic:

CODE:
Please log in to see this code.
profile picture

Eugene

#2
SplitPosition can be misleading in some rare cases in multi-symbol backtests: RSI scale out system in simulation mode.

However, I'd start with the order of exits used your code which is unrealistic: AtMarket order should precede AtStop orders, not the opposite. See Programming Trading Strategies > Peeking in the WealthScript Programming Guide for details.
profile picture

Cone

#3
The case isn't really so rare, and I thought we had documented it in the QuickRef.. for sure there's an open deficiency report on it, so we can add this to our on-line Open Issues list.

The problem occurs because: 1) Positions are created (and split) in raw profit mode, but, 2) WL's simulation engine sizes and picks positions post-facto when building the equity curve.

Imagine that you have a bar in which you created 6 Positions with 20% of equity sizing (and that you were "flat" before this bar). Already one of the trades cannot be picked. Later you split one of those Positions 2:1, which results in two 10% of Equity positions. Both, one, or none of those split positions could be picked by the simulator. If it's both or none, that's okay. But if only one of those Positions are picked and sized, that's the problem you're seeing.

In theory, you should be able to remediate this situation somewhat by assigning priority to the Position and ensure that you assign the same priority to the Split Position. I'd guess that this would help in many cases, but certainly not all because simulations are usually much more complex than my example for one bar.

In the end, Wealth-Lab needs to be able to "tag" positions that are split so that during the sizing process it either sizes and picks all of them or none. Until then, you have to be careful when using SplitPosition for high-exposure simulations.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).