Fidelity Select Sector Fund Rotation System
Author: bblidner
Creation Date: 4/13/2012 11:19 AM
profile picture

bblidner

#1
I'd appreciate help with getting Fidelity Select Sector Fund Rotation System to enable taking 3 positions.

I have recently downloaded this strategy via Wealth-Lab Pro and attempted to backtest the 40 funds identified in the strategy documentation using 3 positions by first setting the Strategy Parameters Box to "3 symbols", setting the scale to "Daily", setting the Data Range to "12/30/2000 - 3/31/2012", setting the Percent of Equity to "33.00%" and setting the Margin Factor to "1.05". Using these settings, the returned Backtest Result trades show that I buy and sell one symbol three times (33% x 3) rather than three separate symbols at 33% each.

I have searched this site and have found several references to enable trading more than symbol but have not been able to figure out how to correct this problem. I also called the help desk at Wealth-Lab: The help desk representative tried running the strategy and was only able to achieve the same backtest results that I achieved. The representative then contacted the "Engineers" and they also reported the same result, i.e., trades show buying and selling one symbol three time.

Would you please tell me what settings need to be used to enable taking 3 positions using this strategy.

Thank you for your help.

Bruce Blidner
profile picture

Eugene

#2
Bruce,

FYI, each strategy has its own discussion forum. For example, here's the proper place for discussing this particular uploaded strategy: Fidelity Select Sector Fund Rotation System

And this question was raised and answered:

more Symbols not working

This FAQ might also be helpful:

Wiki FAQ | Strategies and WealthScript > Rotation strategies
profile picture

bblidner

#3
Eugene,

Sorry - I've tried to check out/follow the referenced link, but the answer of what to do/how to correct the problem is not clear to me. Could you please modify this code so that it runs on three symbols.

Thanks,

Bruce Blidner

profile picture

Eugene

#4
You don't seem to have read my reply from 3/19/2011 6:32 PM thoroughly.
profile picture

bblidner

#5
Please be patient - I'm really a beginner at this coding/C# stuff. I've seen the reference

"The strategy parameter for number of symbols is inactive. It's simply a remnant of the prototype code, "RSI/Weak stock Rotation". Taking single symbol is hardcoded. It's in line with the strategy rules.

CODE:
Please log in to see this code.


but I don't know what to do with it. Could you please be more specific??

Thanks
profile picture

Eugene

#6
Bruce, I'm at a loss as to why are you quoting my reply partially, having skipped the part that contains suggestion what to do to modify the code? If you take the trouble of reading my reply to the end, I'm sure the proposed solution will be obvious to you:
QUOTE:
Is this possible to add this feature or which database vendor do I need that it rotate first in the sector ETF and afterwards it find the Top3 sectors and after then it finds the TOP 3 in the stocks of these sectors.

You could take the "Weak stock rotation code" and modify it according to the FAQ: I need other rotation rule other than the built-in RSI. Just modify the sorting order as suggested.
There's nothing I have to add to this. Essentially, the FAQ suggests a simple copy/paste job that I hope will be pretty easy to accomplish with your experience.
profile picture

jedi2wlp

#7
I'm running the Fidelity Select Sector Fund Rotation System with the Select Sector Funds. Using the strategy parameters sliders, I've chosen to pick the top 3. I've changed my Position Size to 33% and margin factor to 1.05:1. I ran it on the most recent 5 years. I clicked on FBIOX from my data set. It says 19 trades were not included due to insufficient simulated capital. So, i kept increasing my margin factor until all trades were included. I had to go all the way up to 1.4:1. So, my first question is "Why do I have to increase my margin factor so much to include all trades? In the summary it suggests using 1.05:1

Also, looking at the strategy equity curve, there are times when 1/3 or 2/3 of my portfolio is in cash. According to the WealthScript Programming Guide "Symbol Rotation strategies are those that seek to remain highly exposed to the market (fully or near-fully invested) by choosing the best candidates from a given DataSet of symbols." I would like to see the portfolio fully invested at all times. Is there a bug in the code, or is there a tweak to the code I can make to be fully invested at all times?

I also noticed that the first 3 trades take 3 days to execute. It buys FSPTX on 5/6/08, FBSOX on 5/7/08 and FNARX on 5/9/08. So, my last question is "Why doesn't it just buy all three on 5/6/08?"
profile picture

Eugene

#8
QUOTE:
So, my first question is "Why do I have to increase my margin factor so much to include all trades?


Because taking 3 positions at 33% is the same as taking 1 at 100% with regard to skipped trades. Trades are being skipped due to the gap between the basis price and the actual price. For more details please see the WL User Guide > 100% of Equity Sizing > "Basis Price".

Two PosSizers can help with this:

1. Spread Equity Equally is a PosSizer that spreads available equity (or cash) equally based on the variable number of Alerts (candidates) generated by the system, arriving at equal exposure. Set min = 30%, max = 33%, "Use: Cash", and all trades will be taken even with Margin 1:1.

2. A more general workaround: activate "Skipped trade solution" in the Position Options PosSizer (applies to AtMarket orders) to avoid skipping trades that otherwise could be taken.

QUOTE:
Also, looking at the strategy equity curve, there are times when 1/3 or 2/3 of my portfolio is in cash.


If you research for its original rules, this strategy was never meant to be rotating into more than a single fund. So, 1 symbol was hardcoded from the start, and even Revision A didn't fix it properly! To fix the remnant in the code, edit it like this:

CODE:
Please log in to see this code.


QUOTE:
"Why doesn't it just buy all three on 5/6/08?"


This quirk will be gone for good after fixing the code.
profile picture

jedi2wlp

#9
Thanks Eugene. Making the change to the 1 line of code was a huge help and it works much much better.

However, I'm still struggling a bit with the PosSizers.

For the Spread Equity Equally PosSizer, I was still getting 30-40% of my portfolio staying in cash. I'm still choosing 3 funds and choosing a min size of 30% and a max size of 33%. I'm using a portfolio of 1 million. The first trade was about 332K, the 2nd was 222K, and the third was 148K. So it appears that each trade only uses 30-33% of the remaining cash instead of 30-33% of the total portfolio. Is this working as designed or is this a bug?

For the Positions Options PosSizer, I made sure to click "Skipped Trade Solution" but was still getting 41 trades not included due to insufficient capital. I even tried checking the box "For last postion, use all what's left" and I still had 37 missed trades. So, I kept increasing the margin factor. Finally, after choosing 2:1, all the trades were included. The results on the equity curve look great. No idle cash.

Eugene, do you have any more tips on how to include all the trades without having to bump the margin factor to 2:1? The weird thing is that even though I chose 2:1, the most that was ever borrowed was about 35K (for a million dollar portfolio this would be equivalent to a 1.035:1 margin factor).

thanks,

Ryan

profile picture

Eugene

#10
QUOTE:
Is this working as designed or is this a bug?


By design: "Use Cash" is selected. Unfortunately, choosing "Use Equity" would not help arrive at maximizing exposure since the PosSizer is currently taking the basis price as is (see the User Guide > 100% of Equity Sizing > "Basis price" for details). Perhaps it would be pertinent to introduce a "Skipped trade solution" like in "Position Options" to this PosSizer, too.

QUOTE:
For the Positions Options PosSizer, I made sure to click "Skipped Trade Solution" but was still getting 41 trades not included due to insufficient capital.


"Skipped trade solution" imposes the use of AtMarket signals whereas this system trades with AtClose orders. It doesn't help in every case though.
profile picture

jedi2wlp

#11
I'm trying to use the "GetAllDataForSymbol" command in my code for the Fidelity Select Sector Fund Rotation System so that my equity curve line and buy and hold line start near the same bar. However, since the strategy is much more complex than the example code listed here, I'm struggling to get it to work properly. I'm not a programmer unfortunately.

Any help to get this to work properly would be greatly appreciated.

thanks,
Ryan
profile picture

Eugene

#12
Since the strategy's ROC period is short enough (25 days by default), the purpose of adding GetAllDataForSymbol is not obvious to me. Nevertheless, you could try the workaround from the QuickRef > Bars.Cache. The idea here is as follows:

1. While looping by all symbols of the DataSet, retrieve the "uncrippled" Bars object
2. Build a ROC using that data
3. Save that series with the Bars.Cache.

Paste this snippet on top of the "//Execute rotation strategy" comment (line 31) in the Strategy code:

CODE:
Please log in to see this code.


4. Then, replace this (unique) line 44...

holder.roc = ROC.Series(Bars.Close, Period)[bar];

with the following code:

CODE:
Please log in to see this code.


I think with the provided copy/paste instructions, the modification is so simple that an error is hardly possible.
profile picture

jedi2wlp

#13
Eugene,

Thanks for the assistance. The reason I'm trying to use the GetAllDataForSymbol is that I'm actually using a ROC period of up to 250 bars.. There's been some research done in Academia that a ROC over the past 1 year (but skipping the most recent month) has been a successful momentum strategy.
See link: http://faculty.chicagobooth.edu/tobias.moskowitz/research/papers/Value-and-Momentum-Everywhere.pdf


So, I did the copy and paste exactly as stated; however, I'm getting the following error:

"Runtime error: Index was out of range. Must be non-negative and less than the size of the collection.
at WealthLabStrategies.FSF_Rotation.Execute()
at System.Collections.Generic.List'1.get_Item(Int32index)

I see in the wiki where this error is discussed: http://www2.wealth-lab.com/WL5WIKI/kbErrorsStrategy.ashx
However, I'm still not sure exactly what is causing the problem in the code. I turned off the benchmark buy and hold in preferences but I'm still getting the error message. Any ideas?

My end goal is to build a momentum strategy that uses a ROC from 12 months ago to 1 month ago (so, an 11 month period). It would invest in 3-10 of the best performing sector or industry specific ETFs for 1 month (21 bars). At the end of 1 month, WLP would re-evaulate the ROC data and invest in the new 3-10 best performing ETFs for the next month. I would also like to see the equity curve and buy and hold curves start at the same time so I can easily see the performance of the strategy vs. SPY.
profile picture

Eugene

#14
Don't select "All data". Choose any other option e.g. "Fixed Bars".
profile picture

jedi2wlp

#15
I changed my data range to 11 years, and the strategy runs without errors. However, the buy and hold line is still starting 1 year before my equity curve line. Not sure what I'm doing wrong. I copied and pasted the code exactly like you had said.
profile picture

Eugene

#16
Change the start of the trading loop accordingly:

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

Eugene

#17
In a duplicate thread, dicknorth asked:

QUOTE:
Eugene created this strategy a while back-
Fidelity Select Sector Fund Rotation System [Rev.A]

What code would need to be added so that the
strategy would pick no fund(go to cash or a treasury)
if the SPY had
no increase in the last 6 months?

Thank you
profile picture

Eugene

#18
Actually, the strategy has been updated to [Rev.B] already. Here's my quick take at it. For simplicity's sake, I avoided changing scale to monthly and hardcoded the example as if the SPY had no increase in 120 (20 * 6) days:

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

Carova

#19
Hi Eugene!

Wouldn't it be more like this:
CODE:
Please log in to see this code.


Vince
profile picture

Eugene

#20
Vince,

CODE:
Please log in to see this code.


I like your line of thinking. The code won't trigger unless the close prices would match completely. Here's a tweak:

CODE:
Please log in to see this code.


profile picture

Eugene

#21
In another duplicate thread, dicknorth asked:

QUOTE:
Looking for a "simple" script that would at the end of the month
pick from the 9 Fidelity sector funds that did the
best over the last 6 months only if the SPY ETF was higher
than it was 6 months ago; else cash.

So only one pick a month- either in a fund for the next month
or in cash for the next month.


Some recent scripts on this rotation topic seem not to end up with the correct
picks- requesting only 1 (the best ROC)
fund and getting a message that x number were not traded due
to insufficient funds even with a low % capital to be invested selected (say 90%).

Thank you
profile picture

Eugene

#22
QUOTE:
pick from the 9 Fidelity sector funds that did the best over the last 6 months only if the SPY ETF was higher than it was 6 months ago; else cash.


Run this on Monthly data:

CODE:
Please log in to see this code.



QUOTE:
to insufficient funds even with a low % capital to be invested selected (say 90%).


This is offtopic here but I'll comment on this quickly. MS123 PosSizer Library includes Position Options PosSizer. Its "Skipped trade solution" may alleviate the problem for AtMarket orders by adjusting the basis price to the actual Open[bar+1].
profile picture

Cone

#23
Per this page there are now 11 Fidelity sector ETFs. Not much history here though.. these have only been alive about a year and a half.

This is about as easy as it gets...

1. Put the ETFs in a DataSet,
2. SPY should be contained in any other DataSet.
3. Choose Monthly bars
4. Click on any symbol except FREL (new symbol last month). Actually, just leave this symbol out of the test to avoid complications until it has been around for at least 2 months.

Due to the 6-month SPY requirement, the script starts trading on the 7th [monthly] bar.

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

dicknorth

#24
Thank you for the code- much appreciated.
Good results using the optimizer output against the 9 ishares xl* sector ETFs
when using monthly data (so easy to forget to change from daily!).
profile picture

reidhart

#25
I could not see how to add a post to the version C forum for this strategy (and the link in the first post response is dead), so adding it here.

I had some similar issues as the first couple of posts, most of which I think I resolved:

1. When multiple (3) symbols were selected in rotation, the same stock was bought multiple times, rather than the 3 selected by high ROC.
Fixed by removing "Break" in
CODE:
Please log in to see this code.

The multiple purchase may have been fixed with:
Set Position to "One trade per Symbol" with equity matched to the number of symbols to hold; however, with break, not sure all symbols would be tested for "buyPosition"
Did find that Set Position to "One trade per Symbol" with equity matched to the number of symbols to hold worked best.

2. The strategy was not staying fully invested, so moved the sell to Bar instead of Bar+1 so equity was available for all buys.
Perhaps there is another way to do this, so both sells and buys happen on Bar+1?


3. The current strategy looks at ROC every bar, rather than waiting for a rotation interval like most rotation strategies.
Implemented the Rotate/Hold/Days so that the rotation is reviewed on a regular interval

Revised code below:

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

Eugene

#26
Welcome to the forums Reid.

QUOTE:
1. When multiple (3) symbols were selected in rotation, the same stock was bought multiple times, rather than the 3 selected by high ROC.
...
The multiple purchase may have been fixed with:

1. This is not a bug and hence there's no need in a fix or workaround. Please review this FAQ | Strategies and WealthScript > A Rotation strategy isn't working like it should.


QUOTE:
2. The strategy was not staying fully invested, so moved the sell to Bar instead of Bar+1 so equity was available for all buys.

2. Again, this is not a fix for what is not the strategy's issue. A FAQ again: FAQ | Position Sizing, Extensions, Miscellaneous > I'm using 100% Equity position sizing and strategy doesn't seem to use all capital and/or there are trades not included due to insufficient capital.

Despite the FAQ saying '100%' this also applies to all the other situations when the combined % gets close to 100.


QUOTE:
3. The current strategy looks at ROC every bar, rather than waiting for a rotation interval like most rotation strategies.

3. The system is designed to be run on Weekly data. Have you tried switching it to Weekly scale?
profile picture

indydmax

#27
I was attempting to test this Select Strategy. Created the data set from the symbols provided. And I get this error.

Parameter name: providerInvariantName
Error processing symbol FSPHX Value cannot be null.
Parameter name: providerInvariantName
Error processing symbol FSPTX Value cannot be null.
Parameter name: providerInvariantName
Error processing symbol FSRBX Value cannot be null.
Parameter name: providerInvariantName
Error processing symbol FSRFX Value cannot be null.
Parameter name: providerInvariantName
Error processing symbol FSRPX Value cannot be null.
Parameter name: providerInvariantName
Error processing symbol FSTCX Value cannot be null.
Parameter name: providerInvariantName
Error processing symbol FSUTX Value cannot be null.
Parameter name: providerInvariantName
Error processing symbol FSVLX Value cannot be null.
Parameter name: providerInvariantName
profile picture

Eugene

#28
Check out this page, scroll down to where it says "Runtime error: Value cannot be null":

Errors | Strategy > Strategy compiles but produces a specific runtime error...
profile picture

indydmax

#29
What I found is below. I checked the preferences.
QUOTE:
2. Another possibility is that you have checked "Benchmark Buy & Hold" in Wealth-Lab's Preferences (F12) > Backtest Settings. Disable that option.

That wasn't the issue.
QUOTE:
1. It can happen when creating a Strategy that makes a request to an external symbol and uses multiple timeframes.

I'm not explicitly calling GetExternalSymbol but maybe one of the other functions does.
profile picture

Eugene

#30
Okay, the let's discard "Benchmark Buy & Hold". The idea behind the other suggestion is that you may be trying to apply the system on unsuitable time frame e.g. intraday or compressed scale. And make sure the DataSet has been updated.

But anyway, you are not running the Strategy correctly. This is a Rotation strategy and it should be executed in single-symbol mode. The error messages you're getting indicate it's run in Multi-Symbol Backtest mode.
profile picture

indydmax

#31
Ah. So, this strategy can not be backtested?
profile picture

Eugene

#32
It absolutely can be backtested. Rotational Strategies are special in that they do the looping by symbol on their own, and running them in "portfolio backtest" mode just breaks them. See the FAQ | Strategies and WealthScript > A Rotation strategy isn't working like it should.

And it's very important to not have any empty symbols in your DataSet for this Strategy to run. Eliminate all inactive fund symbols if there are any symbols with 0 bars (Data Manager > highlight the DataSet > click "Symbol details", then sort by bar count), click on the first symbol (or the one with the largest history available), and it should work like a charm.
profile picture

indydmax

#33
Problem solved. One of the symbols from the original list was no longer valid. Removed it and it solved the problem. FSCGX.

THANKS!!!!
profile picture

Eugene

#34
Glad to help you!
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).