Manually setting position size
Author: cravens
Creation Date: 7/11/2012 4:19 PM
profile picture

cravens

#1
I would like to set position size. I am trying to use SetShareSize(300) to get 300 share position size. When back-testing the size defaults to the Fixed Dollar amount in the Portfolio Simulation Mode window. If I want the order to be 300 shares why does this not work? I also need it to work in the Strategy Monitor for actual trades.

What I would like is to have the amount from the Portfolio Simulation Mode window (Say $1000) passed to the SetShareSize() function
and have the limit order set to something like SetShareSize() to attain the value of 0.5*$1000/Close[bar].
Is this possible?

Thanks

Rob

profile picture

Eugene

#2
QUOTE:
If I want the order to be 300 shares why does this not work?

It may not work because you didn't select the WealthScript Override option from the Position Size dialog.
profile picture

cravens

#3

thanks. That worked.

Is it possible to pass the 'Fixed Dollar' value to the wealth script and divide it among several orders such as:

Size1 = 'Fixed Dollar'/5
SetShareSize(Size1)

Size2 = 'Fixed Dollar'/2
SetShareSize(Size2)

Size3 = 'Fixed Dollar'/3;
SetShareSize(Size3)


Is this possible somehow?

Rob



profile picture

Eugene

#4
Pass a share size to a different Strategy? Sounds unclear to me.
profile picture

cravens

#5

One strategy buys three different times scaling in with different percentages of the 'Fixed Dollar' each time.
The first time I want to buy 20%*Fixed Dollar/Close[bar], the second time I want to buy 30%*Fixed Dollar/Close[bar], the third time I want to buy 50%*Fixed Dollar/Close[bar]. This usually happens on three consecutive days but not always.

It needs to work from both the position sizer when back testing and when running in the strategy monitor on a daily basis.

Rob
profile picture

Cone

#6
CODE:
Please log in to see this code.
profile picture

cravens

#7

Thank you. It looks like what I was trying to do.

Rob
profile picture

ronc

#8
I am also setting position size in my code. I am using a single-position strategy, optimizing several variables. One of the variables I want to optimize is the number of positions. In other words, I set the portfolio cash size and then break that into multiple positions. The position size is determined from the number of positions, which is an optimization variable:

CODE:
Please log in to see this code.


In the Wealth Lab UI I set Position Size > Portfolio Simulation Mode > Wealth Script Override (SetShareSize), and I set the Starting Capital = 100,000 as in the code. This works fine during optimization. However, if I then set Preferred Values based on an optimization and then run with those PVs on a different time frame, I get messages saying that trades were not included due to insufficient capital. Since my code is using the same portfolio size as the UI ($100K) I am not clear how it can have insufficient capital, unless it is simply the portfolio losing money along the way due to losing trades.

In any case, what I want to do is run a full test, with all trades executed, based on the variable values from the optimization. Portfolio Mode does not seem to do this since it drops some trades. Raw Profit mode also does not seem to work because it uses the position size from the UI, whereas I want to use the position size that is calculated from the code above, based on the optimized number of positions (maxPositions), which is one of the PVs.

To clarify my ultimate objective, I am trying to optimize (among other things) how many increments to slice the investable cash into when trading a single symbol. E.g. given $10K, is it better to buy and sell in increments of $10K or e.g. N increments of size ($10K / N).

Any suggestions?

Thanks,
Ron
profile picture

LenMoz

#9
Hi Ron,

Another discussion on this topic can be found here ... http://www.wealth-lab.com/Forum/Posts/Optimizing-Number-of-Positions-35459
I created a strategy that optimizes "number of positions". It wasn't easy. The design of that strategy can be found at my post #4 at the link above.

Jumping way ahead now, to my thoughts on the efficacy of optimizing number of positions. For my strategy, optimizations almost always picked the fewest number of holdings I allowed. I concluded that this is not for a good reason. Rather, the optimization is over-fitting, setting the other parameters to pick the smallest number of good trades, then amplifying the results by picking the fewest number of trades. Think of it this way. If limited to one trade, optimization will set the parameters to choose the best instrument to own at each bar. If limited to two positions, it may again find the best plus the second best, and the average is a little worse.

Your results may vary.

Len Mozeko

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).