How to size positions equally?
Author: MrIzzy
Creation Date: 3/21/2014 6:47 PM
profile picture

MrIzzy

#1
I have a certain system that does weekly trades.
So each week it buys a number of positions and then sells them.
The number of positions changes week to week.
The positions are equally sized.
So if on a certain week, I have $100,000 and need to buy ten positions, I would allocate $10,000 to each position.
How can I backtest this strategy? I can't use "% of equity" since the number of positions changes in each period.

Ideally, I would like to write something like:

CODE:
Please log in to see this code.



The strategy knows the number of positions it has to open but can not access the "PortfolioEquity"

I thought of using the techniques described here:
http://www2.wealth-lab.com/WL5Wiki/kbInteractingWithPortfolioEquity.ashx


Here I have access to PortfolioEquity.
Two questions:
1) how can I access the number of positions in each week?
2) how do I set the position size in this area of the code?
CODE:
Please log in to see this code.



Thanks for any insights you could provide.
profile picture

Eugene

#2
The Spread Equity Equally PosSizer from MS123 PosSizers library is designed to automatically arrive at equal exposure by spreading available equity/cash equally based on the number of Alerts generated by the system.

Note that in v6.6 it might not work for live trades, only for backtesting due to live bug #62853 - In PosSizers, the Candidates list is empty for Alert sizing.
profile picture

MrIzzy

#3
Thank you, Eugene, that was just what I needed
profile picture

MrIzzy

#4
Hi Eugene,

With regards to "Spread Equity Equally", a very useful feature would be to allow the user to leave some "wiggle room".

When I use a strategy that always has ten positions and I size them equally, I give each position 9.8%. If I give 10% to each position there are a lot of missing trades due to lack of capital.

Now that we are going to a strategy with changing number of positions, and need to use the PosSizer, the same things happens. There are a bunch of missing trades due to lack of capital. It would, therefore, be great to add a parameter to the PosSizer where you could instruct it to leave a similar wiggle room.

I'd like to have a setting that one could say something like 2%. In that case, the PosSizer would take 98% of the equity and divide between the positions. That would eliminate the number of missing trades.
profile picture

Eugene

#5
Since v2013.04 of the library, the PosSizer already has an option called "Skipped trade solution" which will do almost what you request. Instead of "wiggle room", it adjusts the basis price so that for *AtMarket(bar+1) orders the position size is calculated with regard to the open price of entry bar (bar+1) vs. the close price of signal bar (bar). More information is available in the User Guide > Strategy Window > Backtesting Strategies > 100% of Equity Sizing. Don't be confused by "100%": ten positions at 10% each is essentially the same thing. While activating the option will not magically eliminate all missing trades, that should be a partial relief.
profile picture

Eugene

#6
QUOTE:
Note that in v6.6 it might not work for live trades, only for backtesting due to live bug #62853 - In PosSizers, the Candidates list is empty for Alert sizing.


UPDATE:
This bug will be fixed in WLD 6.9.24. No ETA at the moment as we're still trying to fix an issue with this build.
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).