Backtesting balancing of a portfolio
Author: leszek
Creation Date: 5/5/2014 5:57 PM
profile picture

leszek

#1
I hear all the time that balancing a portfolio is the way to go, so I decided to backtest that theory. I wrote a PosSizer and a script that allows me to optimize percentages of different symbols as well as the holding period. For anyone interested here's the strategy code:

CODE:
Please log in to see this code.


and here's the PosSizer:

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

Eugene

#2
Excellent contribution, thank you.
profile picture

ReneW

#3
Hello,

I wanted to test the mentioned "Balancing PosSizer" which has been introduced recently.

I tried the code from the WL wiki, the "Examples"-class was missing.

Luckily I found this additional piece of code above in this thread, but I was wondering
if this is really necessary. I had thougt that should be within the possizer library.

Furthermore, I have an issue with this strategy. Using the SPY as selected symbol
within the time period 1.1.2002 up to 31.12.2014 it seems to be ok.
Trades are generated and the performance is displayed by WL.

Using the time period 1.1.2003 up to 31.12.2014 (or any shorter time periode) no trades are generated within
the WL performance tabs..., they are only logged in the DEBUG and ERROR Log and not
send to WL.

What do I wrong ? I cannot find a configuration tab for the "Portfolio Balancing "- Sizer.



Addon: The trades, when displayed, are of size "1"....
I must have done something wrong here, but what ?
Normally this size should have been set within the possizer itself.


profile picture

mcfalwell

#4
leszek - can I hire you to make some changes to this for me?
profile picture

Eugene

#5
bishop asked in a duplicate thread:

Hi,

I am testing the aforementioned trading strategy and not sure if it works correctly.

I've created a watchlist of three symbols: AXP, BA, and CAT and assigned these symbols to each entrysymbol strings within the code and allocated 10% to each symbol.

In the Position Size window I've chosen Portfolio Rebalancing PosSizer.

When I run the strategy on the whole watchlist, I can see the following:

1. For some reason, some trades are not included due to insufficient capital (even with 2-to-1 margin)
2. The second symbol (which is BA in my case) returns an error: PosSizer error: symbol BA not found in the position information array.
3. The strategy places 2 or 3 trades on one bar every time it enters the position

Is it all by design? Or I am missing something?

Thank you.
profile picture

Eugene

#6
Hi,

I'm unable to reproduce neither one of your observations using Yahoo! EOD data (any data loading settings). There are no skipped trades, no error and the correct number number of entries (1). By the way, don't use the code above: it shouldn't work out of the box. I've just updated the Wiki page with a more actual Strategy code that takes into account the fact that leszek's PosSizer class was renamed when included in the MS123 PosSizers. Please rerun using updated code and see if it makes the error go away.

P.S.
QUOTE:
1. For some reason, some trades are not included due to insufficient capital (even with 2-to-1 margin)


2:1 margin is not really different from 1:1 margin. What makes difference is a small increase in the fractional part e.g. 1.03:1.
profile picture

bishop

#7
Eugene,

Sorry for duplicating. After you updated the code, I was able to rerun the strategy without any issues.

Thank you.
profile picture

Eugene

#8
Glad to have helped Vitaly.