December 21, 2021 at 6:31 am #66969
I would like to test a relative strength strategy using the GICS level 1 sectors. The idea is:
1) Get the 126-day ROC for each sector.
2) Buy the sectors with the top 3 ROC values.
How do I get from my script that calculates the ROC values to an entry criteria script that chooses the top 3 values? My best guess is some form of an If statement?12345678910111213141516//1) Get the 126-day ROCV1 = ISTICKER(CODE=XLF:US, ROC(BARS=126)) ;V2 = ISTICKER(CODE=XLC:US, ROC(BARS=126)) ;V3 = ISTICKER(CODE=XLY:US, ROC(BARS=126)) ;V4 = ISTICKER(CODE=XLP:US, ROC(BARS=126)) ;V5 = ISTICKER(CODE=XLV:US, ROC(BARS=126)) ;V6 = ISTICKER(CODE=XLI:US, ROC(BARS=126)) ;V7 = ISTICKER(CODE=XLB:US, ROC(BARS=126)) ;V8 = ISTICKER(CODE=XLK:US, ROC(BARS=126)) ;V9 = ISTICKER(CODE=XLRE:US, ROC(BARS=126)) ;V10 = ISTICKER(CODE=XLU:US, ROC(BARS=126)) ;V11 = ISTICKER(CODE=XLE:US, ROC(BARS=126)) ;//2) Buy the top 3 valuesIF()
thank youDecember 21, 2021 at 9:27 am #66973
I wouldn’t do this as a script, i’d setup a Rebalance Back Test, where the Filter was something all codes would pass (Close() > 0 for example) and the Ranking was the 126ROC value.
You can then run the back test over the GICS Level 1 Sectors, and set the Max Positions to 3 and % per trade as 33.33%. You can rebalance the positions as often as you wish (Weeky / Monthly, etc).
More information here: https://help.optuma.com/kb/faq.php?id=1022December 21, 2021 at 10:53 am #66977
Thank you. Your instructions were clear and your link was very helpful. I am happy with my results as a starting point. I would like to improve them with a filter. The example given in your link is using a moving average on an index. What if I want to do this same filter except on the open positions instead of a benchmark index? Is that possible?December 21, 2021 at 1:25 pm #66983
If you mean the script where the close is greater than a 50MA, you would remove the XJO Getdata() line and use only the MA reference.123CLOSE() > MA(BARS=50)
This filter will be applied to the sectors being scanned, rather than a specific index.December 21, 2021 at 3:16 pm #66985
Thank you. I am sorry I didn’t ask my question clearly. The filter is a filter for entry at each rebalance. I want to add an exit criteria in order to reduce the average loss. I want to get out of a position in some cases before the rebalance. Is this possible? Thank you.December 21, 2021 at 3:42 pm #66987
I believe if you change the Rebalance Positions to “On Signal” the filter script should be the trigger for the rebalance to occur.December 21, 2021 at 4:01 pm #66989
Yes, switching back to the signals test type allows to script an exit, but removes the ranking which was my initial issue. I was trying to set this up as much as I could without you, but I am stuck. Below is exactly what I am trying to test. Perhaps this will help you to guide me to the best solution.
Sector Relative Strength Portfolio Test
Initial Entry: 01/01/1999
· Rank the 11 sectors using a 126 day ROC.
· Buy the top 3 with an equal dollar amount.
Rebalance 21 or 63 days later:
· Rank the 11 sectors using a 126 day ROC.
· Stay long the sector if the rank is a top 3.
· Exit the sector if it is not in the top 3.
· Buy any sector in the top 3 that is not currently owned.
· Exit a sector if the 5-day simple crosses below the 200-day simple or if there is a -30% drawdown from the high.
· Re-enter if the 5-day simple crosses above the 200-day simple
thank youDecember 22, 2021 at 11:49 am #66994
I did not mean changing the whole backtest back to Signals, my meaning was to set the Rebalance Positions property only to On Signal…December 22, 2021 at 12:39 pm #66995
Thank you for clearing that up. I appreciate you helping me get comfortable using the Back Tester. I am not sure that setting the rebalance positions property to on signal is exactly what I am trying to test. I believe setting the rebalance positions property to on signal stops the monthly rebalance and only rebalances based on the filter.
What I really want to test is a monthly rebalance, but also have the flexibility to exit before a monthly rebalance if the filter triggers false and re-enter if the filter triggers true again. Is this possible to maintain a monthly rebalance and have additional exits and entries based on the filter or some other way to program this?
Just for your information, the script I have for the criteria just asks if the benchmark index has its 3 day moving average above its 200 day moving average.123456D1 = GETDATA(CODE=SPY:US) ;MA1 = MA(D1, CALC=Close, BARS=3) ;MA2 = MA(D1, BARS=200, CALC=Close) ;MA1 > MA2
December 22, 2021 at 1:05 pm #66998
- This reply was modified 7 months ago by Louis Spector.
No, not at this time. The rebalance can either be based on a set time, or based on a scripted trigger.
The closest you would be able to get, would be to setup two scripts, one for MA cross script, another that triggers when a new month rolls over. The rebalance would occur anytime either of those two scripts triggered.
We are working on updating the testing module overall, which should allow greater flexibility in the future.December 22, 2021 at 3:01 pm #66999
That’s great news and an interesting idea. I didn’t find anything in the forums regarding scripting a monthly trigger. How would I accomplish that? Thank you.December 22, 2021 at 3:42 pm #67000
This script would trigger each time a new month started (1st Trading Day of the month):1234567//Find Month NumbersV1 = MONTHNUM();//Find Changes in MonthV2 = V1 > V1 or V1 < V1;V2January 11, 2022 at 12:25 pm #67199
Awesome!!! Thank you.
- You must be logged in to reply to this topic.