Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT7 "Beta" Indicator

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

    NT7 "Beta" Indicator

    Here's an indicator which calculates the "Beta" of an instrument, relative to a secondary instrument.

    Typically, Beta is calculated based on monthly returns, so if you use monthly bars and a 36-month period, and calculate against the S&P500 index, the result should agree with commonly-quoted sources such as Yahoo Finance.

    You could also use other periods, lookbacks, or secondary instruments if you wish.

    With this, and all multi-instrument indicators, currently you must add the secondary data series to the chart before applying the indicator. There are currently bugs in NT7 which will cause problems if an indicator refers to instrument data series which are not displayed on the chart.

    The indicator's "Symbol2" parameter defaults to the secondary instrument displayed on the chart, so you don't need to enter the symbol again.

    Update 4/7/10: Please see the Indicators area for an updated version:
    http://www.ninjatrader-support2.com/...d=1&linkid=290
    Attached Files
    Last edited by kdoren; 04-07-2010, 03:45 AM. Reason: Removed Beta.zip file, please see Indicators area for updated version

    #2
    I get it to plot OK with stocks (tried C, AA, GE) but with ETFs as the primary instrument there is no data for Beta (tried EEM, SPY) even though they plot fine in window 1.

    Comment


      #3
      The only thing I can think of is that I mistakenly set the default value for "CalculateOnBarClose" to be false, which would make it recalc on every tick. That's arguably what you want for a Ratio or Spread indicator, where you want to see the changes in real time, but it's definitely not what you want for something like Beta, which is more compute-intensive and you don't need it in real time. Some ETFs have very high tick volumes, so that could be causing a problem during trading hours.

      I replaced the file Beta.zip in my original post with one that has the default set to CalculateOnBarClose=true, so you can re-download it and try it; you can also just change the setting in indicator properties but you'll have to remember to do it every time.

      Other than tick volume I can't think of any reason for any difference between ETFs and stocks, they're all just symbols to NT.

      Comment


        #4
        I've posted an updated "Beta" indicator in the Indicators area:

        http://www.ninjatrader-support2.com/...d=1&linkid=290

        Comment


          #5
          Thanks Kevin,

          That is very handy. You now have me thinking about how to use it to dynamically calculate beta-weighted deltas of a known portfolio...

          A loaded question... but do you think the extra sync code for multi-instrument is still necessary?

          Comment


            #6
            I believe that synchronization code is necessary, or I wouldn't have gone through the pain of writing it.

            Here are the kinds of problems it protects against:

            Lookbacks across missing bars: indicators such as Correlation or Beta only make sense if the bars are time-synchronized. If a bar is missing, Closes[0][x] and Closes[1][x] will refer to different times, and the indicator results are simply wrong - it makes no sense to compare Wednesday's ES data with Tuesday's TF data. This is not a theoretical problem: daily bars for TF have data for holidays, while ES bars do not. If you try to make a correlation calculation for ES and TF using daily bars, the results will be wrong if the period includes a holiday.

            With smaller timeframes, missing bars can and do happen even with major instruments, due to light volume, data feed issues, late openings, or trading halts.

            You could cross your fingers and ignore the problem, and believe me that is what I would have liked to do, but what is the point of putting a lot of effort into system development if you can't trust the results (good or bad). You could be steered away from a good approach, or toward a bad one, without knowing it.

            Real-Time sync errors: NT7 synchronizes historical bars, if possible, meaning that when OnBarUpdate is called, Closes[0][0] and Closes[1][0] will refer to the same time (assuming neither bar is missing). Not so in real time; NT7 will call OnBarUpdate when it gets the first tick of the next bar; one bar will close before the other, and Closes[0][0] and Closes[1][0] can and will refer to different times. If CalculateOnBarClose == true, a Spread or Ratio indicator would sometimes use 1-bar-old data for one of the instruments, unless special precautions were taken.

            I tried a number of ad-hoc methods, but in the end I decided the best thing I could do was to make a "SyncedDataSeries" subclass of DataSeries, and bury the synchronization complexity inside. It's way overkill if all you want is to calculate Beta for 36 monthly bars, but it generalizes fairly well and results in fairly clean main-body code. I had to build mathematical routines that skip over missing bars, but that's easy to code and debug compared with dealing with synchronization problems.

            For me, I just couldn't see the sense in building multi-instrument systems that trade real money, if I had to worry that the underlying code might sometimes produce erroneous results.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            601 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            347 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            559 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            558 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X