public override double GetCovariance(TimeSeries series, DateTime datetime1, DateTime datetime2) { if (!(series is DoubleSeries)) { throw new ArgumentException("not a DoubleSeries"); } double mean1 = this.GetMean(); double mean2 = series.GetMean(); double n = 0.0; double sum = 0.0; int index1 = series.GetIndex(datetime1, EIndexOption.Next); int index2 = series.GetIndex(datetime2, EIndexOption.Prev); for (int i = index1; i <= index2; ++i) { DateTime dt = this.GetDateTime(i); if (series.Contains(dt)) { sum += (this[i] - mean1) * ((double)series[dt] - mean2); ++n; } } if (n <= 1.0) { return(0.0); } return(sum / (n - 1.0)); }
public ECross Crosses(TimeSeries series, DateTime datetime, int row = 0) { int index1 = this.GetIndex(datetime); int index2 = series.GetIndex(datetime); if (index1 <= 0 || index1 >= this.Count || index2 <= 0 || index2 >= series.Count) { return(ECross.None); } DateTime dt1 = this.GetDateTime(index1 - 1); DateTime dt2 = series.GetDateTime(index2 - 1); if (dt1 == dt2) { if (this[index1 - 1, row] <= series[index2 - 1, row] && this[index1, row] > series[index2, row]) { return(ECross.Above); } if (this[index1 - 1, row] >= series[index2 - 1, row] && this[index1, row] < series[index2, row]) { return(ECross.Below); } } else { double num1; double num2; if (dt1 < dt2) { DateTime dateTime3 = this.GetDateTime(index1 - 1); num1 = this[index1 - 1, row]; num2 = series.GetIndex(dateTime3, EIndexOption.Next) == index2 ? series[series.GetIndex(dateTime3, EIndexOption.Prev), row] : series[series.GetIndex(dateTime3, EIndexOption.Next), row]; } else { DateTime dateTime3 = series.GetDateTime(index2 - 1); num2 = series[index2 - 1, row]; num1 = this.GetIndex(dateTime3, EIndexOption.Next) == index1 ? this[this.GetIndex(dateTime3, EIndexOption.Prev), row] : this[this.GetIndex(dateTime3, EIndexOption.Next), row]; } if (num1 <= num2 && this[index1, row] > series[index2, row]) { return(ECross.Above); } if (num1 >= num2 && this[index1, row] < series[index2, row]) { return(ECross.Below); } } return(ECross.None); }
public ECross Crosses(TimeSeries series, DateTime datetime, int row = 0) { int index1 = this.GetIndex(datetime); int index2 = series.GetIndex(datetime); if (index1 <= 0 || index1 >= this.Count || index2 <= 0 || index2 >= series.Count) { return ECross.None; } DateTime dt1 = this.GetDateTime(index1 - 1); DateTime dt2 = series.GetDateTime(index2 - 1); if (dt1 == dt2) { if (this[index1-1, row] <= series[index2 - 1, row] && this[index1, row] > series[index2, row]) return ECross.Above; if (this[index1-1, row] >= series[index2 - 1, row] && this[index1, row] < series[index2, row]) return ECross.Below; } else { double num1; double num2; if (dt1 < dt2) { DateTime dateTime3 = this.GetDateTime(index1 - 1); num1 = this[index1 - 1, row]; num2 = series.GetIndex(dateTime3, EIndexOption.Next) == index2 ? series[series.GetIndex(dateTime3, EIndexOption.Prev), row] : series[series.GetIndex(dateTime3, EIndexOption.Next), row]; } else { DateTime dateTime3 = series.GetDateTime(index2 - 1); num2 = series[index2 - 1, row]; num1 = this.GetIndex(dateTime3, EIndexOption.Next) == index1 ? this[this.GetIndex(dateTime3, EIndexOption.Prev), row] : this[this.GetIndex(dateTime3, EIndexOption.Next), row]; } if (num1 <= num2 && this[index1, row] > series[index2, row]) return ECross.Above; if (num1 >= num2 && this[index1, row] < series[index2, row]) return ECross.Below; } return ECross.None; }
public override double GetCovariance(TimeSeries series, DateTime datetime1, DateTime datetime2) { if (!(series is DoubleSeries)) throw new ArgumentException("not a DoubleSeries"); double mean1 = this.GetMean(); double mean2 = series.GetMean(); double n = 0.0; double sum = 0.0; int index1 = series.GetIndex(datetime1, EIndexOption.Next); int index2 = series.GetIndex(datetime2, EIndexOption.Prev); for (int i = index1; i <= index2; ++i) { DateTime dt = this.GetDateTime(i); if (series.Contains(dt)) { sum += (this[i] - mean1) * ((double)series[dt] - mean2); ++n; } } if (n <= 1.0) return 0.0; return sum / (n - 1.0); }