Use/Nonuse of SetOption("WorstRankHeld", 1) and Subsequent Impact

Hello,

I've created a formula that uses the backtestmode(backtestRotational), with the purpose of being long the S&P 500 select SPDR sector ETF (there are 11 total sector etfs - xlb, xlc, etc.) with the highest Linear Regression Slope ( a simple relative strength model). As a result, over the time horizon selected, the portfolio is long only one etf with the highest rank. I've done so with the following two methods:

Method 1

SetBacktestMode( backtestRotational);
SetOption("InitialEquity", 100000);
SetOption("MinShares", 1);
SetOption("AllowPositionShrinking", True);
SetOption("MaxOpenPositions", 1); 
SetOption("WorstRankHeld",1);
SetPositionSize(100, spsPercentOfEquity);
A = Optimize("LRS Length", 110, 10, 300, 10);
PositionScore = 100000 + LinRegSlope( C, A );

Method 2 

SetBacktestMode( backtestRotational);
SetOption("InitialEquity", 100000);
SetOption("MinShares", 1);
SetOption("AllowPositionShrinking", True);
SetOption("MaxOpenPositions", 1);
SetPositionSize(100, spsPercentOfEquity);
A = Optimize("LRS Length", 110, 10, 300, 10);
PositionScore = 100000 + LinRegSlope( C, A );


The only difference between these two methods is that Method 1 has the additional line:
SetOption("WorstRankHeld",1);

My thoughts are that this line is actually not needed since SetOption("MaxOpenPositions", 1) is present in each methodology.  I also thought that results for these two methods would therefore be identical.  When tested, both methods are long only one ETF at a time. 

Interestingly, I get meaningfully different results between the two methods. When I include the line SetOption("WorstRankHeld, 1), the number of trades went up quite a lot and obviously the results are different. 

Why is that? 

In the method without the line SetOption("WorstRankHeld", 1), how does the system decide when to exit the existing long position and enter a new long position in a different etf? 

Thanks

@vplack

Welcome to the forum.

Please be aware that you are required to be "Verified" to post questions.

Please search for "Verified" or "Verified Badge" and follow the steps to get verified - only takes a few minutes.

When you get verified, you may want to post the code and comments again to make it easier to read.

@vplack,
Welcome to the forum.
Please fix your code tags. Method 2 is showing in forum text and your explanation/questions are enclosed in code tags - making it difficult to read.

@vplack,
When I have "Why" questions I go to the debugger so that I can follow along and see what is happening inside my code.
AFL Visual Debugger
Give it a go.

Thanks ghanson. I'm a first time user and sorry about that. Let me try this again.

I've created a formula that uses the backtestmode(backtestRotational), with the purpose of being long one S&P 500 select SPDR sector ETF (there are 11 total sector etfs - xlb, xlc, etc.) with the highest Linear Regression Slope ( a simple relative strength model). As a result, over the time horizon selected, the portfolio is long only one etf with the highest rank. I've done so with the following two methods:

Method 1

SetBacktestMode( backtestRotational);
SetOption("InitialEquity", 100000);
SetOption("MinShares", 1);
SetOption("AllowPositionShrinking", True);
SetOption("MaxOpenPositions", 1); 
SetOption("WorstRankHeld",1);
SetPositionSize(100, spsPercentOfEquity);
A = Optimize("LRS Length", 110, 10, 300, 10);
PositionScore = 100000 + LinRegSlope( C, A );


Method 2

SetBacktestMode( backtestRotational);
SetOption("InitialEquity", 100000);
SetOption("MinShares", 1);
SetOption("AllowPositionShrinking", True);
SetOption("MaxOpenPositions", 1);
SetPositionSize(100, spsPercentOfEquity);
A = Optimize("LRS Length", 110, 10, 300, 10);
PositionScore = 100000 + LinRegSlope( C, A );

The only difference between these two methods is that Method 1 has the additional line:

SetOption("WorstRankHeld",1);

My thoughts are that this line is actually not needed since SetOption("MaxOpenPositions", 1) is present in each methodology.
I also thought that results for these two methods would therefore be identical.
While both methods are long only one ETF at a time, I get meaningfully different results between the two methods.
When I include the line SetOption("WorstRankHeld, 1), the number of trades went up quite a lot and obviously the results are different.

Why is that?

In the method without the line SetOption("WorstRankHeld", 1), how does the system decide when to exit the existing long position and enter a new long position in a different etf?

Thanks for any help/guidance.

@ghanson

Thank you for the debugger idea. I will check it out.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.