Skipped trades when using R3 Strategy(Aggressive version) with Pyramiding PosSizer
Author: cravens
Creation Date: 2/15/2012 8:26 PM
profile picture

cravens

#1

I am getting the error '141 trades were not included in the backtest results due to insufficient simulated capital or dropped by the selected PosSizer. PosSizer is set to Pyramiding. My backtest account size is set to 100k and the the position size can be as little as $1 and I still get the error. I thought the R3 strategy was supposed to pyramid the position size (1,2,4,8). Anyone have any idea what is wrong?

All of the other position sizing routines function.

Thanks
Rob
profile picture

Eugene

#2
Originally, "R3" was designed to purchase an equal size each time it creates a new position e.g. 10%, another 10% (total: 20%), etc. If you like to use Pyramiding with a mutli-position strategy, first thing is to specify the correct initial signal name. This is a prerequisite to using the Pyramiding PosSizer, enabling it to pick up the primary entry signal as the pyramid base, and treat all others accordingly.

In the case of "R3 Strategy", you need to type 1 in that input field because of this:
CODE:
Please log in to see this code.

The field should not say "initial" (default) or be left empty. You can find that on the PosSizer's online help page.
profile picture

cravens

#3

Thank you.

Is there a way to make it 2,3,5 instead of 1,2,4 ?

Rob

profile picture

Eugene

#4
1,2,4 is "Reverse pyramid".

"Reverse Incremental pyramid" allows some adjustment by introducing the pyramid increment as a fixed percent value. Maybe not exactly but try playing with it. It's illustrated on Figure 5 here:

Pyramiding > "The shape of the pyramid".
profile picture

cravens

#5
Maybe I am approaching this wrong. Lets say I have $2000 total for the full position. I want to scale in at 2, 3, 5 and the asset price is $100. First position would be 4 shares, then 6 shares then 10 shares.
Is there a way to force this share size on each purchase in the code (not necessarily with PosSizer)? The $2000 may change from the outer control where the strategy is set up.
Any suggestions?

Rob
profile picture

Eugene

#6
SetShareSize()
profile picture

Eugene

#7
Keep in mind that without the Pyramiding PosSizer, you won't be able to correctly test a scale-in scenario in a MSB portfolio simulation. Without this PosSizer, Wealth-Lab's real-world simulation rules can skip the initial entry signal due to insufficient funds, but your system will be entering pyramided trades like nothing happened. This applies to SetShareSize as well (which by its nature is not appropriate for testing in portfolio simulation mode): if the initial trade has not been taken, the additional entry signals will not be skipped if you're not using the PosSizer.
profile picture

jamesmhaley

#8
I'm having a problem with the pyramiding PosSizer. I've successfully installed the MS123 PosSizer library. I've set the PosSizer to "Pyramiding" and I've configured it so that the initial entry signal is "buy1" with a pyramid shape of "Upright". The max pyramid entries is set to 3. So that I wouldn't have to send my complete program, I've created a simple buy 3 consecutive bars/sell all positions for the last 30 bars (please see copy below). The results are similar to what's happening in my original program. I was expecting to get 3 buys with the upright pyramid for each of the last 30 bars. I do get some bars that have the expected 3 buys/sells and the proper buy pyramid. However, on most bars, I get between 1-3 buys. What is also confusing to me is that each time I execute the code, I get different results (using the same equity). I'm obviously missing something. I would appreciate your help.

Thanks, Jim
****************************

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

Eugene

#9
The problem here is with coding, not with the PosSizer: it's a mistake to use LastPosition in a multi-position strategy.

Check out the WealthScript Programming Guide, Programming Trading Strategies > Multi-Position Strategies, especially the "MP Strategy Template" code snippet.

QUOTE:
What is also confusing to me is that each time I execute the code, I get different results (using the same equity).

Wiki FAQ: Every time I run a Strategy I get a different result. What am I missing?
profile picture

jamesmhaley

#10
Eugene,
I changed my code to reflect the example in the Programming Guide discussing how to use the same exit trigger for all active positions in a MP strategy. I'm using the same pyramiding configuration described previously. In trying to pyramid, my example code is trying to do three consecutive buys followed by sell all open positions. I've attached the resultant trades under my code to show the results I'm getting. I'm executing the code against a single position (AAPL). Why am I not getting three buy/sells for the last ten bars? I would appreciate your help.

Thank you,
Jim

CODE:
Please log in to see this code.


QUOTE:
Position Symbol Quantity Entry Date Entry Price Exit Date Exit Price Profit % Profit $ Bars Held Profit per Bar Entry Name Exit Name MAE % MFE %
Long AAPL 99 2/14/2012 509.46 2/15/2012 497.67 -2.35 ($1,183.11) 2 ($591.55) buy1 Sell All -2.48 3.29
Long AAPL 49 2/14/2012 509.46 2/15/2012 497.67 -2.38 ($593.61) 2 ($296.80) buy3 Sell All -2.50 3.27
Long AAPL 24 2/14/2012 509.46 2/15/2012 497.67 -2.44 ($298.86) 2 ($149.43) buy2 Sell All -2.53 3.24
Long AAPL 100 2/16/2012 502.21 2/17/2012 502.12 -0.05 ($24.90) 2 ($12.45) buy1 Sell All -0.40 1.09
Long AAPL 99 2/21/2012 514.85 2/22/2012 513.04 -0.38 ($195.09) 2 ($97.55) buy1 Sell All -1.14 0.11
Long AAPL 49 2/21/2012 514.85 2/22/2012 513.04 -0.41 ($104.59) 2 ($52.30) buy3 Sell All -1.15 0.09
Long AAPL 97 2/23/2012 516.39 2/24/2012 522.41 1.13 $568.04 2 $284.02 buy1 Sell All -0.02 1.24
Long AAPL 95 2/27/2012 525.76 2/28/2012 535.41 1.80 $900.85 2 $450.42 buy1 Sell All -0.02 1.82
profile picture

Eugene

#11
QUOTE:
Why am I not getting three buy/sells for the last ten bars?

I'm limited to guesswork since your initial position size is unknown, but considering AAPL's price and the quantity on the "buy1" signals, it looks like the PosSizer is successfully ruling out the add-on trades due to insufficient funds.
profile picture

jamesmhaley

#12
Eugene,
For testing purposes, I've got starting capital = $1,000,000. For the PosSizer settings, I've selected the "Fixed Dollar" radio button and I'm using $50,000. The "Initial entry signal" = "buy1", the "Max number of pyramid entries" = 3 and the "Pyramid shape" drop-down list = "Upright". For original testing purposes, I chose AAPL and I don't think the insufficient funds is an issue. Anyway, I changed my equity to "F". I'm getting similar results using Ford that I did with AAPL. For simple testing purposes, I'm executing on just the last 10 bars with three consecutive buys followed by a sell all position. To see how the pyramiding works, I was hoping to get around 30 buys/sells with an upright pyramid structure. I've attached my Ford results below. I executed the code twice and got different results. I understand that under certain scenarios, wealth-lab will give different results - I get that. But under my narrow testing over a 10 bar period using just one equity, I would expect the identical results. I'm obviously missing something? I would appreciate your help.

*********************
First Execution:
*********************
Position Symbol Quantity Entry Date Entry Price Exit Date Exit Price Profit % Profit $ Bars Held Profit per Bar Entry Name
Exit Name MAE % MFE %
Long F 4,006 2/15/2012 12.38 2/16/2012 12.74 2.88 $1,426.26 2 $713.13 buy1 Sell All -0.02 3.13
Long F 2,003 2/15/2012 12.38 2/16/2012 12.74 2.84 $705.18 2 $352.59 buy3 Sell All -0.03 3.12
Long F 1,001 2/15/2012 12.38 2/16/2012 12.74 2.78 $344.46 2 $172.23 buy2 Sell All -0.06 3.09
Long F 3,924 2/17/2012 12.75 2/21/2012 12.53 -1.76 ($879.18) 2 ($439.59) buy1 Sell All -2.29 0.06
Long F 3,990 2/22/2012 12.28 2/23/2012 12.40 0.94 $462.90 2 $231.45 buy1 Sell All -0.99 1.29
Long F 1,995 2/22/2012 12.28 2/23/2012 12.40 0.91 $223.50 2 $111.75 buy2 Sell All -1.01 1.27
Long F 997 2/22/2012 12.28 2/23/2012 12.40 0.85 $103.74 2 $51.87 buy3 Sell All -1.04 1.24
Long F 4,032 2/24/2012 12.23 2/27/2012 12.30 0.54 $266.34 2 $133.17 buy1 Sell All -1.98 1.05
Long F 2,016 2/24/2012 12.23 2/27/2012 12.30 0.51 $125.22 2 $62.61 buy3 Sell All -1.99 1.03
Long F 4,065 2/28/2012 12.25 2/29/2012 12.38 1.03 $512.55 2 $256.28 buy1 Sell All -0.02 2.43

*********************
Second Execution:
*********************

Position Symbol Quantity Entry Date Entry Price Exit Date Exit Price Profit % Profit $ Bars Held Profit per Bar Entry Name Exit Name MAE % MFE %
Long F 4,006 2/15/2012 12.38 2/16/2012 12.74 2.88 $1,426.26 2 $713.13 buy1 Sell All -0.02 3.13
Long F 2,003 2/15/2012 12.38 2/16/2012 12.74 2.84 $705.18 2 $352.59 buy3 Sell All -0.03 3.12
Long F 3,924 2/17/2012 12.75 2/21/2012 12.53 -1.76 ($879.18) 2 ($439.59) buy1 Sell All -2.29 0.06
Long F 1,962 2/17/2012 12.75 2/21/2012 12.53 -1.79 ($447.54) 2 ($223.77) buy2 Sell All -2.31 0.05
Long F 981 2/17/2012 12.75 2/21/2012 12.53 -1.85 ($231.72) 2 ($115.86) buy3 Sell All -2.34 0.01
Long F 3,990 2/22/2012 12.28 2/23/2012 12.40 0.94 $462.90 2 $231.45 buy1 Sell All -0.99 1.29
Long F 1,995 2/22/2012 12.28 2/23/2012 12.40 0.91 $223.50 2 $111.75 buy2 Sell All -1.01 1.27
Long F 997 2/22/2012 12.28 2/23/2012 12.40 0.85 $103.74 2 $51.87 buy3 Sell All -1.04 1.24
Long F 4,032 2/24/2012 12.23 2/27/2012 12.30 0.54 $266.34 2 $133.17 buy1 Sell All -1.98 1.05
Long F 2,016 2/24/2012 12.23 2/27/2012 12.30 0.51 $125.22 2 $62.61 buy3 Sell All -1.99 1.03
Long F 1,008 2/24/2012 12.23 2/27/2012 12.30 0.44 $54.66 2 $27.33 buy2 Sell All -2.03 1.00
Long F 4,065 2/28/2012 12.25 2/29/2012 12.38 1.03 $512.55 2 $256.28 buy1 Sell All -0.02 2.43

Thanks,
Jim
profile picture

Eugene

#13
QUOTE:
But under my narrow testing over a 10 bar period using just one equity, I would expect the identical results

Why so? Just because the data range is small?

It's not the number of bars that counts. As the FAQ I pointed you at stresses, assigning a Position.Priority, one way (WealthScript code) or another (Preferences > Use Worst Trades...), is the key to get repeatable backtests. Your example code is missing it.

As everything about this is a Priority thing, I'm addressing this issue first; now it's time to move on to your pyramiding question:
QUOTE:
I was hoping to get around 30 buys/sells with an upright pyramid structure.

Actually, you should be expecting 15 buys/sells with that script. To get 30 trades, 3 on each of the last 10 bars, a code like this is required:
CODE:
Please log in to see this code.

Notice how the script assigns the top priority (3.0) to the "pyramid base" and a lower value to the "addon trades". (To work correctly, "Use Worst Trades..." should be unchecked in Wealth-Lab's Preferences dialog, otherwise you risk having some entry signals skipped.)

As you can make certain of, failure to prioritize the pyramid base by leaving the priority decision to Wealth-Lab (i.e. random priority) can skip some initial/addon entry signals.

(Just for reference, this aspect had been previously touched in another forum thread: RSI scale out system in simulation mode.)
profile picture

jamesmhaley

#14
Thanks, Eugene!
I appreciate your code snippet. I have it working now.
Jim
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).