Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Has anyone developed a framework for testing a sector rotation strategy?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Has anyone developed a framework for testing a sector rotation strategy?

    I've searched the forum for tips on building a market sector rotation strategy to use for backtesting, but have found no mention of it. Has anyone developed one who would be willing to share?

    By sector rotation strategy, in simplest terms I mean this:
    I have a portfolio of funds that represent various market sectors,
    on a periodic basis, I run some strategy that results in some kind of score for each fund in the portfolio.
    The funds are ranked based on the score and I sell the current portfolio and purchase the top X funds.
    I'm fairly new to NT and C# programming and would like to skip past reinventing the wheel of the basic concept and move on to implementing and testing strategies.

    Can anyone lend a hand? Thx

    #2
    I am not aware of any released publicly on the forums.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Trying to develop/backtest now

      I'm trying to develop and backtest this now. I'd like to develop a strategy that uses the Sector SPDRs and relative strength ranking of these ETFs. I am having some trouble wrapping my head around C# and position management in the NT platform.

      My strategy will be mostly based of Mike Carr's book "Smarter Investing in Any Economy: The Definitive Guide to Relative Strength Investing" . He backtested a sector rotation strategy that returned 23%/yr using the Fidelity Sector select funds. The strategy updated positions weekly--something much slower than what the typical NT operates at.

      I'd like to add my own rules to reduce drawdowns and use the SPDR etfs.

      Comment


        #4
        MidnightRider228,

        You would have to create an extensive multi-instrument strategy to achieve what you want. You can see some information on creating multi-instruments here: http://www.ninjatrader-support.com/H...ameInstruments

        Not that depending on your data provider you may be limited to the number of instruments you can run at the same time. Also note that each additional bar series you add will add to CPU/memory requirements. Adding hundreds of instruments is not recommended.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I'd only be using the 9 Sector ETFs:
          XLY XLP XLE XLF XLV XLI XLB XLK XLU

          I would hold the top 2 strongest ETFs, updated weekly. I'd only sell if the relative strength rank fell below a rank of 4.

          My main concern is backtesting and optimizing my custom relative strength indicator.

          I think I've got everything together as far as adding bars to the multi-instrument strategy. I'm having trouble with order entry, keeping track of what I'm already long and liquidating weak positions with each new weekly bar.

          Is this done with the Position Object?

          Right now I'm debugging with Yahoo data

          Comment


            #6
            You could track your positions through the IPosition objects, correct. Ultimately, you should be able to know your positions by simply holding onto your entry order IOrder objects though. Just don't reset these to null until after you have exited that position. While you hold that object, you are in that position and can check execution prices, etc.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Trouble with entering orders

              I'm still having some trouble with my order entry/exit. My strategy seems to be working, I've verified correct operation through print statements to the output window.

              It's a multi-instrument strategy that uses the following ETFs:
              XLY XLP XLE XLF XLV XLI XLB XLK XLU

              My algorithm calculates the relative strength on weekly basis. It then ranks these ETFs from 1-9. #1 is the strongest, #9 is the weakest. The number of positions that it holds is based on a runtime input. For instance, I can elect to hold 3 of the ETFs, and at the beginning of the backtest. I would then initially buy 3 funds. It sells positions when a ETF's RS rank falls below another runtime input and replaces it with the highest ranked etf that is not already owned for that week.

              My buy orders are executing (although with some qty problems), but the damn thing never sells until the last day of backtesting.

              It's a multi instrument strategy. I call it on the S&P Spyder ETF (SPY) in the strategy analyzer window and then add the bars for each ETF in the initialize method using Add("XLY"...).

              At the beginning of the strategy, I say

              if(BarsInProgress != 0)
              { return; }

              Then comes my strategy logic which I've verified to work with print statements.

              My problems come with EnterLong() and ExitLong(). There's an ATM overload for these methods that uses BarsInProgress. I submit my orders using the BarsInProgress variable for the ETFs I want to buy. I keep track of what I hold with an array of integers in the strategy that correspond to the bar's index in the BarsArray[] variable. When it's time to sell, I ExitLong() using the same overloaded version of the method.

              Do I need to submit buy/sell orders in the context of the calling bar? i.e. not do

              if(BarsInProgress != 0)
              { return; }

              at the beginning?

              Also what should EntriesPerDirection be set to when calling? What about the EntryHandling runtime variable?
              Last edited by MidnightRider228; 02-05-2010, 07:34 AM.

              Comment


                #8
                MidnightRider228, for debugging your order behavior TraceOrders are very helpful -



                Are you using unique entry signal names for those different ETF's? Then EntryHandling set to unique should do it -

                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by merzo, 06-25-2023, 02:19 AM
                10 responses
                823 views
                1 like
                Last Post NinjaTrader_ChristopherJ  
                Started by frankthearm, Today, 09:08 AM
                5 responses
                15 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                43 views
                0 likes
                Last Post jeronymite  
                Started by yertle, Today, 08:38 AM
                5 responses
                16 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by adeelshahzad, Today, 03:54 AM
                3 responses
                19 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Working...
                X