Пример #1
0
        public float getIRR(double s, double r)
        {
            double[] cfexpanded = new double[100];
            int      cp         = 0;
            CFData   d1         = this.data[0];
            double   dc0        = d1.getX();

            cfexpanded.SetValue(dc0, cp);
            for (int cj = 1; cj < this.data.Length; ++cj)
            {
                d1 = this.data[cj];
                double dc1 = d1.getX();
                int    c2  = (int)d1.getY();
                for (int ck = 1; ck <= c2; ++ck)
                {
                    cp += 1;
                    cfexpanded.SetValue(dc1, cp);
                }
            }
            double intermediate = Microsoft.VisualBasic.Financial.IRR(
                ref cfexpanded, 0.1);

            if (Double.IsNaN(intermediate))
            {
                return((float)0.0);
            }
            else
            {
                return((float)intermediate);
            }
        }
Пример #2
0
        public float getNPV(double s)
        {
            double disc   = 1.0 / (1.0 + s);
            double npvsum = 0.0;
            int    cp     = 0;
            CFData d1     = this.data[0];
            double dc0    = d1.getX();

            for (int cj = 1; cj < this.data.Length; ++cj)
            {
                d1 = this.data[cj];
                double dc1 = d1.getX();
                int    c2  = (int)d1.getY();
                for (int ck = 1; ck <= c2; ++ck)
                {
                    cp     += 1;
                    npvsum += Math.Pow(disc, cp) * dc1;
                }
            }
            return((float)(dc0 + npvsum));
        }
Пример #3
0
 private void recalc()
 {
     try
     {
         MaskedTextBox tf  = (MaskedTextBox)cfi[0].Controls[1];
         Double        dc0 = (Double.Parse(tf.Text));
         CFData        d1  = new CFData(dc0, 1.0);
         cf.setCFData(d1, 0);
         for (int cj = 1; cj < cfi.Length; ++cj)
         {
             System.Windows.Forms.Panel c1 = (Panel)(cfi[cj]);
             MaskedTextBox tf1             = (MaskedTextBox)c1.Controls[1];
             Double        dc1             = (Double.Parse(tf1.Text));
             MaskedTextBox tf2             = (MaskedTextBox)c1.Controls[2];
             Double        dc2             = (Double.Parse(tf2.Text));
             CFData        d2 = new CFData(dc1, dc2);
             cf.setCFData(d2, cj);
         }
         cf.setSafeI(Double.Parse(S.Text) / 100.0);
         S.Text = (cf.getSafeI() * 100.0).ToString("N", nfi);
         cf.setRiskI(Double.Parse(R.Text) / 100.0);
         R.Text = (cf.getRiskI() * 100.0).ToString("N", nfi);
         double dnpv1 = cf.getNPV();
         npvchar.Text = Math.Round(dnpv1, 2).ToString("C", nfi);
         double dmirr1 = cf.getMIRR() * 100.0;
         mirrchar.Text = Math.Round(dmirr1, 2).ToString() + "%";
         try {
             double dirr1 = cf.getIRR() * 100.0;
             irrchar.Text = Math.Round(dirr1, 2).ToString() + "%";
         } catch (ArgumentException) {
             irrchar.Text = "No Solution";
         }
     }
     catch (FormatException)
     {
         MessageBox.Show("One or more cash flow contains invalid character.\nCheck the cash flows entered before continuing.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     xmlHasChanged = true;
 }
Пример #4
0
 public void setCFData(CFData d, int i)
 {
     this.data[i] = d;
 }
Пример #5
0
 public float getMIRR(double s, double r)
 {
     try
     {
         double discs   = 1.0 / (1.0 + s);
         double discr   = 1.0 / (1.0 + r);
         double npvsum  = 0.0;
         double pnpvsum = 0.0;
         double nnpvsum = 0.0;
         int    cp      = 0;
         CFData d1      = this.data[0];
         double dc0     = d1.getX();
         for (int cj = 1; cj < this.data.Length; ++cj)
         {
             d1 = this.data[cj];
             double dc1 = d1.getX();
             int    c2  = (int)d1.getY();
             for (int ck = 1; ck <= c2; ++ck)
             {
                 cp     += 1;
                 npvsum += Math.Pow(discs, cp) * dc1;
                 if (dc1 > 0)
                 {
                     pnpvsum += Math.Pow(discr, cp) * dc1;
                 }
                 if (dc1 < 0)
                 {
                     nnpvsum += Math.Pow(discs, cp) * dc1;
                 }
             }
         }
         if (dc0 > 0)
         {
             pnpvsum += dc0;
         }
         if (dc0 < 0)
         {
             nnpvsum += dc0;
         }
         double top           = (-1.0 * pnpvsum * Math.Pow(1.0 + r, this.data.Length));
         double bottom        = (nnpvsum * (1.0 + s));
         double intermediate  = (Math.Pow(top / bottom, 1.0 / (this.data.Length - 1.0)));
         double intermediate2 = intermediate - 1.0;
         if (Double.IsNaN(intermediate2))
         {
             return((float)(0.0));
         }
         else
         {
             return((float)(intermediate - 1.0));
         }
     }
     catch (System.DivideByZeroException)
     {
         Console.WriteLine("ERROR. Divided by 0.");
         return((float)(0.0));
     }
     catch (NotFiniteNumberException)
     {
         Console.WriteLine("ERROR. Not a Finite Number.");
         return((float)(0.0));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return((float)(0.0));
     }
 }