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

Days till Expiration within a Futures Backtester

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

    Days till Expiration within a Futures Backtester

    Hi all,

    Re VIX future.

    I need to know the days till expiration of each futures contract within a backtester. Currently, I can get the days until roll for the current moment future. However, I need the exact days until expiration for each future.

    Under Market Data -> Global Merge Policy, I have 'Merge Back Adjusted'

    ----------------------------------------------------------------------------------

    Print(Time[0] + " " + this.Instrument.MasterInstrument.GetNextRolloverDa te(DateTime.Now).Subtract(Time[0]).TotalDays + " Days till Roll");

    The above gives me the current-most future's Roll Date but does not seem to properly roll for farther back futures. For example, the backtester automatically rolls the "ES 09-20" contract for a 3 year lookback for a backtester such that, in say July of 2019, the backtester is 'trading' the Sep 19 contract, not today's front contract which is Sep 20. (Even though I type in "ES 09-20" for the Instrument in Strategy Analyzer. Am I understanding this correctly?)

    But when I print the above Print row in a larger backtester, it only gives me the number of days until the current front contract. For example, if I use "ES 09-20" as the backtested product and a 12 month historical window, the above printed row for 01/06/2020 12:00:00 PM says there are 247 days till expiration. This is the number of days until the "ES 09-20" expires which is NOT what the backtester is actually trading on 01/06/2020. On 01/06/2020 it is trading I think "ES 03-20" and so within the backtester on 01/06/2020 I need the number of days till expiration for the then front contract, "ES 03-20".

    So the above is as close as I have gotten. I need days till expiration for the front contract for each point in the backtester.

    Thoughts?

    Thanks,
    Tim
    Last edited by ozziyhtomit; 07-16-2020, 03:10 PM.

    #2
    Hello ozziyhtomit,

    The RolloverIndicators gets the next contract month and from this you can get the date. Then subtract that date from today's date to see how many days it will be.
    Shows a button on the chart to roll the expiry to the next available contract month. Option to hide button until a number of days before or on roll date. Another option to confirm by opening the instrument overlay selector or automatically rollover without confirmation. (Update June 27th, 2019 – Added an option to show […]
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Sorry should have been more clear.

      1. Trying to get this data within a strategy file, not on a chart.

      2. I am trying to get expiration dates - not roll dates. These two dates are different for almost all futures. (I posted my Print row example to show my progress, but I am not actually looking for roll date.)

      3. I need it to correctly work within a backtester. IE I need the date of expiration to essentially roll as the future rolls within the backtester. Does this make sense? So for a 1 year back VIX backtester, on historical date 07/01/2020 I need to programmatically obtain date 07/22/2020 since on date 07/01/2020 the then-front contract is the July contract and 07/22/2020 is that future's expiration date. But on date 01/01/2020 in the backtester, I need to programmatically obtain 01/22/2020 since on date 01/01/2020 the then-front contract is the January contract and that future's expiration date is 01/22/2020.



      Thanks again!




      Last edited by ozziyhtomit; 07-16-2020, 03:45 PM. Reason: Clarifying sentence

      Comment


        #4
        Alternatively,

        If I can import a csv file directly into a Strategies file (a csv read) once upon starting, I can import the expiration dates myself. I am not looking to import it for a chart or via the import functionality of NT. I just want to be able to obtain the exact expiration dates for a futures contract, which the below website already gives me.



        Thank you,
        Tim


        Comment


          #5
          Hello ozziyhtomit,

          I'm suggesting that you copy the code from the RolloverIndications indicator into your coded Strategy.

          Unfortunately, the rollover dates in the Instrument editor are the only dates associated with an instrument in NinjaTrader.

          If you want to use something other than those dates, you would need to custom design a way to read the dates you want. You could choose to have a text file with those dates and read from text file.

          This would be the same in historical data as real-time data.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Doh - sorry I was a little slow on that.

            OK thank you re the text file idea. I'll dig into that.

            Thank you Chelsea

            Comment


              #7
              Got er done thanks Chelsea!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              26 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 02-22-2024, 01:11 AM
              5 responses
              32 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, Yesterday, 09:53 PM
              2 responses
              49 views
              0 likes
              Last Post wzgy0920  
              Started by Kensonprib, 04-28-2021, 10:11 AM
              5 responses
              192 views
              0 likes
              Last Post Hasadafa  
              Started by GussJ, 03-04-2020, 03:11 PM
              11 responses
              3,234 views
              0 likes
              Last Post xiinteractive  
              Working...
              X