public static object acq_count_unique(object[,] x, [ExcelArgument(Description = "Optional flag if TRUE (default) ignores differences between error codes")] object ignore_error_codes) { object result = ExcelError.ExcelErrorNA; if (x == null) { result = ExcelError.ExcelErrorNA; } else { int n = x.GetLength(0); int m = x.GetLength(1); if (n > 0 && m > 0) { bool ignore_errors = ExcelHelper.CheckValue <bool>(ignore_error_codes, true); HashSet <string> unique_values = new HashSet <string>(); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { unique_values.Add(Excel_ToString(x[i, j], ignore_errors)); } } result = unique_values.Count; } } return(result); }
public static object acq_mean( [ExcelArgument(Description = "Array")] object x, [ExcelArgument(Description = "Array of Weights [optional]")] object w, [ExcelArgument(Description = "Ignore NA flag [optional] (default: false)")] object ignore_na) { double[] x_input = ExcelHelper.CheckArray <double>(x); //TODO: we need to check that correspondance between x and w is preserved double[] w_input = ExcelHelper.CheckArray <double>(w); bool na_rm = ExcelHelper.CheckValue <bool>(ignore_na, false); double result = ACQ.Math.Stats.Utils.WeightedMean(x_input, w_input, na_rm); return(ExcelHelper.CheckNan(result)); }
public static DateTime acq_adjustbusinessday(DateTime date, [ExcelArgument(Description = "Adjustment direction (-1, 1)")] object direction, [ExcelArgument(Description = "Adjusted day should be in the same month")] object same_month) { int step = (int)ExcelHelper.CheckValue <double>(direction, 1); //default is next bool mod = ExcelHelper.CheckValue <bool>(same_month, true); //default is true DateTime businessday = date; while (IsHoliday(businessday)) { businessday = businessday.AddDays(step); if (mod && businessday.Month != date.Month) { step = -step; businessday = date; //reset to start date, we know it is a holiday } } return(businessday); }