示例#1
0
文件: Irr.cs 项目: leo0530/Zephyr
        public ValueEval Evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex)
        {
            if (args.Length == 0 || args.Length > 2)
            {
                // Wrong number of arguments
                return(ErrorEval.VALUE_INVALID);
            }

            try
            {
                double[] values = AggregateFunction.ValueCollector.CollectValues(args[0]);
                double   guess;
                if (args.Length == 2)
                {
                    guess = NumericFunction.SingleOperandEvaluate(args[1], srcRowIndex, srcColumnIndex);
                }
                else
                {
                    guess = 0.1d;
                }
                double result = irr(values, guess);
                NumericFunction.CheckValue(result);
                return(new NumberEval(result));
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
        }
示例#2
0
        public ValueEval Evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex)
        {
            int nArgs = args.Length;

            if (nArgs < 2)
            {
                return(ErrorEval.VALUE_INVALID);
            }

            try
            {
                double rate = NumericFunction.SingleOperandEvaluate(args[0], srcRowIndex, srcColumnIndex);
                // convert tail arguments into an array of doubles
                ValueEval[] vargs = new ValueEval[args.Length - 1];
                Array.Copy(args, 1, vargs, 0, vargs.Length);
                double[] values = AggregateFunction.ValueCollector.CollectValues(vargs);

                double result = FinanceLib.npv(rate, values);
                NumericFunction.CheckValue(result);
                return(new NumberEval(result));
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
        }
示例#3
0
        private bool CheckArgument(double aDouble)
        {
            NumericFunction.CheckValue(aDouble);

            // make sure that the number is positive
            if (aDouble < 0)
            {
                throw new EvaluationException(ErrorEval.NUM_ERROR);
            }

            return(true);
        }
示例#4
0
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0)
        {
            double result;

            try
            {
                double d0 = NumericFunction.SingleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
                result = Math.Log(d0) / NumericFunction.LOG_10_TO_BASE_e;
                NumericFunction.CheckValue(result);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
            return(new NumberEval(result));
        }
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1)
        {
            double result;

            try
            {
                double d0 = NumericFunction.SingleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
                double d1 = NumericFunction.SingleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
                result = Evaluate(d0, d1);
                NumericFunction.CheckValue(result);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
            return(new NumberEval(result));
        }
示例#6
0
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1, ValueEval arg2)
        {
            // arguments/result for this function
            double mean       = 0;
            double x          = 0;
            bool   cumulative = ((BoolEval)arg2).BooleanValue;
            double result     = 0;

            try
            {
                x    = NumericFunction.SingleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
                mean = NumericFunction.SingleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);

                // check for default result : excel implementation for 0,0
                // is different to Math Common.
                if (IsDefaultResult(x, mean))
                {
                    return(new NumberEval(DEFAULT_RETURN_RESULT));
                }
                // check the arguments : as per excel function def
                CheckArgument(x);
                CheckArgument(mean);

                // truncate x : as per excel function def
                if (cumulative)
                {
                    result = cumulativeProbability((int)x, mean);
                }
                else
                {
                    result = probability((int)x, mean);
                }

                // check the result
                NumericFunction.CheckValue(result);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }

            return(new NumberEval(result));
        }
示例#7
0
        public ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0, ValueEval arg1,
                                  ValueEval arg2, ValueEval arg3)
        {
            double result;

            try
            {
                double rate = NumericFunction.SingleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
                double d1   = NumericFunction.SingleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
                double d2   = NumericFunction.SingleOperandEvaluate(arg2, srcRowIndex, srcColumnIndex);
                double d3   = NumericFunction.SingleOperandEvaluate(arg3, srcRowIndex, srcColumnIndex);
                result = Evaluate(rate, d1, d2, d3);
                NumericFunction.CheckValue(result);
            }
            catch (EvaluationException e)
            {
                return(e.GetErrorEval());
            }
            return(new NumberEval(result));
        }
示例#8
0
        public override ValueEval Evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0,
                                           ValueEval arg1)
        {
            double result;

            try {
                double d0    = NumericFunction.SingleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
                double d1    = NumericFunction.SingleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
                double logE  = Math.Log(d0);
                double base1 = d1;
                if (base1 == Math.E)
                {
                    result = logE;
                }
                else
                {
                    result = logE / Math.Log(base1);
                }
                NumericFunction.CheckValue(result);
            } catch (EvaluationException e) {
                return(e.GetErrorEval());
            }
            return(new NumberEval(result));
        }