private static TimeSeries OpTwoTimeSeries(TimeSeries ts1, TimeSeries ts2, string name, Func <double, double, double> op, bool checkZero = false) { var ts = new TimeSeries(name, "", -1); for (int i = 0; i < ts1.Count; ++i) { var datetime = ts1.GetDateTime(i); if (ts2.Contains(datetime)) { var d2 = ts2[datetime, SearchOption.ExactFirst]; if (!checkZero || d2 != 0.0) { ts.Add(datetime, op(ts1[datetime, 0, SearchOption.ExactFirst], d2)); } } } return(ts); }
public double GetCovariance(TimeSeries series) { EnsureNotNull(series); var m1 = GetMean(); var m2 = series.GetMean(); int count = 0; double sum = 0; for (int i = 0; i < Count; ++i) { var dateTime = GetDateTime(i); if (series.Contains(dateTime)) { sum += (this[i] - m1) * (series[dateTime, SearchOption.ExactFirst] - m2); ++count; } } return(count <= 1 ? 0 : sum / (count - 1)); }
private static TimeSeries OpTwoTimeSeries(TimeSeries ts1, TimeSeries ts2, string name, Func<double, double, double> op, bool checkZero = false) { var ts = new TimeSeries(name, "", -1); for (int i = 0; i < ts1.Count; ++i) { var datetime = ts1.GetDateTime(i); if (ts2.Contains(datetime)) { var d2 = ts2[datetime, SearchOption.ExactFirst]; if (!checkZero || d2 != 0.0) ts.Add(datetime, op(ts1[datetime, 0, SearchOption.ExactFirst], d2)); } } return ts; }
public double GetCovariance(TimeSeries series) { EnsureNotNull(series); var m1 = GetMean(); var m2 = series.GetMean(); int count = 0; double sum = 0; for (int i = 0; i < Count; ++i) { var dateTime = GetDateTime(i); if (series.Contains(dateTime)) { sum += (this[i] - m1) * (series[dateTime, SearchOption.ExactFirst] - m2); ++count; } } return count <= 1 ? 0 : sum / (count - 1); }