using System; using System.Collections.Generic; using TSLab.Script; using TSLab.Script.Handlers; using TSLab.Script.Helpers; namespace RSquared_ { public class RSquared : IDouble2DoubleHandler { [HandlerParameter(true, "9", Min = "5", Max = "100", Step = "1")] public int RSQPeriod { get; set; } public IList Execute(IList source) { var P = source; var rsq1 = new double[P.Count]; for(int i = 0; i < P.Count; i++) { if(i=i-RSQPeriod ; j--) { x = ind; // x axis value y = P[j]; // y axis value Ex += x; Ey += y; Exy += x*y; Ex2 += Math.Pow(x,2); Ey2 += Math.Pow(y,2); ind++; } Ex22=Math.Pow(Ex,2); Ey22=Math.Pow(Ey,2); //slope = (per*Exy-Ex*Ey) / (per*Ex2-Ex22); // slope of regression line //b = (Ey-slope*Ex)/per; div = Math.Sqrt((RSQPeriod*Ex2-Ex22)*(RSQPeriod*Ey2-Ey22)); if(div==0) rsq1[i]=0; else { r = (RSQPeriod*Exy-Ex*Ey) / div; rsq1[i]=Math.Pow(r,2); } } } return rsq1; } } }