pyramiding in portfolio?
Author: wouterv
Creation Date: 10/23/2009 2:24 AM
profile picture

wouterv

#1
Hi,

I was trying to add pyramiding to my trading strategy (turtle-like) and I implemented a simple (perhaps naive) approach by adding positions when the current price is above about 1 atr of the entry price.

However I see in portfolio simulation these signals can be acted upon, while there is no open position after all (I guess due to the way portfolio simulation works, first registering all signals and then striking out those that can't be handled). Is there a way to get around this?

Thanks,
Wouter
profile picture

Eugene

#2
These signals shouldn't be acted upon, there's something with the code. Here's a similar approach from our Knowledge Base: pyramiding when the current price goes up 10% from the entry price. Try using it as an example:

WealthScript Techniques | Pyramiding (Adding to position)
profile picture

wouterv

#3
Hi Eugene,

Thanks for the pointer. Just to see the example in working I c&p it and ran it with fixed dollar amount mode and there I see indeed that it works fine. However I wanted to run it in portfolio simulation mode with 5% risk percentage. For this I added a RiskStopLevel:

CODE:
Please log in to see this code.


When I do this and run it on all data in the nasdaq 100 yahoo stocks, I see several "2" or "3" entries that do not match a "1" entry (I hope it's readable):
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 28.666 28-10-1985 2,25 23-10-1986 4,14 83,98 ? 54.162,74 251 ? 215,79 1 MA XU -0,73 117,38

Long AAPL 142.395 8-11-1985 2,57 23-10-1986 4,14 61,09 ? 223.544,15 242 ? 923,74 2 MA XU -8,22 90,32

Long AAPL 82.937 19-12-1985 2,84 23-10-1986 4,14 45,77 ? 107.802,10 214 ? 503,75 3 MA XU -4,84 72,22

Long AAPL 64.150 20-2-1986 3,14 23-10-1986 4,14 31,84 ? 64.134,00 172 ? 372,87 4 MA XU -3,47 55,77

Long MSFT 2.790.533 21-10-1986 0,13 29-10-1987 0,33 151,76 ? 555.086,90 260 ? 2.134,95 2 MA XU -3,31 319,87

Long AAPL 41.362 27-10-1986 4,25 28-10-1986 4,17 -1,89 ? 3.324,96- 2 ? 1.662,48- 1 MA XU -2,95 0,38

Long AAPL 250.874 30-10-1986 4,29 26-10-1987 6,99 62,94 ? 677.343,80 250 ? 2.709,38 1 MA XU -1,28 248,19

Long MSFT 1.839.273 6-11-1986 0,16 29-10-1987 0,33 108,87 ? 316.364,50 248 ? 1.275,66 3 MA XU -10,99 248,35

Long MSFT 566.615 5-1-1988 0,40 4-2-1988 0,35 -12,51 ? 28.346,75- 23 ? 1.232,47- 1 10% -12,50 7,20

Long JAVA 697.675 8-1-1988 2,22 20-1-1988 1,98 -10,81 ? 167.458,00- 9 ? 18.606,44- 1 10% -10,81 7,69

Long AAPL 25.091 12-1-1988 10,51 25-1-1988 10,21 -2,86 ? 7.543,30- 10 ? 754,33- 1 MA XU -9,02 7,04

Long COST 236.150 9-2-1988 9,13 28-3-1988 9,04 -0,99 ? 21.269,50- 34 ? 625,57- 1 10% -0,99 10,90

Long COST 89.667 18-2-1988 10,06 28-3-1988 9,04 -10,16 ? 91.700,51- 28 ? 3.275,02- 2 10% -10,16 0,62

Long PCAR 149.486 6-4-1988 3,83 9-5-1988 3,42 -10,64 ? 60.880,79- 24 ? 2.536,70- 3 10% -10,64 0,64

Long INTC 777.652 8-4-1988 1,02 19-5-1988 0,91 -11,15 ? 88.473,92- 30 ? 2.949,13- 2 10% -11,15 2,63
profile picture

Eugene

#4
Please note that RiskStopLevel should be added before executing an entry, not after the fact.
profile picture

wouterv

#5
Thanks for the pointer. I've changed that, but it does not make any difference, the same issue still occurs.
profile picture

Cone

#6
That code says, "if there are no active positions then check for a buy..."

How do you expect to pyramid like that?
profile picture

wouterv

#7
That was just a snippet of the code change I applied to this community code:

http://www2.wealth-lab.com/WL5WIKI/kbPyramid.ashx

So I'm taking the wiki example for pyramiding, changed it so I can use it with portfolio simulation and then I get pyramid trades that are not preceded by an actual real trade. My guess is it is because of the way portfolio simulations work.
profile picture

Cone

#8
QUOTE:
My guess is it is because of the way portfolio simulations work.
Could be. Portfolio Simulations can only enter new trades if you actually have enough free cash available for them. Just take a look at the Equity/Cash graph after a backtest. If you're seeing mostly light green (equities), then there you go.

You can also see if this is the case by running a backtest in Raw Profit mode. There you'll see all the trades.
profile picture

Eugene

#9
I see a problem with my code: it can enter pyramid positions if no initial position has been taken when there's insufficient capital (in portfolio simulation mode).
profile picture

wouterv

#10
The question that remains is: how can I actually pyramid correctly in portfolio simulation?
So that it won't open a position unless another position has REALLY been opened?
profile picture

Cone

#11
I'm with you now. It's a good question, and not a simple solution (if one actually exists), that deserves a KB article.

While we don't necessarily support custom solutions in Support, please create a support ticket for this one. We'll need time to look into developing a solution and putting it up on the wiki.
profile picture

Eugene

#12
To anyone interested, here's the four possible pyramiding scenarios in our PosSizer library. All available in a few clicks and no programming required:

Pyramiding PosSizer > The shape of the pyramid
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).