PosSizer with One Trade per Symbol
Author: falcon82
Creation Date: 1/22/2013 10:16 AM
profile picture

falcon82

#1
Hello,

the last time I had some issues because Wealth-Lab does a wrong backtest with the Multi-Symbol-Backtest because Wealth-Lab executes all signals first and then applying position priority and position sizing overlay. Thats not the way you would execute a system in real live. For more Information see here: Strategy Window > Backtesting Strategies > Inside a Portfolio Simulation, Single-Position Strategies with multiple triggers

Anyways, I don t wanna discuss this again because it appears a few times in this forum. I got a solution for the problem: First I code my strategy with the Multi-open-Position template (including Position Priority for sure) and then applying a Position Sizer on this strategy to force the backtest just to trade one trade per symbol. With this solution the backtest is like in real live - a Real-Portfolio-Backtest.

BUT with this solution I have the next problem:-/ There are only a few Position Sizer (e.g. One Trade per Symbol, Position Options) which have the option to select *only one trade per symbol*. The other Position Sizer don t have this option and if I would like to apply other position sizing rules on the strategy I would run a Multi-open-Positions strategy what I don t want.

SO I have three questions:

1. Is it possible that every Position Sizer gets the option *one trade per symbol*? Maybe just a little checkbox or something else to use other position sizing rules but with a real-portfolio-backtest.

2. Is there a *simple possibility* to apply more than one Position Sizer on a strategy?

3. Maybe this question already answer the question two but with *no simple possibility*. I know that I could apply more position sizing rules on a strategy when I code the Position Sizer on my own. I already found the manual from Fidelity and got the information from the WealthLabWiki. But I think that the examples are quite rare. In the Wiki is just one Position Sizer example (Random Sizing). Is it possible to put a few more examples in the WealthLabWiki (like with the strategies) just to have some more code snippets that I could use for my own Position Sizer?

Maybe some else can give me an example how I could code a Position Sizer with *one trade per symbol* and *equity trading rules*. Thanks!
profile picture

Eugene

#2
Re: real life. This is how Wealth-Lab has always been designed. This is a close approximation. Changing the way it works (e.g. "date-sequenced backtest") would be an architectural change, and such challenge is not considered. Although I dont understand how using a multi-position template would help override this design, as it seemingly changes nothing, let us simply address your questions as they come:

1. No, this is simply not possible. If an option is reasonable or natural, we may consider adding it. (Example: adding the Turtles risk control to the Percent Volatility PosSizer, because the Turtles themselves were using a volatility-based money management sizing). But taking a part of a PosSizer to apply to another on demand is not an option.

2. The way to combine position sizing rules is by coding a custom PosSizer.

3. I believe the examples in the Wiki are sufficient to start building every type of PosSizer: either inherited from BasicPosSizer or from PosSizer. Sorry but the MS123 PosSizers library code is closed source.

Since what you are asking for is simple, below are a couple of code snippets to help you get started:

CODE:
Please log in to see this code.


As you could have read in the PosSizer API document, creating an indicator off of the current EquityCurve is a no-brainer. One thing you have to keep in mind is that since these DataSeries are being built dynamically, the developer should call the "Value" method to access indicator values instead of the "Series" method. Otherwise an incorrect value will be returned by your indicator/PosSizer.

Considering the aforementioned, there is nothing obscure about trading the equity curve:

CODE:
Please log in to see this code.

profile picture

falcon82

#3
Hello Eugene,

thanks for your answer - it helps a lot!

I don t know why it works but when I code the strategy in Multi-open-Positions mode AND apply a Position Sizer on the strategy which limit the *max open positions* to one then I have the result that the backtest takes every (not open) position with the highest priority in the Portfolio Backtest. When I code a strategy in Single-open-Position (LastPositionActive etc.) mode WL doesn t take every (not open) symbol with the highest priority because it applies the position sizing and priority after it runs over the symbols in raw profit mode. In this case Wealth-Lab skips some symbols with a high priority in the Portfolio-Backtest because it thinks that these symbols were already open. I already pasted the explanation link from the WL documentation in my first post. I don t know why the first way (multi positions) works and the second (single position) doesn t!?

I have one last question! Maybe you can save me a lot of work. I really like all your Position Sizer in WL and I think that these Sizers cover nearly all money management technics. So in the future I will definitely code some on my own but at the moment I don t see the need for that (except for the open position control) because WL has a lot of useful sizers. The only think is that I want to limit/reduce the *max open positions* in a Multi-open-Positions strategy.

So I thought maybe there is a way to size the *max open positions* directly in a WL Multi-open-Positions strategy script? Maybe after the barloop or with another trick? So I could control the *max open positions* directly in the Multi-open-Positions strategy script and can then apply some WL Position Sizer on the strategy. Is there a possibility?

Thanks for your help!

profile picture

Eugene

#4
There is no other way to size a Position in script but to use SetShareSize().

EDIT 03/21/2018: Or one can use the Position Options PosSizer's ability to read percent equity or max % risk from .Tag property.
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).