- ago
I was experimenting with the Advanced Pos Sizer/ Trading the Equity Curve, came across some "unexpected" results. To illustrate:

Test strategy: A Seventeen Liner (located in Sample Strategies folder)

Test A: Baseline
All default settings (Pos size 5k, fixed; backtest on Dow 30 dataset, etc)


Results


Equity Curve (to show its in a downtrend)


Signals for next trading day

With a current price of ~$300, the trading size for each alert is ~$4800, or let's say $5k as per the pos sizing.
So far, so good, everything as expected.


Test B: Trading the Equity Curve
Settings used, note the use of Fixed Value of 5k for base sizing as in Test A above, all other settings are default, the box to Reduce is checked


Results

Note that the Exposure went UP, not down

Signals for next trading day

Each signal equates to 35 x 300 = $10k (rounded)! How's that possible? Since the Equity is in a drawdown the Pos size is supposed to be cut (by 50%), not increased. Moreover, each trade size now comes at 2x the base fixed pos size of 5k!

Also, a review of the Positions in Backtest Results shows

The 1st trade for BAC is the right size (5k) but the next two are 7.5k each i.e. 50% > base pos size. But the box to Reduce pos size is checked!


Test C - Trading the Equity Curve #2
One setting modified... UNchecked the box to Reduce/Increase size, unchecking is supposed to Increase (not Decrease) the pos size by X (50) %


Results

cf baseline: the exposure went DOWN, not up

Signals for next trading day

Trade size works out to 5.7k (19 x 300) which, while higher than the base pos size of 5k, is not +50%.


To summarize the issues with Trading the Eq Curve pos sizer:
1. The Reduce (enabled) / Increase size (disabled) seems to be doing the opposite.
2. Past trades were executed at 2 x base pos size which simply cannot happen in any scenario.
3. Trade signals are being generated at strange pos sizes.

I would encourage the developers to test it all on their PCs.
0
513
Solved
20 Replies

Reply

Bookmark

Sort
- ago
#1
I see bugs in the code now. Fixing them for PowerPack B7. Thanks for spotting this.
1
- ago
#2
(This may seem obvious but) Can you please clarify...
When one is doing a Portfolio Backtest, does this Position Sizer use the Portfolio Equity or is each security assessed individually against its own equity?
0
- ago
#3
The portfolio equity.
0
- ago
#4
Using WL8 B15. PowerPack B7.

The Reduce (enabled) / Increase size (disabled) option appears to be working correctly. However, other issues remain, to illustrate....

All testing as in original post (17 Liner strategy/ P'folio Backtest on Dow 30), data till Fri, 9/2/22.


First tested using Incr Pos Sz by 50% when Eq is in drawdown:

Since Eq is in drawdown the new Pos Sz should be 5k (base) + 50% = 7.5k.
Here are the alerts for next trading day:

The Pos Sz is coming out to approx 10k, not 7.5k e.g. AAPL closed ~156 x 65 shares = ~10k.

Moving on...
Now checking option to Reduce Pos Sz by 50%:

Since Eq is in a drawdown the new Pos Sz will be: 5k -50% = 2.5k. Let's check...

With the new setting here are the alerts for next trading day:

The new Pos Sz is coming out to ~3k whereas it ought to be 2.5k.

Also, here are some open positions with trade date of 8/31/22:

Pos Sz for HD = 17 * 292.47 = ~5k
Pos Sz for AAPL = 16 * 160.58 = 2.5k
(numbers rounded)
How can one have two different Pos Szs for the same bar?

TL;DR
- Reduce/Increase option now works as intended
- Position Sizes are still not always correct, either in backtesting or for alerts
0
- ago
#5
Although you stress "a drawdown", the PosSizer does not consider drawdowns. It goes into action when either the fast moving average of equity or the equity itself gets below the slow MA (depending on "Instead, use Equity/SMA2 crossings"). Have you checked the equity MAs?
0
- ago
#6
It's semantics.
A drawdown in equity is what would cause the fast MA to cross below the short MA.
Eq drawdown is the cause, MA crossunder is the effect.


Be that as it may it shouldn't cause:
- different Pos Sizes on the same bar
- wrong Pos Sizes (e.g. 10k size can only be caused by coding error as its not the properly adjusted size).
0
- ago
#7
QUOTE:
The Pos Sz is coming out to approx 10k, not 7.5k e.g. AAPL closed ~156 x 65 shares = ~10k.

On this Sep 2 bar my results are $7.4K for AAPL, $5K for DIS. Not ~10K.

QUOTE:
How can one have two different Pos Szs for the same bar?

Trying to find an explanation for this, I think that maybe the bar numbers of the EquityCurve (portfolio's) and the Transaction object are out of sync. Like the position sizing for the two symbols is processed based on the EquityCurve on different bars. :/

UPDATE: Yes, this is right. At the moment this PosSizer could be reliably used if all symbols have an equal bars count.
0
- ago
#8
I'll get this fixed in PowerPack B8.
1
Best Answer
- ago
#9
QUOTE:
On this Sep 2 bar my results are $7.4K for AAPL, $5K for DIS. Not ~10K.

Hmm... the screenshot I attached clearly showed the Pos Sz was coming out to 10k for the Alerts.
-------------------------

BTW, other Pos Sizers have issues too, I'll try to write them up soon.
0
- ago
#10
QUOTE:
BTW, other Pos Sizers have issues too, I'll try to write them up soon.

Looking forward to it (assuming a new topic).
0
- ago
#11
/// Updated to WL8 B16, PowerPack B8. ///

In order to duplicate the original post which used daily data for 10 years with a last date of 8/26/22, set that date range under Backtest Data; Eq Curve Pos Szr is set to Reduce sz by 50% on 5/25 MA crossunder:


As in the original post 3 alerts were generated:

Each alert equates to 20 x 300 = $6k (rounded). This is incorrect as the Pos Sz can either be 5k (base size) or 2.5k (adjusted by -50% if MA condition is met).
-----------------------

Moved the date range forward by 1 week, to 9/2/22, to mimic as in reply #4 above.

First, lets check under Backtest Results/Positions what happened to those alerts we saw on 8/26/22:

Their Pos Sz comes out to 5k (rounded). Note that the alerts were for 20 shares @Market; on backtest 17 shares were bought.


Let's check the alerts generated on 9/2/22; Eq Curve Pos Szr set to Reduce Pos Sz by 50%:

Pos Sz for AAPL = 19 * 156 (close of 9/2/22) = 3k (rounded); for DIS = 27 * 111 = 3k; for GS = 9 * 331 = 3k.
The Pos Sz can either be 5k (base size) or 2.5k (adjusted by -50% if MA condition is met).


Finally, let's check what happens to alert Pos Sz when the Eq Curve Pos Szr is set to Increase Pos Sz by 50%:

The Pos Sz is coming out to 10k (rounded) whereas it can either be 5k (base size) or 7.5k (adjusted by +50% if MA condition is met).
----------------------------------------

TL;DR:
1) Reduce/Increase option in the Pos Szr works as intended (...was fixed in PwrPk B7).
2) Pos Szs on backtest: Trades on same bar are now the same size (...fixed in PP B8).
3) Pos Szs on backtest: More or less as expected (...fixed in PP B8).
4) Position Sizes for ALERTS remain incorrect (even though the backtest will show their future positions' sizes to be adjusted as per the sizer). This remains to be fixed.
0
- ago
#12
Glad to hear it works (mostly). The sizing of alerts is correct for me.
0
Cone8
 ( 24.99% )
- ago
#13
I’m not following the whole discussion, so take this with a grain of salt. Is it possible that the alerts are affected by the broker account size? Do you have that preference selected?
0
- ago
#14
@Cone
Broker a/c size is irrelevant as its fixed position size (adjusted, if needed, based on Equity Curve).

@Eugene
The Pos Sz for alerts is incorrect, as amply demonstrated in the screenshots above.
While an adjustment to the base Pos Sz is being made, if needed, its by the wrong amount. There's a math error somewhere.
0
- ago
#15
I cannot duplicate, there is no math error and it works for me.
0
- ago
#16
Image of part of my Post #11:

----------------------------------------------------

There is a clear discrepancy between Pos Sz in Alerts and Pos Sz in Positions, as illustrated. And Pos Sz is fixed so its not like we're using "% of A/C equity" to explain the discrepancy.

I respectfully ask one of the other developers to step in and resolve.
Its a long thread and may take a while for them to get up to speed....
0
Glitch8
 ( 10.94% )
- ago
#17
Hmmm, in my test just now the alert is correct, it's $5000 (half the $10000) and the same quantity as the resulting position that occurs if I extend the date by 1 day.

0
- ago
#18
(The Pos Sz is actually 10k in your example: 44 * 227 = ~10k)

Assuming you're using PowerPack B8 also...
Since your Alert quantity matched the Position quantity I guess that settles it, though I don't understand why I got discrepant results (on a Portfolio Backtest on Dow 30)... maybe there are ghosts in my machine, LOL.
Thanks for settling the matter.
------------------

I want to thank Eugene for his effort in fixing the Pos Sizer... it had multiple bugs and he stayed with me all the while trying to figure out where they were.
In the final stretch I thought the Alerts still had a bug so I just wanted a second opinion as I wanted this important Sizer to be *completely error free*.

Ciao!
0
Glitch8
 ( 10.94% )
- ago
#19
I’ll test some more tomorrow with a portfolio backtest, maybe there’s some difference there.
0
- ago
#20
Just to clarify: I tested on the W-D Dow 30 portfolio, truncating bars after 8/28/2022 to get Alerts. The position size was correct. After the fixes I don't see how else could the discrepancy come from the PosSizer logic, if only from the EquityCurve value maybe.
0

Reply

Bookmark

Sort