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

R squared

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

    R squared

    I am having difficulties trying to modify the R-squared indicator such that variable time is replaced with data points of my choice.

    The ultimate goal is to be able to perform an R-square calculation on two variables of my choice.

    The other option is to somehow incorporate the code below (from another source) into my program. I can do this but my limited programming skills can't figure out when, where and how to add in my variables.

    public static void LinearRegression(double[] xVals, double[] yVals,
    int inclusiveStart, int exclusiveEnd,
    out double rsquared, out double yintercept,
    out double slope)
    {
    Debug.Assert(xVals.Length == yVals.Length);
    double sumOfX = 0;
    double sumOfY = 0;
    double sumOfXSq = 0;
    double sumOfYSq = 0;
    double ssX = 0;
    double ssY = 0;
    double sumCodeviates = 0;
    double sCo = 0;
    double count = exclusiveEnd - inclusiveStart;

    for (int ctr = inclusiveStart; ctr < exclusiveEnd; ctr++)
    {
    double x = xVals[ctr];
    double y = yVals[ctr];
    sumCodeviates += x * y;
    sumOfX += x;
    sumOfY += y;
    sumOfXSq += x * x;
    sumOfYSq += y * y;
    }
    ssX = sumOfXSq - ((sumOfX * sumOfX) / count);
    ssY = sumOfYSq - ((sumOfY * sumOfY) / count);
    double RNumerator = (count * sumCodeviates) - (sumOfX * sumOfY);
    double RDenom = (count * sumOfXSq - (sumOfX * sumOfX))
    * (count * sumOfYSq - (sumOfY * sumOfY));
    sCo = sumCodeviates - ((sumOfX * sumOfY) / count);

    double meanX = sumOfX / count;
    double meanY = sumOfY / count;
    double dblR = RNumerator / Math.Sqrt(RDenom);
    rsquared = dblR * dblR;
    yintercept = meanY - ((sCo / ssX) * meanX);
    slope = sCo / ssX;
    }

    #2
    Hi,

    I'm not entirely sure which variable you're looking to replace.

    However if you'd like some public variables where you can choose as you start the indicator, please see our Reference Sample on User Defined Inputs for further information:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Originally posted by NinjaTrader_Matthew View Post
      Hi,

      I'm not entirely sure which variable you're looking to replace.

      However if you'd like some public variables where you can choose as you start the indicator, please see our Reference Sample on User Defined Inputs for further information:

      http://www.ninjatrader.com/support/f...ead.php?t=5782
      Hi was anyone able to do this? i'd like to be able to compare

      variable 1: trade logic; sma1 cross above sma2
      variable 2: price

      In other words, how well did a trade logic explain price. Similar to how in the strategy analyzer you can "optimize" for r2, I'd like to be able to know the r2 of a strategy everyday so I can change my weights of how much funds i'm allocating to that particular strategy.

      thanks

      Comment


        #4
        Hello calhawk01,

        Thank you for your post.

        I would use a strategy to determine this as the indicator's cannot take positions and therefore would not have a means to measure the efficiency of a condition. This means you would use SystemPerformance.AllTrades.TradesPerformance.RSqu ared: https://ninjatrader.com/support/help...s/rsquared.htm

        It seems you are discussing this with my colleague already at the following link: https://ninjatrader.com/support/foru...d.php?t=106469

        Please let me know if you have any questions.

        Comment


          #5
          Originally posted by NinjaTrader_PatrickH View Post
          Hello calhawk01,

          Thank you for your post.

          I would use a strategy to determine this as the indicator's cannot take positions and therefore would not have a means to measure the efficiency of a condition. This means you would use SystemPerformance.AllTrades.TradesPerformance.RSqu ared: https://ninjatrader.com/support/help...s/rsquared.htm

          It seems you are discussing this with my colleague already at the following link: https://ninjatrader.com/support/foru...d.php?t=106469

          Please let me know if you have any questions.
          Hi Pat, thanks for the response. You're right and that's what I'm doing now. Still waiting on your colleague to provide further details on strategy r2 logic.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Barry Milan, Today, 10:35 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by WeyldFalcon, 12-10-2020, 06:48 PM
          14 responses
          1,427 views
          0 likes
          Last Post Handclap0241  
          Started by DJ888, Yesterday, 06:09 PM
          2 responses
          9 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          40 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Today, 08:51 AM
          2 responses
          16 views
          0 likes
          Last Post bill2023  
          Working...
          X