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.ashxHere 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.
Size:
Color:
Size:
Color:
Thank you, Eugene, that was just what I needed
Size:
Color:
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.
Size:
Color:
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.
Size:
Color:
Size:
Color: