c#IRR函数(参数无效异常)

时间:2013-07-24 09:06:22

标签: c#

我遇到了c#IRR函数的问题我得到的“参数无效”异常,我在给定项目中每年都有一个netcash数组:

 public double IRR
{
    get
    {
          var operatingYears =
            EntProject.ResultYearSet.Where(p => p.YearType == YearTypeEnum.Operating)
                      .Select(x => (double)x.NetCash)
                      .ToArray();


        return NavitasFormulae.GetInternalRateofReturn(operatingYears);
    }          

IRR功能:

 public static double GetInternalRateofReturn(double[] values,double guess = 0.0001)
{
    try
    {
        return Financial.IRR(ref values);

    }

    catch (ArgumentException)
    {
        // throw new BusinessException(BusinessExceptionEnum.Operational,
        //                           "Cannot calculate IRR from the yearly values");

        return 0; //If the series of values are not suitable, then the function will return zero.

    }

    catch (Exception)
    {
        throw new BusinessException(BusinessExceptionEnum.Operational,
                                    "The IRR Function encountered an error");
    }
}

我试图将猜测更改为不同的值,并且在数组中也传递了一个负数(每年总费用的总和),但仍然没有运气?

1 个答案:

答案 0 :(得分:0)

希望还不算太晚。我正在处理这个问题,我将IRR方法的猜测值更改为0.00000001。

IRR的结果永远不会为零。因此,猜测值表示零IRR结果的接近程度。

rate = Microsoft.VisualBasic.Financial.IRR(ref values, 0.00000001);

我在C#中调用此函数

相关问题