Spread Equity Equally PosSizer
Author: Panache
Creation Date: 8/16/2016 11:06 AM
profile picture

Panache

#1
I'm not sure I understand how Spread Equity Equally works. I thought it was supposed to divide the remaining cash or equity equally among the positions to be purchased, ie. if I there were $1,000 of cash and two positions were to be purchased, each would be $500. If so, it doesn't appear to be working.

Secondly, I assumed that each time a Strategy was run, it would give the same results. That too seems to be a problem.

To demonstrate, here's a very simple Strategy:

CODE:
Please log in to see this code.


I have a Starting Capital of 1,000,000 and configure Spread Equity Equally to have a Max Position Size of 1,000,000 shares (to make sure that isn't a limiting factor), using cash. I'm running this on a Fidelity DataSet consisting of AA.

If I run this Strategy several times, I get one of two results:

AAPL 5,156 shares at 98.97 ($510,289.30)
AA 30,341 shares at 8.29 ($251,526.90)

or

AA 61,957 shares at 8.29 ($513,623.50)
AAPL 2,508 shares at 98.97($248,216.80)

First, I don't understand why the PosSizer would be giving me such dramatically different results.

Second, in both results, the second position is approximately half the dollar amount of the first position, instead of having an equal dollar value.

Finally, I don't understand why in both results, the total position is only approximately 75% of my Starting Capital. The first position is approximately correct, although about $10,000 too big, but the second position is only about half as big as I would have expected.

profile picture

Eugene

#2
QUOTE:
I have a Starting Capital of 1,000,000 and configure Spread Equity Equally to have a Max Position Size of 1,000,000 shares

Sorry if it has confused you but the minimum and maximum position sizes are not shares but percentages. In this case as you wouldn't want to exceed 50% per position, enter "50" instead of "1,000,000".

QUOTE:
First, I don't understand why the PosSizer would be giving me such dramatically different results.
...
Secondly, I assumed that each time a Strategy was run, it would give the same results. That too seems to be a problem.

There's no problem considering your demo strategy's design that lets randomization take place. If you're not familiar with the Position.Priority concept then please check out the informative Wiki FAQ on topic: Every time I run a Strategy I get a different result. What am I missing? It will help you find out why it happens and how to stabilize the trades.

QUOTE:
Second, in both results, the second position is approximately half the dollar amount of the first position, instead of having an equal dollar value.

Thanks, I'll look into it and let you know later.
profile picture

Panache

#3
QUOTE:
There's no problem considering your demo strategy's design that lets randomization take place. If you're not familiar with the Position.Priority concept then please check out the informative Wiki FAQ on topic: Every time I run a Strategy I get a different result. What am I missing? It will help you find out why it happens and how to stabilize the trades.


Correct me if I'm wrong, but I didn't think there was any need to assign priorities unless there was a possibility of the Strategy generating more signals than the PosSizer was able to accommodate, ie. if you are setting the Position Size to 50% of equity and the Strategy generates 3 signals, without priority, you are going to get various combinations of 2 of the 3 trades.

In this case, were my Strategy generates exactly 2 signals, and the Position Sizer should accept up to 100 buys, I expected to get the same result every time, which is what happens if I use Percent of Equity 50, with a modest Margin Factor.

btw - As I was proving to myself that 50% Equity produced the correct result, I noticed that the first position in Spread Equity Equally (whichever result) is exactly the same as what is generated by 50% Equity, ie. AA 61,957 shares and AAPL 5,516 shares. Therefore, the problem with Spread Equity Equally appears to be how it calculates the number of shares for subsequent positions. Just for grins, I added a third buy, and Spread Equity Equally again sizes the first position correctly, the second position is about 2/3 of correct size and the third position is about 1/3 of the correct size. I hope that helps.
profile picture

Eugene

#4
Thanks for raising this issue. I've determined that the PosSizer is functioning mostly correctly although in an unexpected manner. Here's what happens. Let's assume that the maximum position size is 50% and your system takes 2 trades. Wealth-Lab processes the candidate trades one by one.

1) When you choose "Cash", this value gets decreased by Wealth-Lab with every trade being made and passes it to the PosSizer. The first trade may get up to 50% of the total cash but the next trade also gets 50% of the remaining cash i.e. only 25% equity. Obviously this is not what users expect the PosSizer to do!

2) When "Equity" is chosen, this value remains steady and Wealth-Lab returns it to the PosSizer for every other candidate trade on this bar. The equity is spread equally as expected.

Consequently I recommend against using the "Cash" option. It was not tested fairly well. As removing it from the GUI may have adverse effects on existing setups I'm considering to make both options work equally (i.e. both to be equity-based) in a future release. A note has been added to the Wiki.
profile picture

Eugene

#5
P.S.

QUOTE:
Correct me if I'm wrong, but I didn't think there was any need to assign priorities...

Sure I will. Things to keep in mind:

1) Having not fixed the Position.Priority either way, be it code-based or via Preferences, randomization takes place. With the now infamous "Cash" option activated, the first candidate always gets the correct size while the subsequent ones get a progressively decreasing size.

2) To be on the safe side, for 2 trades your maximum trade size should stay below 50% even with the "Skipped trade solution" activated, or 33% for 3 trades and so forth. A small Margin Factor might further help the "Solution" option.
profile picture

Panache

#6
Thanks. It appears to be working fine using Equity instead of Cash.

Since you've been thinking about this, I have two more questions about using it:

1. If I am back testing and don't know how many signals are going to be generated, is there any reason it won't work setting the percentages from 1 to 100 to make sure I am fully invested? From my very limited testing, having the maximum be 100 gives the same result with 2 signals as having the maximum set to 50.

2. Along the same lines, is there any reason I can't set the Margin Factor to 2:1 instead of something smaller to make sure I don't skip any trades when back testing, even with the Skipped trade solution?
profile picture

Eugene

#7
QUOTE:
2. Along the same lines, is there any reason I can't set the Margin Factor to 2:1 instead of something smaller to make sure I don't skip any trades when back testing, even with the Skipped trade solution?

The "Skipped trade solution" does its job by replacing Wealth-Lab's basis price from the penultimate bar's Close with the next bar's Open price. However, sometimes it still needs some help. The difference between 2:1 and e.g. 1.05 is in the little leeway that the second option provides. That leeway helps to make sure all trades are executed when you don't want to reduce the size to e.g. 49% or less - although this is an option too.

QUOTE:
From my very limited testing, having the maximum be 100 gives the same result with 2 signals as having the maximum set to 50.

That's because both 50 and 100 would reject your 2nd trade alike provided that you haven't activated the "S.T. solution", or reduced the max size somewhat below 50, or used a leeway in your Margin Factor.
profile picture

Eugene

#8
In v2016.09 of MS123 PosSizers, the "Cash" option in "Spread Equity Equally" has been depreciated. For backward compatibility it's now made to return result equal to the "Equity" option that functions correctly.