Longer-Term Strategy to Buy Pullbacks, Corrections, and Bear Markets
Author: glenpbrockIII
Creation Date: 4/8/2015 1:59 PM
profile picture

glenpbrockIII

#1
I am Fidelity customer that historically has not traded frequently in the recent past. I am, however, interested in strategy (as opposed to mere buy and hold), but have never programmed a strategy, and am having trouble.

I propose to test my strategy using S&P500 daily data from 1975 to the present. The overarching strategy would be based on investing 70% of an initial sum on a "buy and hold basis". Other percentages of the initial sum would be managed using the following rules:

>> 10% of the initial amount: Buy when the S&P500 is 10% below its most recent high; sell when the S&P500 increases 100% (i.e., doubles) from its next new all-time high (realizing this could be a long time).
>> 10% of the initial amount: Buy when the S&P500 is 20% below its most recent high; sell when the S&P500 increases 50% from its next new all-time high (again, could be held for a while, except in the 1990s).
>> 10% of the initial amount: Buy when the S&P is 30% below its most recent high; sell when the S&P500 reaches its next new all-time high.
>> 25% of the initial amount (an amount initially equally to this) using margin: Buy when the S&P500 is 50% below its most recent high; sell when the S&P500 reaches its next new all time high.

Amounts in the 4 ">>" categories above would go into cash when not invested in the S&P500 (and I would be OK assuming a 0% return on cash).

It seems like it would be easiest to break the backtesting into four streams, and then I could manually combine them (taking account manually of the loss of opportunity to reinvest dividends during the times when the various portions were in cash, as well as the interest charged to use margin). I say it would be easier because it's easier for me to conceptualize how each "stream" would accumulate or decrease in value as buys/sells occur, and no "rebalancing" of the percentages would be necessary.

Does anyone know if the Wealth Lab software can do this backtesing? I have version 6.8 of Wealth Lab Pro, and can get the data from Fidelity. I spent a few hours searching for an existing strategy without success, and then copied the following code from the "Dip Buyer" strategy:

...

I think it might be able to be modified to do four simulations and (with some manual calcs. by me based on the charts/data generated by the backtesting), I could determine whether this strategy would have beaten buy-and-hold for the S&P over a 30-year period.

Can anyone help me with the basic modifications I would need to program my strategy? I am shamelessly asking because I simply don't think I can do it myself. If I got the basic programming, and the strategy seemed to hold theoretical promise, I could tinker with the entry and exit percentages above, but essentially I can't figure out how to use old highs and new highs as the basis for the triggers.

Help would be greatly appreciated if anyone has time.

Glen
profile picture

Cone

#2
QUOTE:
I propose to test my strategy using S&P500 daily data from 1975 to the present.
No harm in this, but the S&P 500 has changed a LOT in 40 years, so keep in mind that you'll be working only with "survivors", i.e. survivorship bias. Fidelity data, however, only goes back to 1992. For more data, including delisted stocks, check out http://premiumdata.net/

QUOTE:
taking account manually of the loss of opportunity to reinvest dividends during the times when the various portions were in cash, as well as the interest charged to use margin)
Not necessary. You can automatically apply dividends when they are paid and you can set a fixed amount of margin and interest in Preferences (F12) > Backtest Settings

QUOTE:
Does anyone know if the Wealth Lab software can do this backtesing
The only real limit to WLP backtesting is one's ability to program their strategy.

We can help with the Strategy, but the 70% and 10% allocations are not clear to me. Is the idea to buy equal portions of every stock in the DataSet while triggering on the movements of the S&P 500 index?
profile picture

Eugene

#3
QUOTE:
It seems like it would be easiest to break the backtesting into four streams, and then I could manually combine them

The Strategy can be programmed to handle all the four rules. Or, each rule can be made into a separate Strategy and then combined via the Combination Strategy wizard - which is the convenient instrument for building "portfolios of systems" interactively (btw, where each system can be made run on an individual DataSet).

The Combo Strategy way may be also preferred here because of user's simplicity in controlling the allocations: otherwise it would take selecting a PosSizer to do the position sizing.
profile picture

glenpbrockIII

#4
Good point about the survivorship bias. I still want to do the backtest, but that is good context. And i didn't realize that Fidelity could only provide data back to 1992.

Wow -- this software is great! It's wonderful that dividend yield and interest charges to use margin can be handled and that the four rules can be integrated. I just don't know the commands well enough so could really use some help implementing.

i didn't think about the weighting -- excellent point. My idea was that the 70%/10% allocations would all be used to purchase a basket of all the then-current S&P component stocks, just as if an index fund like SPY was acquiring shares. However, i see the problem wiht that now because the S&P index (and SPY) is market cap. weighted -- i don't know how that could work. I'd still get a lot of use out of the backtesing if i used one symbol (SPY), and limited the backtesting to the inception date of SPY (Jan 22, 1993). That's still 22 years of data, including the last half of the big Bull Market of last century, and the dot-com bubble and 2008 financial crisis. Limiting the period would also solve the problem with using Fidelity data. Can the sofware backtest an ETF like SPY?

So, the only difference between the 70% and the other four rules is the timing of the buys (and the existence of the sells in the 10%/10%/10%/25% (margin) rules. The 70% would be invested in SPY (a market-weighted basket of the S&P stocks), and stay there, with dividends reinvested. The other four components (the 10/10/10, and the 25% margin piece) would consist of buying SPY and selling SPY according to the rules. Dividends would only reinvest when those portions were in stock and not cash, and the 25% margin holding would get charged interest for the use of margin. Would that be able to be done?
profile picture

Eugene

#5
QUOTE:
Can the sofware backtest an ETF like SPY?

Yes. Here's version to be run on SPY. The "recent high" is set to 252 days which you can adjust to your taste with the parameter slider:

CODE:
Please log in to see this code.


For the proper allocations according to your position sizing rules, you'll need Position Priority PosSizer. It's part of MS123 PosSizer Library. Don't forget to restart WLP after installing the extension. Here's how the PosSizer can be set up:



Note: Installation of extensions requires verification of your WLP entitlement. For instructions, please create a support ticket.
profile picture

glenpbrockIII

#6
Will do. Thanks so much for all the help - I really appreciate it!
profile picture

glenpbrockIII

#7
I've downloaded the Position Priority PosSizer. and have all the code in the Editor section of the strategy, but I can't figure out how to get the PosSizer Settings box to allow me to enter the settings above. How do I get the dialog box open in the strategy to enter the values?
Any help would be greatly appreciated -- thanks.
profile picture

Eugene

#8
Please refer to the User Guide to quickly answer such questions (Reference > Data Panel). There's Data panel on the left with Position Size dropdown. Firstly, click the down arrow to open it, then select "Position Priority" in the PosSizer dropdown, then click "Configure".

profile picture

glenpbrockIII

#9
Thanks. I will study the users guide more closely to try to become more self-suffcient. Thanks for all the help!
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).