Help to create PosSizer
Author: tassod
Creation Date: 11/21/2010 2:15 PM
profile picture

tassod

#1
Hi Eugene,

Thanks for taking care of the source code request. I don't know if this is to much to ask, but do you think you can help me out in getting started with creating a PosSizer for Wealthlab? I've started taking some courses during the past year on C# programing and have some basic knowledge. What I would like to do is create a PosSizer based on the Percent Volatility formula but will also allow me set an initial risk stop based on a percentage of my account equity.
profile picture

Eugene

#2
Hi,

I believe that the demo PosSizer's source code will help you get started in the right direction. It's pretty straightforward and illustrates the two ways of building a PosSizer:

1. Starting from scratch by inheriting from the PosSizer class,
2. Inheriting from the BasicPosSizer with all its added options.
profile picture

tassod

#3
Maybe i'm getting myself way to deep with this, my knowledge of C# hasn't quite reached the level yet of this source code. Maybe you can help me with the following code that you wrote for me a while ago.
CODE:
Please log in to see this code.

I want wealthlab to trade a fixed number of contracts and in this case, just 1 per trade (i'm testing this on futures contracts). I dont want my position size to be adjusted. None of the options in the portfolio simulation mode will do what I need it to do. Basically what i'm looking for is for the program to set an initial stop based on a percentage of my portfolio equity (example) - 1% of $250,000 or $2500. I've looked into RiskStopLevel but cannot get that to work and i dont believe that's what i'm looking for. Can i build a "DLL" for this or can it simply be coded into the strategy?
profile picture

Eugene

#4
RiskStopLevel is exactly what you need. As already said months ago. Refer to the original discussion: Setting a fixed initial stop. You don't need a PosSizer.
profile picture

tassod

#5
So which option do I choose in Portfolio simulation mode? Max percent risk?
profile picture

Eugene

#6
Right.
profile picture

tassod

#7
Eugene,

For certain i am doing something wrong, but i cannot get this to work. I'm using Max percent risk like you said and it is still sizing my positions and I don't want that, i just want it to trade 1 contract. Second, the code prior to me adding the RiskStopLevel used to exit where it was told to do so but now it just enters postions and does not exit. Here's the code:
CODE:
Please log in to see this code.
profile picture

Eugene

#8
There are several mistakes.

1. RiskStopLevel isn't used for exits as suggested by the QuickRef and the User Guide.

2. When coding for entries you forgot wrapping the group of statements in curly braces.
CODE:
Please log in to see this code.

And your entry is completely independent and unconditioned:
CODE:
Please log in to see this code.


As I'm reading over your request it seems strange. PosSizers are used to size positions. Max % Risk allows you to lose no more than X% of account equity. How does that fit with trading 1 contract, I don't understand.
profile picture

tassod

#9
Here is what the user guide says:

"Max Percent Risk

This option creates a position size based on an initial risk level that is set in the Strategy code. Your Strategy should assign the initial stop loss price level to the RiskStopLevel property. The Max Percent Risk setting requires you to specify the maximum portfolio equity loss that you are willing to tolerate. The result is a position size based on your maximum loss level calculated by the magnitude between the position's entry and stop prices."


Obviously, this is not the option I'm looking for because this does "size" my positions. When I execute the strategy, I get for example a "Quantity" of 5 for XYZ symbol when I only want it to be a "Quantity" of 1 at all times. Keep in mind, this strategy is testing futures contracts and not Stocks so that is what i mean by "1 contract".

This brings me back to my original question now on this thread and RiskStopLevel is not what I need.
profile picture

Eugene

#10
You don't need a PosSizer either. They're used to size positions, and your size is fixed (1). So you need to set the initial stop. But the account value is not available to Strategies since they have no access to portfolio-level information (equity, cash, etc.)
profile picture

tassod

#11
So how can I set a "fixed" initial stop then if I can't use the account value and obviously now I will be using Raw profit mode.
profile picture

Eugene

#12
In Raw Profit mode, there is no equity, and no cash. Consequently no Sharpe ratio, exposure et al.
profile picture

tassod

#13
So how would you suggest I approach this using what options? WealthScript overide? Or is creating my own PosSizer the only way to go?
profile picture

Eugene

#14
To close the PosSizer question, re-read my reply from 11/24/2010 11:46 AM. No suggestions from me currently.