PosSizer "Spread Equity Equally" request: choose percent of equity on each bar
Author: jedi2wlp
Creation Date: 2/20/2017 8:28 AM
profile picture

jedi2wlp

#1
I was wondering if it would be possible to add another field to the "spread equity equally" PosSizer. I would love to see a field that says "Percent of Equity" where I could choose what percent of equity can be used on each bar.

Background: I have a strategy where I'd like to be invested in the market as much as possible and also not miss any trades due to insufficient capital. The strategy has a max holding period of 10 days so I'm hoping to be able to set the backtest up so that every trading day 10% of my equity is available to place trades and that all the trades on each day would be spread equally among that 10% of available equity.

I saw there was a guy that wanted to do something similar and he was able to figure it out by programming it: https://www.wealth-lab.com/Forum/Posts/PosSizer-for-rotational-strategy-with-overlapping-buys-and-sells-38538

Unfortunately, my programming experience is pretty limited so I was hoping this could be added as a feature which I think would be beneficial to future users. If you guys are able to build it, I'd be more than happy to help out with the QA testing on it.

best regards,

Ryan
profile picture

Eugene

#2
Hi Ryan,

Thanks for your suggestion. Before I consider to review this idea, let's see if your task could be approached with existing tools.

QUOTE:
I would love to see a field that says "Percent of Equity" where I could choose what percent of equity can be used on each bar.

What would it give? A PosSizer only sizes positions when they're created, by itself it cannot readjust the percent of equity on each bar. However, rebalancing could probably be reached in conjunction with the Balancing PosSizer if your Strategy is specially crafted for use with it (see example in the Wiki).

QUOTE:
I have a strategy where I'd like to be invested in the market as much as possible and also not miss any trades due to insufficient capital.

In this case, what if you try to set a reasonable percent equity to catch most alerts, a Margin Factor, and some of the Position Options PosSizer's features: "Max Open Positions (n)" + "For last position, use all what's left" and optionally, the "Skipped trade solution" if your system's trades are AtMarket?
profile picture

jedi2wlp

#3
Thank you very much Eugene for the reply. I spent some time tonight attempting to use the existing tools as suggested but my attempts were unsuccessful unfortunately.

QUOTE:
What would it give? A PosSizer only sizes positions when they're created, by itself it cannot readjust the percent of equity on each bar. However, rebalancing could probably be reached in conjunction with the Balancing PosSizer if your Strategy is specially crafted for use with it (see example in the Wiki).


To clarify what I'm attempting to accomplish, let me explain a little further. The PosSizer would size the position at the time of the trade and it would not re-adjust or re-balance after the fact. Attached is an image of what I imagine the backtest would approximately look like on an account that has $100,000 starting capital and uses 10% equity on each trading day. Hopefully the attachment makes it a little more clearer what I'm attempting to do.

I did look over the Balancing PosSizer example code, but since my experience in coding is extremely limited, I failed to comprehend how it worked. When I ran it, all the trades were 1 share each despite the fact that the code indicates a portfolio percentage of 30.

QUOTE:
In this case, what if you try to set a reasonable percent equity to catch most alerts, a Margin Factor


I definitely could try to set up a reasonable percent equity to catch most of the alerts. However, I’m wanting to create a standardized backtest (where percent equity, margin factor, etc would stay the same) that I can run on 20 different data sets without missing trades and being in minimal amounts of cash. My plan is to run the strategy on various data sets that have different types of stocks in them (for example, big cap stocks, small cap stocks, etc) to see if the strategy works better on certain data sets.

QUOTE:
and some of the Position Options PosSizer's features: "Max Open Positions (n)" + "For last position, use all what's left" and optionally, the "Skipped trade solution" if your system's trades are AtMarket?


I did look at the Position Options PosSizer but I it doesnt' appear to offer any way to to spread the trades equally. Setting max open positions would create missed trades which I’m hoping to avoid. “For last position, use all what’s left” would create some trades that are much bigger than others which is not ideal.

Please let me know if you have any other ideas or solutions Thanks again Eugene for the help,

Ryan
profile picture

jedi2wlp

#4
attachment
profile picture

Eugene

#5
Ryan,

To spread equity equally on each bar using the PosSizer, you'd have to modify your Strategy to create (extra) trades on each bar. Here's a code example by Cone in a parallel thread. Only creating new trades makes a PosSizer size (new) positions.
profile picture

jedi2wlp

#6
Eugene,

Thanks again for the help. I looked at the thread you mentioned and the code. If I understand correctly, they're closing all the positions and then reopening them with the new sizes; this is being done to rebalance the portfolio each month.

In my strategy, I actually don't want the positions to ever adjust. The buys occur, they stay open for between 2 and 10 days and are then closed. The number of shares never changes. Here's another attachment with more details of what I'm trying to accomplish. Any help is greatly appreciated.

Ryan
profile picture

Eugene

#7
Ryan, so your system doesn't rebalance at all. That's fine. Then what's the problem with the "Spread Equity Equally" PosSizer? I'm confused.

Do you want it to have a flexible % Equity parameter (via script input, I suppose) to catch all signals? If so, it would no longer "spread equity equally".
profile picture

jedi2wlp

#8
QUOTE:
That's fine. Then what's the problem with the "Spread Equity Equally" PosSizer?

The problem with "Spread Equity Equally" PosSizer is I can't tell the system how much total equity it is allowed to use on each day (bar).

QUOTE:
Do you want it to have a flexible % Equity parameter (via script input, I suppose) to catch all signals?

So, yes, I would love to see a parameter that says "Percent of Equity" where I could choose the percent of equity that can be used on each day (bar). And yes, my intention is to be able to catch all signals.

Example:
If I chose 10% for "percent of equity":
On the first day, the system would be allowed to use 10% of the equity on the trades for that day. It would look at the alerts and spread the 10% that's available amongst the trades. So, if there were 10 alerts, each trade would be sized at 1% of the total equity and thus only 10% equity would be used on that day.

QUOTE:
If so, it would no longer "spread equity equally".

So, yes, on some days the trades would be larger in dollar value if there were only a few alerts on that day; on other days the trades would be smaller if there were a lot of alerts.
profile picture

Eugene

#9
QUOTE:
I can't tell the system how much total equity it is allowed to use on each day (bar).

It's not a problem, it's by design. You can tell it to not exceed some min/max size, and that's all. To tell it to use a different percentage would make it some different PosSizer. And actually, I don't understand why you think you need this input. The PosSizer's already doing all that automatically.

QUOTE:
So, if there were 10 alerts, each trade would be sized at 1% of the total equity and thus only 10% equity would be used on that day.
...
So, yes, on some days the trades would be larger in dollar value if there were only a few alerts on that day; on other days the trades would be smaller if there were a lot of alerts.

You're describing what the PosSizer has already been doing: spreading equity equally. See why I'm still confused?
profile picture

jedi2wlp

#10
QUOTE:
It's not a problem, it's by design. You can tell it to not exceed some min/max size, and that's all.

This is why I was asking for an enhancement be added to the PosSizer to allow this. Or create a new PosSizer that would be able to do this.

QUOTE:
I don't understand why you think you need this input. The PosSizer's already doing all that automatically.

I need this parameter so I don't miss trades and so I don't have too much sitting in cash. Currently, this PosSizer simply looks at all your equity and then spreads the trades based off this number. So, if have $100,000 in equity, set my max position size to 10% and if I have 5 trades, it uses up 50% of my equity which would likely cause future trades to be missed. If I set it to 1%, then I end up sitting on too much cash. Since I don't know how many trades will be triggered each day, it's important to be able to size the trades each day so they don't eat up too much equity.

QUOTE:
You're describing what the PosSizer has already been doing: spreading equity equally.

Yes, it spreads it equally for that bar, but it might use too much overall equity (which would cause future missed trades) or it might use too little overall equity (which will mean too much of my equity is in cash).
profile picture

Eugene

#11
Thanks Ryan, now it starts making better sense. Please have a look at Graded equity percentage PosSizer then. While it might not provide the exact level of flexibility that you desire, it's one step ahead of "Spread Equity Equally". Let me know what you find and if it's not working well I'll put your enhancement request on my list for review.
profile picture

jedi2wlp

#12
I've looked at "Graded equity percentage" PosSizer, and unfortunately, it doesn't accomplish what I'm looking to do. I think the "Spread Equity Equally" PosSizer is more closely related with what I'm looking to do.

I would think it shouldn't be too difficult to add this feature to the "Spread Equity Equally" PosSizer, but then again, my experience in programming is very limited.

I imagine the formula in the PosSizer looks something like this for a $100,000 account

$100,000 / # of trades = position of each trade
If there's 5 trades, then 100,000 / 5 = $20,000 per trade

My suggestion would be to add logic of

( % of equity X 100,000 ) / # of trades = position of each trade
(10% X 100,000) / 5 = $2000

Would it be difficult to add this feature to the "Spread Equity Equally" PosSizer?
profile picture

Eugene

#13
I'll add this item to the project's backlog for a later review and let you know here in a couple of weeks.
profile picture

jedi2wlp

#14
Thanks Eugene, it's very much appreciated.

I was thinking about trying this guy's customer built PosSizer to see how it worked.
https://www.wealth-lab.com/Forum/Posts/PosSizer-for-rotational-strategy-with-overlapping-buys-and-sells-38538
post 28 has a zip file called "Abacus Position Sizer.zip"

Do you happen to know the steps to get his PosSizer into my PosSizer library?

Ryan
profile picture

Eugene

#15
Hi Ryan,

QUOTE:
Do you happen to know the steps to get his PosSizer into my PosSizer library?

Fortunately for you, the 3rd party "Abacus" PosSizer you referred to comes with compiled DLL (Abacus Position Sizer\bin\Release\Abacus Position Sizer.dll) which you could unpack straight to Program Files\Fidelity Investments\Wealth-Lab Pro 6 and then uncheck "Downloaded from the internet" and Apply (otherwise the DLL will not appear after restarting WLP). Make sure to unpack only that single file and not to create subfolders. The file has to be straight in the WLP main folder. Please give it a go and let me know if it covers your needs or not.

If it worked it would be optimal for several reasons. First, the addition of a percentage of equity, while not a big deal itself, looks slightly questionable as in your scenario the PosSizer consumes only a fraction of equity (e.g. 10%) instead of spreading it as its name implies.

The bigger issue is your request to set that percentage on each bar. So how would the PosSizer do it? Wealth-Lab is Position-based, PosSizers proceed candidates and positions. We can pass some values on to PosSizers with Positions' properties. Unlike e.g. Position Options which uses a property to provide natural position-based Max % Risk and % Equity, to let a single Position set the portfolio-based percentage would be awkward. Also, another candidate position may override (change) this setting as systems are likely to have multiple candidates to process on the same bar.

Long story short, from a design standpoint an elegant solution isn't evident to me at the present moment.
profile picture

Cone

#16
QUOTE:
which you could unpack straight to Program Files\Fidelity Investments\Wealth-Lab Pro 6 and then uncheck "Downloaded from the internet" and Apply
I don't think you'll be allowed to do that operation in the installation folder. Instead, put it in your downloads folder, right click > Properties > General > Click "Unblock" > OK, and then move it to the WLP installation folder.